已删除20个文件
已修改67个文件
已复制9个文件
已添加187个文件
已重命名4个文件
| | |
| | | "@microsoft/signalr": "^6.0.4", |
| | | "ali-oss": "^6.17.1", |
| | | "axios": "^0.21.1", |
| | | "bootstrap": "^5.3.3", |
| | | "core-js": "^3.6.5", |
| | | "echarts": "^5.0.2", |
| | | "element-plus": "^2.2.14", |
| | | "less": "^4.1.1", |
| | | "mitt": "^3.0.1", |
| | | "vue": "^3.2.37", |
| | | "vue-draggable-next": "^2.0.1", |
| | | "vue-router": "^4.0.0-0", |
| | |
| | | }, |
| | | "eslintIgnore": [ |
| | | "*" |
| | | ] |
| | | ], |
| | | "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" |
| | | } |
| | |
| | | let loadingStatus = false; |
| | | if (process.env.NODE_ENV == 'development') { |
| | | axios.defaults.baseURL = 'http://127.0.0.1:9291/'; |
| | | // axios.defaults.baseURL = 'http://192.168.20.251:9291/'; |
| | | } |
| | | else if (process.env.NODE_ENV == 'debug') { |
| | | axios.defaults.baseURL = 'http://127.0.0.1:9291/'; |
| | | axios.defaults.baseURL = 'http://127.0.0.1:8098/'; |
| | | } |
| | | |
| | | else if (process.env.NODE_ENV == 'production') { |
| | | axios.defaults.baseURL = 'http://127.0.0.1:9291/'; |
| | | axios.defaults.baseURL = 'http://192.168.20.253:9291/'; |
| | | } |
| | | if (!axios.defaults.baseURL.endsWith('/')) { |
| | | axios.defaults.baseURL+="/"; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="Linebox" > |
| | | <div class="card"> |
| | | <div class="card-header"> |
| | | <div id="lines2"> |
| | | <div class="card-body">{{ device.deviceName }}<br /> |
| | | -{{ device.childDeviceCode }}- |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <div class="card-body"> |
| | | <ul class="list-group lis"> |
| | | <li class="list-group-item list-group-item-dark">读åä¿¡å·</li> |
| | | <li class="list-group-item list-group-item-secondary">ä»»å¡å·ï¼{{ |
| | | device.data.command.taskNum }}</li> |
| | | <li class="list-group-item list-group-item-secondary">æçå·ï¼{{ |
| | | device.data.command.barcode }}</li> |
| | | <li class="list-group-item list-group-item-secondary">ç»ç¹å°åï¼{{ |
| | | device.data.command.targetAddress }}</li> |
| | | <li :class="getSignalClass(device.data.writeInteractiveSignal[6])">æ«ç ç«å°å
¥åºè¯·æ±</li> |
| | | <li :class="getSignalClass(device.data.writeInteractiveSignal[4])">å åæºåºåºç«å°è¯·æ±</li> |
| | | <li :class="getSignalClass(device.data.writeInteractiveSignal[2])">å åæºå
¥åºç«å°è¯·æ±</li> |
| | | <li :class="getSignalClass(device.data.writeInteractiveSignal[0])">线ä½åºåºå£è¯·æ±</li> |
| | | </ul> |
| | | <ul class="list-group lis"> |
| | | <li class="list-group-item list-group-item-dark">åå
¥ä¿¡å·</li> |
| | | <li class="list-group-item list-group-item-secondary">ä»»å¡å·ï¼{{ |
| | | device.data.commandWrite.taskNum }}</li> |
| | | <li class="list-group-item list-group-item-secondary">æçå·ï¼{{ |
| | | device.data.commandWrite.barcode }}</li> |
| | | <li class="list-group-item list-group-item-secondary">ç»ç¹å°åï¼{{ |
| | | device.data.commandWrite.targetAddress }}</li> |
| | | <li :class="getSignalClass(device.data.writeInteractiveSignal[7])">æ«ç ç«å°å
¥åºè¯·æ±</li> |
| | | <li :class="getSignalClass(device.data.writeInteractiveSignal[5])">å åæºåºåºç«å°è¯·æ±</li> |
| | | <li :class="getSignalClass(device.data.writeInteractiveSignal[3])">å åæºå
¥åºç«å°è¯·æ±</li> |
| | | <li :class="getSignalClass(device.data.writeInteractiveSignal[1])">线ä½åºåºå£è¯·æ±</li> |
| | | </ul> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { defineProps } from "vue"; |
| | | |
| | | // å®ä¹ç»ä»¶å±æ§ |
| | | const props = defineProps({ |
| | | device: { |
| | | type: Object, |
| | | required: true |
| | | } |
| | | }); |
| | | |
| | | // è·åä¿¡å·ç±»å |
| | | const getSignalClass = (signal) => { |
| | | // console.log("ð ~ getSignalClass ~ signal:", signal) |
| | | return signal !== true ? 'list-group-item list-group-item-danger' : 'list-group-item list-group-item-success'; |
| | | }; |
| | | </script> |
| | | |
| | | <style scoped> |
| | | /* .Stackerbox{ |
| | | width: 220px; |
| | | float: left; |
| | | } */ |
| | | .Linebox{ |
| | | width: 500px; |
| | | float: left; |
| | | } |
| | | .box1{ |
| | | float: left; |
| | | } |
| | | .card-body{ |
| | | text-align: center; |
| | | border-radius: 6% ; |
| | | } |
| | | .Stacker{ |
| | | background-color: burlywood; |
| | | } |
| | | .lis{ |
| | | float: left; |
| | | width: 233px; |
| | | } |
| | | </style> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="Linebox"> |
| | | <div class="card"> |
| | | <div class="card-header"> |
| | | <div id="lines2" > |
| | | <div class="card-body">{{device.deviceName}}<br/> |
| | | -{{ device.data.childDeviceCode }}- |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <div class="card-body"> |
| | | <ul class="list-group lis"> |
| | | <li class="list-group-item list-group-item-dark">读åä¿¡å·</li> |
| | | <li class="list-group-item list-group-item-secondary">ä»»å¡å·ï¼{{ device.data.commandAfter.conveyorLineTaskNum }}</li> |
| | | <li class="list-group-item list-group-item-secondary">æçå·ï¼{{ device.data.commandAfter.conveyorLineBarcode }}</li> |
| | | <li class="list-group-item list-group-item-secondary">ç»ç¹å°åï¼{{ device.data.commandAfter.conveyorLineTargetAddress }}</li> |
| | | <li class="list-group-item list-group-item-secondary">æ¯å¦æçï¼{{ device.data.commandAfter.hasPallet }}</li> |
| | | <li class="list-group-item list-group-item-secondary">æ¥è¦ä»£ç ï¼{{ device.data.commandAfter.conveyorLineAlarm }}</li> |
| | | <li class="list-group-item list-group-item-secondary">请æ±åé¦ï¼{{ device.data.commandAfter.responState }}</li> |
| | | <li :class="device.data.commandAfter.interactiveSignal !=0 ? 'list-group-item list-group-item-success' :'list-group-item list-group-item-danger'">交äºä¿¡å·</li> |
| | | </ul> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | <script setup> |
| | | import { defineProps } from "vue"; |
| | | |
| | | // å®ä¹ç»ä»¶å±æ§ |
| | | const props = defineProps({ |
| | | device: { |
| | | type: Object, |
| | | required: true |
| | | } |
| | | }); |
| | | |
| | | // è·åä¿¡å·ç±»å |
| | | const getSignalClass = (signal) => { |
| | | // console.log("ð ~ getSignalClass ~ signal:", signal) |
| | | return signal !== true ? 'list-group-item list-group-item-danger' : 'list-group-item list-group-item-success'; |
| | | }; |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .Stackerbox { |
| | | width: 220px; |
| | | float: left; |
| | | } |
| | | .Linebox { |
| | | width: 300px; |
| | | float: left; |
| | | } |
| | | .box1 { |
| | | float: left; |
| | | } |
| | | .card-body { |
| | | text-align: center; |
| | | border-radius: 6%; |
| | | } |
| | | .Stacker { |
| | | background-color: burlywood; |
| | | } |
| | | .lis { |
| | | float: left; |
| | | width: 266px; |
| | | } |
| | | </style> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="Stackerbox"> |
| | | <div class="card"> |
| | | <div class="card-header"> |
| | | <div> |
| | | <div class="card-body Stacker"> |
| | | {{ Stacker.deviceName }} |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <div class="card-body"> |
| | | <ul class="list-group"> |
| | | <li class="list-group-item list-group-item-secondary"> |
| | | ä»»å¡å·ï¼{{ Stacker.data.currentTaskNum || 'ææ ä»»å¡å·' }} |
| | | </li> |
| | | <li class="list-group-item list-group-item-secondary"> |
| | | ä¸ä¸ä¸ªä»»å¡ï¼{{ Stacker.data.LastTaskNum || 'ææ ä»»å¡å·' }} |
| | | </li> |
| | | <li :class="getStatusClass(Stacker.data.stackerCraneAutoStatusDes)"> |
| | | 工使¨¡å¼ï¼{{ Stacker.data.stackerCraneAutoStatusDes }} |
| | | </li> |
| | | <li :class="getStatusClass(Stacker.data.stackerCraneStatusDes)"> |
| | | 设å¤ç¶æï¼{{ Stacker.data.stackerCraneStatusDes }} |
| | | </li> |
| | | <li :class="getStatusClass(Stacker.data.stackerCraneWorkStatusDes)"> |
| | | å·¥ä½ç¶æï¼{{ Stacker.data.stackerCraneWorkStatusDes }} |
| | | </li> |
| | | <li class="list-group-item list-group-item-secondary"> |
| | | èµ·ç¹ï¼{{ Stacker.data.SourceAddress || 'ææ ä»»å¡' }} |
| | | </li> |
| | | <li class="list-group-item list-group-item-secondary"> |
| | | ç»ç¹ï¼{{ Stacker.data.TargetAddress || 'ææ ä»»å¡' }} |
| | | </li> |
| | | <li class="list-group-item list-group-item-secondary"> |
| | | å½ä»¤æ¹å¼ï¼{{ Stacker.data.Command==1? 'åæ¾ç©æä½ä¸': 'ç§»å¨å°æå®ä½ç½®' }} |
| | | </li> |
| | | <li class="list-group-item list-group-item-secondary"> |
| | | AGVçµéï¼{{ Stacker.data.electricity+'%' }} |
| | | </li> |
| | | </ul> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { defineProps } from "vue"; |
| | | |
| | | // å®ä¹ç»ä»¶å±æ§ |
| | | const props = defineProps({ |
| | | Stacker: { |
| | | type: Object, |
| | | required: true |
| | | } |
| | | }); |
| | | |
| | | // è·åç¶æç±»åï¼ä¼åç¶æå¤æï¼ |
| | | const getStatusClass = (status) => { |
| | | if (status === 'èæº' || status === 'æ æ
é' || status === '空é²') { |
| | | return 'list-group-item list-group-item-success'; |
| | | } |
| | | if (status === 'æ
é' || status === 'åæº') { |
| | | return 'list-group-item list-group-item-danger'; |
| | | } |
| | | return 'list-group-item list-group-item-warning'; // é»è®¤è¦åç¶æ |
| | | }; |
| | | |
| | | |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | |
| | | </style> |
| | |
| | | }, |
| | | rowClick({ row, column, event }) { |
| | | //æ¥è¯¢çé¢ç¹å»è¡äºä»¶ |
| | | this.$refs.table.$refs.table.toggleRowSelection(row); //åå»è¡æ¶éä¸å½åè¡; |
| | | // this.$refs.table.$refs.table.toggleRowSelection(row); //åå»è¡æ¶éä¸å½åè¡; |
| | | }, |
| | | modelOpenAfter(row) { |
| | | //ç¹å»ç¼è¾ãæ°å»ºæé®å¼¹åºæ¡åï¼å¯ä»¥å¨æ¤å¤åé»è¾ï¼å¦ï¼ä»åå°è·åæ°æ® |
| | |
| | | |
| | | import gridBody from './extend/importDevicePro.vue' |
| | | import gridBody from "./extend/importDevicePro.vue"; |
| | | let extension = { |
| | | components: { |
| | | //æ¥è¯¢ç颿©å±ç»ä»¶ |
| | | gridHeader: '', |
| | | gridHeader: "", |
| | | gridBody: gridBody, |
| | | gridFooter: '', |
| | | gridFooter: "", |
| | | //æ°å»ºãç¼è¾å¼¹åºæ¡æ©å±ç»ä»¶ |
| | | modelHeader: '', |
| | | modelBody: '', |
| | | modelFooter: '' |
| | | modelHeader: "", |
| | | modelBody: "", |
| | | modelFooter: "", |
| | | }, |
| | | tableAction: '', //æå®æå¼ 表çæé(è¿éå¡«å表å,é»è®¤ä¸ç¨å¡«å) |
| | | tableAction: "", //æå®æå¼ 表çæé(è¿éå¡«å表å,é»è®¤ä¸ç¨å¡«å) |
| | | buttons: { view: [], box: [], detail: [] }, //æ©å±çæé® |
| | | methods: { |
| | | //ä¸é¢è¿äºæ¹æ³å¯ä»¥ä¿çä¹å¯ä»¥å é¤ |
| | | onInit() { |
| | | // console.log(this.detailOptions.buttons); |
| | | // console.log(this.$refs.detail) |
| | | var detailImport = this.detailOptions.buttons.find(item=>item.value == 'import'); |
| | | var detailImport = this.detailOptions.buttons.find( |
| | | (item) => item.value == "import" |
| | | ); |
| | | if(detailImport){ |
| | | detailImport.onClick = function () { |
| | | this.$refs.gridBody.open(); |
| | | }; |
| | | } |
| | | } |
| | | // this.buttons.unshift({ |
| | | // //ä¹å¯ä»¥ç¨pushæè
spliceæ¹æ³æ¥ä¿®æ¹buttonsæ°ç» |
| | | // name: "å¼å¯æå¡", //æé®åç§° |
| | | // icon: "el-icon-document", //æé®å¾æ vue2çæ¬è§iviewææ¡£iconï¼vue3çæ¬è§element uiææ¡£icon(注æä¸æ¯element pulsææ¡£) |
| | | // type: "primary", //æé®æ ·å¼vue2çæ¬è§iviewææ¡£buttonï¼vue3çæ¬è§element uiææ¡£button |
| | | // onClick: function () { |
| | | // this.$Message.success("å¼å¯æå¡"); |
| | | // }, |
| | | // }); |
| | | }, |
| | | onInited() { |
| | | //æ¡æ¶åå§åé
ç½®å |
| | |
| | | }, |
| | | rowClick({ row, column, event }) { |
| | | //æ¥è¯¢çé¢ç¹å»è¡äºä»¶ |
| | | this.$refs.table.$refs.table.toggleRowSelection(row); //åå»è¡æ¶éä¸å½åè¡; |
| | | // this.$refs.table.$refs.table.toggleRowSelection(row); //åå»è¡æ¶éä¸å½åè¡; |
| | | }, |
| | | modelOpenAfter(row) { |
| | | //ç¹å»ç¼è¾ãæ°å»ºæé®å¼¹åºæ¡åï¼å¯ä»¥å¨æ¤å¤åé»è¾ï¼å¦ï¼ä»åå°è·åæ°æ® |
| | |
| | | //console.log(this.$refs) |
| | | this.$nextTick(() => { |
| | | if (this.$refs.upload_excel) { |
| | | alert('ç¹å»äºä¸ä¼ æé®') |
| | | alert("ç¹å»äºä¸ä¼ æé®"); |
| | | this.$refs.upload_excel.upload = function () { |
| | | console.log('ç¹å»äºä¸ä¼ æé®') |
| | | } |
| | | console.log("ç¹å»äºä¸ä¼ æé®"); |
| | | }; |
| | | } |
| | | // alert(1) |
| | | }) |
| | | |
| | | } |
| | | } |
| | | }); |
| | | }, |
| | | }, |
| | | }; |
| | | export default extension; |
| | |
| | | }, |
| | | rowClick({ row, column, event }) { |
| | | //æ¥è¯¢çé¢ç¹å»è¡äºä»¶ |
| | | this.$refs.table.$refs.table.toggleRowSelection(row); //åå»è¡æ¶éä¸å½åè¡; |
| | | // this.$refs.table.$refs.table.toggleRowSelection(row); //åå»è¡æ¶éä¸å½åè¡; |
| | | }, |
| | | modelOpenAfter(row) { |
| | | //ç¹å»ç¼è¾ãæ°å»ºæé®å¼¹åºæ¡åï¼å¯ä»¥å¨æ¤å¤åé»è¾ï¼å¦ï¼ä»åå°è·åæ°æ® |
| | |
| | | }, |
| | | rowClick({ row, column, event }) { |
| | | //æ¥è¯¢çé¢ç¹å»è¡äºä»¶ |
| | | this.$refs.table.$refs.table.toggleRowSelection(row); //åå»è¡æ¶éä¸å½åè¡; |
| | | // this.$refs.table.$refs.table.toggleRowSelection(row); //åå»è¡æ¶éä¸å½åè¡; |
| | | }, |
| | | modelOpenAfter(row) { |
| | | //ç¹å»ç¼è¾ãæ°å»ºæé®å¼¹åºæ¡åï¼å¯ä»¥å¨æ¤å¤åé»è¾ï¼å¦ï¼ä»åå°è·åæ°æ® |
| | |
| | | }, |
| | | rowClick({ row, column, event }) { |
| | | //æ¥è¯¢çé¢ç¹å»è¡äºä»¶ |
| | | this.$refs.table.$refs.table.toggleRowSelection(row); //åå»è¡æ¶éä¸å½åè¡; |
| | | // this.$refs.table.$refs.table.toggleRowSelection(row); //åå»è¡æ¶éä¸å½åè¡; |
| | | }, |
| | | modelOpenAfter(row) { |
| | | //ç¹å»ç¼è¾ãæ°å»ºæé®å¼¹åºæ¡åï¼å¯ä»¥å¨æ¤å¤åé»è¾ï¼å¦ï¼ä»åå°è·åæ°æ® |
| | |
| | | "/api/user/modifyUserPwd?password=" + |
| | | this.password + |
| | | "&userName=" + |
| | | this.row.UserName; |
| | | this.row.userName; |
| | | this.http.post(url, {}, true).then((x) => { |
| | | if (!x.status) { |
| | | return this.$message.error(x.message); |
| | |
| | | }, |
| | | rowClick({ row, column, event }) { |
| | | //æ¥è¯¢çé¢ç¹å»è¡äºä»¶ |
| | | this.$refs.table.$refs.table.toggleRowSelection(row); //åå»è¡æ¶éä¸å½åè¡; |
| | | // this.$refs.table.$refs.table.toggleRowSelection(row); //åå»è¡æ¶éä¸å½åè¡; |
| | | }, |
| | | modelOpenAfter(row) { |
| | | //ç¹å»ç¼è¾ãæ°å»ºæé®å¼¹åºæ¡åï¼å¯ä»¥å¨æ¤å¤åé»è¾ï¼å¦ï¼ä»åå°è·åæ°æ® |
| | |
| | | // import 'dayjs/locale/zh-cn' |
| | | // import locale from 'element-plus/lib/locale/lang/zh-cn' |
| | | import * as ElementPlusIconsVue from '@element-plus/icons-vue' |
| | | |
| | | import 'bootstrap/dist/css/bootstrap.min.css'; |
| | | |
| | | |
| | | import permission from './api/permission' |
| | |
| | | meta:{ |
| | | anonymous:true |
| | | } |
| | | }, |
| | | { |
| | | },{ |
| | | path: '/bigdata', |
| | | name: 'bigdata', |
| | | component: () => import('@/views/charts/bigdata.vue'), |
| | |
| | | |
| | | let redirect = [{ |
| | | path: '/404', |
| | | name: '404', |
| | | component: () => import('@/components/redirect/404'), |
| | | let redirect = [ |
| | | { |
| | | path: "/404", |
| | | name: "404", |
| | | component: () => import("@/components/redirect/404"), |
| | | meta:{ |
| | | anonymous:true |
| | | } |
| | | }, { |
| | | path: '/401', |
| | | name: '401', |
| | | component: () => import('@/components/redirect/401') |
| | | }, { |
| | | path: '/coding', |
| | | name: 'coding', |
| | | component: () => import('@/components/redirect/coding') |
| | | }, { |
| | | path: '/message', |
| | | name: 'message', |
| | | component: () => import('@/components/redirect/Message.vue') |
| | | }] |
| | | anonymous: true, |
| | | }, |
| | | }, |
| | | { |
| | | path: "/401", |
| | | name: "401", |
| | | component: () => import("@/components/redirect/401"), |
| | | }, |
| | | { |
| | | path: "/coding", |
| | | name: "coding", |
| | | component: () => import("@/components/redirect/coding"), |
| | | }, |
| | | { |
| | | path: "/message", |
| | | name: "message", |
| | | component: () => import("@/components/redirect/Message.vue"), |
| | | }, |
| | | ]; |
| | | export default redirect; |
| | |
| | | path: '/Sys_Log', |
| | | name: 'sys_Log', |
| | | component: () => import('@/views/system/Sys_Log.vue') |
| | | },{ |
| | | path: '/txt_log', |
| | | name: 'txt_log', |
| | | component: () => import('@/views/syslog/txt_log.vue') |
| | | }, |
| | | { |
| | | path: '/Sys_User', |
| | |
| | | path: '/router', |
| | | name: 'router', |
| | | component: () => import('@/views/basicinfo/router.vue') |
| | | }, { |
| | | path: '/AgvStation', |
| | | name: 'AgvStation', |
| | | component: () => import('@/views/system/AgvStation.vue') |
| | | }] |
| | | }, |
| | | { |
| | | path: '/AGVStatus', |
| | | name: 'AGVStatus', |
| | | component: () => import('@/views/Devicestatus/AGVStatus.vue') |
| | | }, |
| | | { |
| | | path: '/Dt_StationManager', |
| | | name: 'Dt_StationManager', |
| | | component: () => import('@/views/basicinfo/Dt_StationManager.vue') |
| | | }, |
| | | ] |
| | | |
| | | export default viewgird |
¶Ô±ÈÐÂÎļþ |
| | |
| | | import mitt from 'mitt'; |
| | | |
| | | const eventBus = mitt(); |
| | | |
| | | export default eventBus; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | // import sysConfig from '@/config/index' |
| | | // import tool from '@/utils/tool' |
| | | import store from "../store/index"; |
| | | import http from "@/../src/api/http.js"; |
| | | import * as signalR from "@microsoft/signalr"; |
| | | import { ElNotification } from "element-plus"; |
| | | |
| | | import eventBus from "./eventBus"; |
| | | |
| | | // import * as signalrMessage from './mqtt/message' |
| | | //使ç¨signalr |
| | | export default function useSignalr() { |
| | | // const userInfo = tool.data.get('USER_INFO') //ç¨æ·ä¿¡æ¯ |
| | | let openedNotification = null; // ä¿åå½åæå¼çNotificationå®ä¾ |
| | | let socketUrl = "hubs/simple"; //socketå°å |
| | | // if (sysConfig.VITE_PROXY === 'false') { |
| | | socketUrl = http.ipAddress + socketUrl; //夿æ¯å¦è¦èµ°ä»£ç模å¼ï¼èµ°äºçè¯åå¸ä¹åç´æ¥nginx代ç |
| | | // } |
| | | //å¼å§ |
| | | const startSignalr = () => { |
| | | //åå§åè¿æ¥ |
| | | const connection = init(); |
| | | // å¯å¨è¿æ¥ |
| | | connection |
| | | .start() |
| | | .then(() => { |
| | | console.log("å¯å¨è¿æ¥"); |
| | | }) |
| | | .catch((err) => { |
| | | console.log("è¿æ¥å¤±è´¥", err); |
| | | }); |
| | | }; |
| | | |
| | | //åå§å |
| | | const init = () => { |
| | | console.log("åå§åSignalR对象"); |
| | | // SignalR对象 |
| | | const connection = new signalR.HubConnectionBuilder() |
| | | .withUrl(socketUrl, { |
| | | accessTokenFactory: () => store.getters.getToken(), |
| | | skipNegotiation: true, |
| | | transport: signalR.HttpTransportType.WebSockets, |
| | | }) |
| | | .withAutomaticReconnect({ |
| | | nextRetryDelayInMilliseconds: () => { |
| | | return 5000; // æ¯5ç§éè¿ä¸æ¬¡ |
| | | }, |
| | | }) //èªå¨éæ°è¿æ¥ |
| | | .configureLogging(signalR.LogLevel.Information) |
| | | .build(); |
| | | connection.keepAliveIntervalInMilliseconds = 15 * 1000; // å¿è·³æ£æµ15s |
| | | // connection.serverTimeoutInMilliseconds = 30 * 60 * 1000 // è¶
æ¶æ¶é´30m |
| | | // æå¼è¿æ¥ |
| | | connection.onclose(async () => { |
| | | console.log("æå¼è¿æ¥"); |
| | | }); |
| | | |
| | | //æçº¿éæ° |
| | | connection.onreconnected(() => { |
| | | console.log("æçº¿éæ°è¿æ¥æå"); |
| | | }); |
| | | //æ¶æ¯å¤ç |
| | | receiveMsg(connection); |
| | | return connection; |
| | | }; |
| | | |
| | | //æ¥æ¶æ¶æ¯å¤ç |
| | | const receiveMsg = (connection) => { |
| | | //æ¥æ¶ç»åº |
| | | connection.on("LoginOut", (data) => { |
| | | // signalrMessage.loginOut(data) |
| | | }); |
| | | |
| | | connection.on("NewMessage", (data) => { |
| | | eventBus.emit("stackerDataError", data); |
| | | if (openedNotification === null || openedNotification.closed) { |
| | | // ä¸ä¸ä¸ªNotificationå·²å
³éæå°æªæå¼ |
| | | openedNotification = ElNotification({ |
| | | title: "æå", |
| | | message: data, |
| | | type: "success", |
| | | onClose: () => { |
| | | // Notificationå·²å
³é |
| | | openedNotification = null; // æ¸
空å½åæå¼çNotificationå®ä¾ |
| | | console.log("Notificationå·²å
³é"); |
| | | }, |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | connection.on("StackerData", (data) => { |
| | | console.log(data) |
| | | eventBus.emit("stackerData", data); |
| | | }); |
| | | connection.on("LineData", (data) => { |
| | | eventBus.emit("locationData", data); |
| | | }); |
| | | connection.on("Logs", (data) => { |
| | | eventBus.emit("Logs", data); |
| | | }); |
| | | }; |
| | | |
| | | //页é¢éæ¯ |
| | | // onUnmounted(() => {}) |
| | | return { startSignalr }; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <el-row> |
| | | <el-col :span="24"> |
| | | <device-stacker v-for="stacker in Stackers" :key="stacker.deviceName" :Stacker="stacker"></device-stacker> |
| | | </el-col> |
| | | </el-row> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { onMounted, reactive, toRefs } from "vue"; |
| | | import eventBus from "@/uitils/eventBus"; |
| | | import DeviceStacker from "@/components/DeviceStacker.vue"; |
| | | |
| | | // å åæº |
| | | const Stackers = reactive([]); |
| | | |
| | | // 设å¤å表ï¼ä¿®æ¹éå¤è®¾å¤åç§°ï¼ |
| | | const devices = reactive([]); |
| | | |
| | | const intToBitArrayFromBinaryString = (num, numBits) => { |
| | | let binaryString = num.toString(2).padStart(numBits, '0'); |
| | | return Array.from({ length: numBits }, (_, index) => binaryString[index] === '1'); |
| | | }; |
| | | |
| | | // çå¬è®¾å¤æ°æ®åå |
| | | onMounted(() => { |
| | | eventBus.on('stackerData', eventData => { |
| | | if (Stackers.length == 0) { |
| | | Stackers.push({ deviceName: eventData.deviceName, data: eventData.data }); |
| | | } |
| | | else { |
| | | const Stacker = Stackers.find(c => c.deviceName == eventData.deviceName); |
| | | if (Stacker) { |
| | | Stacker.data = eventData.data |
| | | } |
| | | else { |
| | | Stackers.push({ deviceName: eventData.deviceName, data: eventData.data }); |
| | | } |
| | | } |
| | | }) |
| | | }); |
| | | </script> |
| | | <style scoped> |
| | | .Stackerbox { |
| | | width: 550px; |
| | | float: left; |
| | | height: 300px; |
| | | } |
| | | |
| | | .box1 { |
| | | float: left; |
| | | } |
| | | |
| | | .card-body { |
| | | text-align: center; |
| | | border-radius: 6%; |
| | | } |
| | | |
| | | .Stacker { |
| | | background-color: burlywood; |
| | | } |
| | | |
| | | .lis { |
| | | float: left; |
| | | width: 233px; |
| | | } |
| | | </style> |
| | |
| | | <template> |
| | | <div class="title"></div> |
| | | <el-container> |
| | | <!-- <el-header >è¿è¡æ¥å¿</el-header> --> |
| | | <el-main> |
| | | <el-card v-for="(log, index) in logs" :key="index" class="log-card" :style="{ color: log.color }"> |
| | | <div :style="{ color: log.color }">{{ log.logEntry }}</div> |
| | | <div :style="{ color: log.color }">{{ log.time }}</div> |
| | | </el-card> |
| | | </el-main> |
| | | </el-container> |
| | | </template> |
| | | |
| | | <script> |
| | | import { ref, reactive } from 'vue' |
| | | import { ref, onMounted } from 'vue' |
| | | import eventBus from "@/uitils/eventBus"; |
| | | |
| | | export default { |
| | | setup() { |
| | | return { |
| | | const logs = ref([]); |
| | | onMounted(() => { |
| | | eventBus.on('Logs', eventData => { |
| | | if (logs.value.length > 500) { |
| | | logs.value = []; |
| | | } |
| | | const logEntry = "æ¥å¿ä¿¡æ¯ï¼" + eventData.log |
| | | const time = "æ¶é´ï¼" + eventData.time |
| | | logs.value.unshift({ logEntry: logEntry, time: time, color: eventData.color }); |
| | | |
| | | // logs.value.unshift(logEntry); |
| | | }); |
| | | }); |
| | | return { |
| | | logs |
| | | } |
| | | } |
| | | } |
| | |
| | | font-size: 28px; |
| | | color: orange; |
| | | } |
| | | |
| | | .log-card { |
| | | margin-bottom: 10px; |
| | | } |
| | | </style> |
| | |
| | | import { useRouter, useRoute } from "vue-router"; |
| | | import store from "../store/index"; |
| | | import http from "@/../src/api/http.js"; |
| | | import useSignalr from '../uitils/signalr.js'; |
| | | export default defineComponent({ |
| | | components: { |
| | | VolMenu, |
| | |
| | | }); |
| | | } |
| | | |
| | | const { startSignalr } = useSignalr() |
| | | startSignalr() |
| | | |
| | | //å½åå·æ°æ¯ä¸æ¯é¦é¡µ |
| | | if (router.currentRoute.value.path != navigation[0].path) { |
| | | //æ¥æ¾ç³»ç»èå |
| | |
| | | const loading = ref(false); |
| | | const codeImgSrc = ref(''); |
| | | const userInfo = reactive({ |
| | | userName: '', |
| | | password: '', |
| | | verificationCode: '', |
| | | userName: 'admin', |
| | | password: '123456', |
| | | verificationCode: '1234', |
| | | UUID: undefined |
| | | }); |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | |
| | | <template> |
| | | <view-grid ref="grid" :columns="columns" :detail="detail" :editFormFields="editFormFields" |
| | | :editFormOptions="editFormOptions" :searchFormFields="searchFormFields" :searchFormOptions="searchFormOptions" |
| | | :table="table" :extend="extend"> |
| | | </view-grid> |
| | | </template> |
| | | <script> |
| | | import extend from "@/extension/basicinfo/Dt_StationManager.js"; |
| | | import { ref, defineComponent } from "vue"; |
| | | export default defineComponent({ |
| | | setup() { |
| | | const table = ref({ |
| | | key: "stationID", |
| | | footer: "Foots", |
| | | cnName: "ç«å°ä¿¡æ¯", |
| | | name: "Dt_StationManager", |
| | | url: "/Dt_StationManager/", |
| | | sortName: "stationID", |
| | | }); |
| | | const editFormFields = ref({ |
| | | stationCode: "", |
| | | stationName: "", |
| | | stationMaterial: "", |
| | | stationEnable: "", |
| | | stationArea: "", |
| | | stationRemark: "", |
| | | deviceCode: "", |
| | | }); |
| | | const editFormOptions = ref([ |
| | | [ |
| | | { |
| | | title: "ç«å°ç¼å·", |
| | | field: "stationCode", |
| | | type: "int", |
| | | }, |
| | | { |
| | | title: "ç«å°åç§°", |
| | | field: "stationName", |
| | | type: "string", |
| | | }, |
| | | { |
| | | title: "ç«å°ç±»å", |
| | | required: true, |
| | | field: "stationMaterial", |
| | | type: "select", |
| | | dataKey: "agvStationEnum", |
| | | data: [], |
| | | }, |
| | | |
| | | ], |
| | | [ |
| | | { |
| | | title: "åºå", |
| | | required: true, |
| | | field: "stationArea", |
| | | type: "select", |
| | | dataKey: "agvareaEnum", |
| | | data: [], |
| | | }, |
| | | { |
| | | title: "æ¯å¦å¯ç¨", |
| | | required: true, |
| | | field: "stationEnable", |
| | | type: "select", |
| | | dataKey: "enable", |
| | | data: [], |
| | | }, |
| | | { |
| | | title: "夿³¨", |
| | | field: "stationRemark", |
| | | type: "string", |
| | | }, |
| | | ], [ |
| | | { |
| | | title: "æå±è®¾å¤", |
| | | field: "deviceCode", |
| | | type: "string", |
| | | }, |
| | | |
| | | ] |
| | | ]); |
| | | const searchFormFields = ref({ |
| | | stationCode: "", |
| | | stationName: "", |
| | | stationMaterial: "", |
| | | stationEnable: "", |
| | | }); |
| | | const searchFormOptions = ref([ |
| | | [ |
| | | { title: "ç«å°åç§°", field: "stationName", type: "like" }, |
| | | { title: "ç«å°ç¼å·", field: "stationCode", type: "like" }, |
| | | |
| | | { |
| | | title: "ç«å°ç±»å", |
| | | field: "stationMaterial", |
| | | type: "select", |
| | | dataKey: "agvStationEnum", |
| | | data: [], |
| | | } |
| | | ], |
| | | [ |
| | | { title: "æå±è®¾å¤", field: "deviceCode", type: "like" }, |
| | | { |
| | | title: "åºå", |
| | | field: "stationArea", |
| | | type: "select", |
| | | dataKey: "agvareaEnum", |
| | | data: [], |
| | | }, { |
| | | title: "æ¯å¦å¯ç¨", |
| | | field: "stationEnable", |
| | | type: "select", |
| | | dataKey: "enable", |
| | | data: [], |
| | | }, |
| | | ], |
| | | ]); |
| | | const columns = ref([ |
| | | { |
| | | field: "stationId", |
| | | title: "stationId", |
| | | type: "int", |
| | | width: 90, |
| | | hidden: true, |
| | | readonly: true, |
| | | require: true, |
| | | align: "left", |
| | | sort: true |
| | | }, |
| | | { |
| | | field: "stationCode", |
| | | title: "ç«å°ç¼å·", |
| | | type: "string", |
| | | width: 100, |
| | | align: "left", |
| | | sort: true |
| | | }, |
| | | { |
| | | field: "stationName", |
| | | title: "ç«å°åç§°", |
| | | type: "string", |
| | | width: 150, |
| | | align: "left", |
| | | sort: true |
| | | }, |
| | | { |
| | | field: "stationMaterial", |
| | | title: "ç«å°ç±»å", |
| | | type: "string", |
| | | width: 150, |
| | | align: "left", |
| | | bind: { key: "agvStationEnum", data: [] }, |
| | | sort: true |
| | | }, |
| | | { |
| | | field: "stationEnable", |
| | | title: "æ¯å¦å¯ç¨", |
| | | type: "string", |
| | | width: 120, |
| | | align: "left", |
| | | bind: { key: "enable", data: [] }, |
| | | sort: true |
| | | }, |
| | | { |
| | | field: "stationArea", |
| | | title: "åºå", |
| | | type: "string", |
| | | width: 120, |
| | | align: "left", |
| | | sort: true, |
| | | bind: { key: "agvareaEnum", data: {} } |
| | | }, |
| | | { |
| | | field: "stationRemark", |
| | | title: "夿³¨", |
| | | type: "string", |
| | | width: 120, |
| | | align: "left", |
| | | sort: true |
| | | // link: true, |
| | | }, |
| | | { |
| | | field: "deviceCode", |
| | | title: "æå±è®¾å¤", |
| | | type: "string", |
| | | width: 120, |
| | | align: "left", |
| | | sort: true |
| | | }, |
| | | ]); |
| | | return { |
| | | table, |
| | | extend, |
| | | editFormFields, |
| | | editFormOptions, |
| | | searchFormFields, |
| | | searchFormOptions, |
| | | columns, |
| | | }; |
| | | }, |
| | | }); |
| | | </script> |
| | | |
| | |
| | | sortName: "createDate", |
| | | }); |
| | | const editFormFields = ref({ |
| | | id:"", |
| | | deviceCode: "", |
| | | deviceName: "", |
| | | deviceType: "", |
| | |
| | | deviceCode: "", |
| | | deviceType: "", |
| | | deviceStatus: "", |
| | | createDate:"", |
| | | }); |
| | | const searchFormOptions = ref([ |
| | | [ |
| | |
| | | type: "select", |
| | | dataKey: "deviceStatus", |
| | | data: [], |
| | | },{ |
| | | field: "createDate", |
| | | title: "å建æ¶é´", |
| | | type: "datetime", |
| | | }, |
| | | ], |
| | | ]); |
| | |
| | | field: "deviceIp", |
| | | title: "设å¤IP", |
| | | type: "string", |
| | | width: 90, |
| | | width: 150, |
| | | align: "left", |
| | | }, |
| | | { |
| | | field: "devicePort", |
| | | title: "设å¤ç«¯å£", |
| | | type: "int", |
| | | width: 120, |
| | | width: 100, |
| | | align: "left", |
| | | }, |
| | | { |
| | |
| | | align: "left", |
| | | }, |
| | | ], |
| | | sortName: "CreateDate", |
| | | sortName: "createDate", |
| | | key: "id", |
| | | }); |
| | | return { |
| | |
| | | gender: "", |
| | | remark: "", |
| | | headImageUrl: "", |
| | | roleName:"", |
| | | }); |
| | | const editFormOptions = ref([ |
| | | [{ title: "å¸å·", required: true, field: "userName"}], |
| | |
| | | width: 90, |
| | | align: "left", |
| | | }, |
| | | // { |
| | | // field: "palletCode", |
| | | // title: "æçç¼å·", |
| | | // type: "string", |
| | | // width: 200, |
| | | // align: "left", |
| | | // }, |
| | | { |
| | | field: "roadway", |
| | | title: "åºå", |
| | | type: "string", |
| | | width: 90, |
| | | align: "left", |
| | | bind:{key:"agvareaEnum",data:{}} |
| | | }, |
| | | { |
| | | field: "agvName", |
| | | title: "AGVç¼å·", |
| | | type: "string", |
| | | width: 90, |
| | | align: "left", |
| | | bind:{key:"agvareaEnum",data:{}} |
| | | }, |
| | | { |
| | | field: "taskType", |
| | |
| | | type: "int", |
| | | width: 90, |
| | | align: "left", |
| | | bind: { key: "agvStationEnum", data: [] }, |
| | | bind: { key: "taskType", data: [] }, |
| | | }, |
| | | { |
| | | field: "taskState", |
| | |
| | | type: "int", |
| | | width: 120, |
| | | align: "left", |
| | | bind: { key: "location", data: [] }, |
| | | }, |
| | | { |
| | | field: "targetAddress", |
| | |
| | | type: "string", |
| | | width: 120, |
| | | align: "left", |
| | | bind: { key: "location", data: [] }, |
| | | }, |
| | | { |
| | | field: "currentAddress", |
| | |
| | | type: "string", |
| | | width: 120, |
| | | align: "left", |
| | | bind: { key: "location", data: [] }, |
| | | hidden:true, |
| | | }, |
| | | { |
| | | field: "nextAddress", |
| | |
| | | type: "string", |
| | | width: 120, |
| | | align: "left", |
| | | bind: { key: "location", data: [] }, |
| | | hidden:true, |
| | | }, |
| | | { |
| | | field: "exceptionMessage", |
| | |
| | | readonly: true, |
| | | require: true, |
| | | align: "left", |
| | | sort:true, |
| | | }, |
| | | { |
| | | field: "taskNum", |
| | |
| | | type: "int", |
| | | width: 90, |
| | | align: "left", |
| | | sort:true, |
| | | }, |
| | | { |
| | | field: "palletCode", |
| | | title: "æçç¼å·", |
| | | type: "string", |
| | | width: 200, |
| | | align: "left", |
| | | sort:true, |
| | | }, |
| | | { |
| | | field: "roadway", |
| | | title: "å··éå·", |
| | | title: "åºå", |
| | | type: "string", |
| | | width: 90, |
| | | align: "left", |
| | | sort:true, |
| | | bind:{key:"agvareaEnum",data:{}} |
| | | }, |
| | | { |
| | | field: "agvName", |
| | | title: "AGVç¼å·", |
| | | type: "string", |
| | | width: 90, |
| | | align: "left", |
| | | bind:{key:"agvareaEnum",data:{}} |
| | | }, |
| | | { |
| | | field: "taskType", |
| | |
| | | width: 90, |
| | | align: "left", |
| | | bind: { key: "taskType", data: [] }, |
| | | sort:true, |
| | | }, |
| | | { |
| | | field: "taskState", |
| | |
| | | width: 150, |
| | | align: "left", |
| | | bind: { key: "taskState", data: [] }, |
| | | sort:true, |
| | | }, |
| | | { |
| | | field: "sourceAddress", |
| | |
| | | type: "int", |
| | | width: 120, |
| | | align: "left", |
| | | bind: { key: "location", data: [] }, |
| | | }, |
| | | { |
| | | field: "targetAddress", |
| | |
| | | type: "string", |
| | | width: 120, |
| | | align: "left", |
| | | bind: { key: "location", data: [] }, |
| | | }, |
| | | { |
| | | field: "currentAddress", |
| | |
| | | type: "string", |
| | | width: 120, |
| | | align: "left", |
| | | bind: { key: "location", data: [] }, |
| | | hidden:true, |
| | | }, |
| | | { |
| | | field: "nextAddress", |
| | |
| | | type: "string", |
| | | width: 120, |
| | | align: "left", |
| | | bind: { key: "location", data: [] }, |
| | | hidden:true, |
| | | }, |
| | | { |
| | | field: "exceptionMessage", |
| | |
| | | type: "datetime", |
| | | width: 150, |
| | | align: "left", |
| | | sort:true, |
| | | }, |
| | | { |
| | | field: "modifier", |
| | |
| | | type: "datetime", |
| | | width: 160, |
| | | align: "left", |
| | | sort:true, |
| | | }, |
| | | { |
| | | field: "remark", |
¶Ô±ÈÐÂÎļþ |
| | |
| | | { |
| | | "Version": 1, |
| | | "WorkspaceRootPath": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\", |
| | | "Documents": [ |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_server\\controllers\\task\\taskcontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|solutionrelative:wideseawcs_server\\controllers\\task\\taskcontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{83F18A31-5983-4587-A0B2-414BF70E50B5}|WIDESEAWCS_TaskInfoService\\WIDESEAWCS_TaskInfoService.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_taskinfoservice\\taskservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{83F18A31-5983-4587-A0B2-414BF70E50B5}|WIDESEAWCS_TaskInfoService\\WIDESEAWCS_TaskInfoService.csproj|solutionrelative:wideseawcs_taskinfoservice\\taskservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{83F18A31-5983-4587-A0B2-414BF70E50B5}|WIDESEAWCS_TaskInfoService\\WIDESEAWCS_TaskInfoService.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_taskinfoservice\\taskexecutedetailservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{83F18A31-5983-4587-A0B2-414BF70E50B5}|WIDESEAWCS_TaskInfoService\\WIDESEAWCS_TaskInfoService.csproj|solutionrelative:wideseawcs_taskinfoservice\\taskexecutedetailservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_tasks\\conveyorlinejob\\commonconveyorlinejob.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|solutionrelative:wideseawcs_tasks\\conveyorlinejob\\commonconveyorlinejob.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_tasks\\stackercranejob\\commonstackercranejob.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|solutionrelative:wideseawcs_tasks\\stackercranejob\\commonstackercranejob.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_server\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|solutionrelative:wideseawcs_server\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{C2D3D138-9109-481B-8BEB-A27597890B2C}|WIDESEAWCS_DTO\\WIDESEAWCS_DTO.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_dto\\enum\\taskstatusenum.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{C2D3D138-9109-481B-8BEB-A27597890B2C}|WIDESEAWCS_DTO\\WIDESEAWCS_DTO.csproj|solutionrelative:wideseawcs_dto\\enum\\taskstatusenum.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_tasks\\testjob.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|solutionrelative:wideseawcs_tasks\\testjob.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{8C2CC25B-DE5D-433E-A550-63864C7A716D}|WIDESEAWCS_IBasicInfoService\\WIDESEAWCS_IBasicInfoService.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_ibasicinfoservice\\idt_stationmanagerservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{8C2CC25B-DE5D-433E-A550-63864C7A716D}|WIDESEAWCS_IBasicInfoService\\WIDESEAWCS_IBasicInfoService.csproj|solutionrelative:wideseawcs_ibasicinfoservice\\idt_stationmanagerservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_tasks\\conveyorlinejob\\conveyorlinetaskcommand.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|solutionrelative:wideseawcs_tasks\\conveyorlinejob\\conveyorlinetaskcommand.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{7F200FE8-CAF6-4131-BD25-8D438FE0ABAC}|WIDESEAWCS_Model\\WIDESEAWCS_Model.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_model\\models\\basicinfo\\dt_stationmanager.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{7F200FE8-CAF6-4131-BD25-8D438FE0ABAC}|WIDESEAWCS_Model\\WIDESEAWCS_Model.csproj|solutionrelative:wideseawcs_model\\models\\basicinfo\\dt_stationmanager.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_server\\appsettings.json||{90A6B3A7-C1A3-4009-A288-E2FF89E96FA0}", |
| | | "RelativeMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|solutionrelative:wideseawcs_server\\appsettings.json||{90A6B3A7-C1A3-4009-A288-E2FF89E96FA0}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_tasks\\stackercranejob\\stackercranedbname.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|solutionrelative:wideseawcs_tasks\\stackercranejob\\stackercranedbname.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{7F200FE8-CAF6-4131-BD25-8D438FE0ABAC}|WIDESEAWCS_Model\\WIDESEAWCS_Model.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_model\\models\\taskinfo\\dt_task.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{7F200FE8-CAF6-4131-BD25-8D438FE0ABAC}|WIDESEAWCS_Model\\WIDESEAWCS_Model.csproj|solutionrelative:wideseawcs_model\\models\\taskinfo\\dt_task.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_server\\controllers\\system\\sys_dictionarycontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|solutionrelative:wideseawcs_server\\controllers\\system\\sys_dictionarycontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | } |
| | | ], |
| | | "DocumentGroupContainers": [ |
| | | { |
| | | "Orientation": 0, |
| | | "VerticalTabListWidth": 256, |
| | | "DocumentGroups": [ |
| | | { |
| | | "DockedWidth": 200, |
| | | "SelectedChildIndex": 2, |
| | | "Children": [ |
| | | { |
| | | "$type": "Bookmark", |
| | | "Name": "ST:128:0:{1fc202d4-d401-403c-9834-5b218574bb67}" |
| | | }, |
| | | { |
| | | "$type": "Bookmark", |
| | | "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 0, |
| | | "Title": "TaskController.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\Controllers\\Task\\TaskController.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Server\\Controllers\\Task\\TaskController.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\Controllers\\Task\\TaskController.cs*", |
| | | "RelativeToolTip": "WIDESEAWCS_Server\\Controllers\\Task\\TaskController.cs*", |
| | | "ViewState": "AgIAAAoAAAAAAAAAAAAYwBcAAAA7AAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-12T01:30:32.857Z", |
| | | "EditorCaption": "" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 4, |
| | | "Title": "CommonStackerCraneJob.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\StackerCraneJob\\CommonStackerCraneJob.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Tasks\\StackerCraneJob\\CommonStackerCraneJob.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\StackerCraneJob\\CommonStackerCraneJob.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Tasks\\StackerCraneJob\\CommonStackerCraneJob.cs", |
| | | "ViewState": "AgIAAGcAAAAAAAAAAADwv1wAAAAnAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-10T07:20:51.488Z", |
| | | "EditorCaption": "" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 3, |
| | | "Title": "CommonConveyorLineJob.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\ConveyorLineJob\\CommonConveyorLineJob.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Tasks\\ConveyorLineJob\\CommonConveyorLineJob.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\ConveyorLineJob\\CommonConveyorLineJob.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Tasks\\ConveyorLineJob\\CommonConveyorLineJob.cs", |
| | | "ViewState": "AgIAAKAAAAAAAAAAAAAvwKoAAAARAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T00:33:00.02Z", |
| | | "EditorCaption": "" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 1, |
| | | "Title": "TaskService.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_TaskInfoService\\TaskService.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_TaskInfoService\\TaskService.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_TaskInfoService\\TaskService.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_TaskInfoService\\TaskService.cs", |
| | | "ViewState": "AgIAAFgAAAAAAAAAAAAgwGkAAAAQAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T02:52:33.157Z", |
| | | "EditorCaption": "" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 2, |
| | | "Title": "TaskExecuteDetailService.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_TaskInfoService\\TaskExecuteDetailService.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_TaskInfoService\\TaskExecuteDetailService.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_TaskInfoService\\TaskExecuteDetailService.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_TaskInfoService\\TaskExecuteDetailService.cs", |
| | | "ViewState": "AgIAAFYAAAAAAAAAAADwv1oAAAANAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T02:54:03.845Z", |
| | | "EditorCaption": "" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 5, |
| | | "Title": "Program.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\Program.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Server\\Program.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\Program.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Server\\Program.cs", |
| | | "ViewState": "AgIAAHgAAAAAAAAAAADwvwAAAAAAAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T05:42:49.47Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 12, |
| | | "Title": "StackerCraneDBName.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\StackerCraneJob\\StackerCraneDBName.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Tasks\\StackerCraneJob\\StackerCraneDBName.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\StackerCraneJob\\StackerCraneDBName.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Tasks\\StackerCraneJob\\StackerCraneDBName.cs", |
| | | "ViewState": "AgIAAEIAAAAAAAAAAAAAAF0AAAAOAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-10T09:13:25.087Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 13, |
| | | "Title": "Dt_Task.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Model\\Models\\TaskInfo\\Dt_Task.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Model\\Models\\TaskInfo\\Dt_Task.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Model\\Models\\TaskInfo\\Dt_Task.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Model\\Models\\TaskInfo\\Dt_Task.cs", |
| | | "ViewState": "AgIAAAAAAAAAAAAAAAAAAB8AAAAHAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-10T08:43:01.804Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 6, |
| | | "Title": "TaskStatusEnum.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_DTO\\Enum\\TaskStatusEnum.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_DTO\\Enum\\TaskStatusEnum.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_DTO\\Enum\\TaskStatusEnum.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_DTO\\Enum\\TaskStatusEnum.cs", |
| | | "ViewState": "AgIAAJUAAAAAAAAAAAAnwJ8AAAAMAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-10T08:33:01.088Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 8, |
| | | "Title": "IDt_StationManagerService.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_IBasicInfoService\\IDt_StationManagerService.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_IBasicInfoService\\IDt_StationManagerService.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_IBasicInfoService\\IDt_StationManagerService.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_IBasicInfoService\\IDt_StationManagerService.cs", |
| | | "ViewState": "AgIAABsAAAAAAAAAAAAnwDIAAAAnAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T01:09:00.319Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 9, |
| | | "Title": "ConveyorLineTaskCommand.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\ConveyorLineJob\\ConveyorLineTaskCommand.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Tasks\\ConveyorLineJob\\ConveyorLineTaskCommand.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\ConveyorLineJob\\ConveyorLineTaskCommand.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Tasks\\ConveyorLineJob\\ConveyorLineTaskCommand.cs", |
| | | "ViewState": "AgIAAAAAAAAAAAAAAAAuwBwAAAA1AAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T01:17:59.023Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 7, |
| | | "Title": "TestJob.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\TestJob.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Tasks\\TestJob.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\TestJob.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Tasks\\TestJob.cs", |
| | | "ViewState": "AgIAAAAAAAAAAAAAAADwvwAAAAAAAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T01:43:47.806Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 10, |
| | | "Title": "Dt_StationManager.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Model\\Models\\BasicInfo\\Dt_StationManager.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Model\\Models\\BasicInfo\\Dt_StationManager.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Model\\Models\\BasicInfo\\Dt_StationManager.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Model\\Models\\BasicInfo\\Dt_StationManager.cs", |
| | | "ViewState": "AgIAAC8AAAAAAAAAAAAhwD8AAAAgAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-10T08:42:55.586Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 14, |
| | | "Title": "Sys_DictionaryController.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\Controllers\\System\\Sys_DictionaryController.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Server\\Controllers\\System\\Sys_DictionaryController.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\Controllers\\System\\Sys_DictionaryController.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Server\\Controllers\\System\\Sys_DictionaryController.cs", |
| | | "ViewState": "AgIAACIBAAAAAAAAAADwv1MBAABEAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-10T08:32:07.315Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 11, |
| | | "Title": "appsettings.json", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\appsettings.json", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Server\\appsettings.json", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\appsettings.json", |
| | | "RelativeToolTip": "WIDESEAWCS_Server\\appsettings.json", |
| | | "ViewState": "AgIAAAAAAAAAAAAAAAAAAAgAAABSAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001642|", |
| | | "WhenOpened": "2025-06-10T07:20:02.074Z" |
| | | } |
| | | ] |
| | | } |
| | | ] |
| | | } |
| | | ] |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | { |
| | | "Version": 1, |
| | | "WorkspaceRootPath": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\", |
| | | "Documents": [ |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{6236BFFF-173D-44A8-9FC3-7C001EA30347}|WIDESEAWCS_QuartzJob\\WIDESEAWCS_QuartzJob.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_quartzjob\\stackercrane\\common\\commonstackercrane.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{6236BFFF-173D-44A8-9FC3-7C001EA30347}|WIDESEAWCS_QuartzJob\\WIDESEAWCS_QuartzJob.csproj|solutionrelative:wideseawcs_quartzjob\\stackercrane\\common\\commonstackercrane.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_tasks\\stackercranejob\\commonstackercranejob.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|solutionrelative:wideseawcs_tasks\\stackercranejob\\commonstackercranejob.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_server\\controllers\\task\\taskcontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|solutionrelative:wideseawcs_server\\controllers\\task\\taskcontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{83F18A31-5983-4587-A0B2-414BF70E50B5}|WIDESEAWCS_TaskInfoService\\WIDESEAWCS_TaskInfoService.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_taskinfoservice\\taskservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{83F18A31-5983-4587-A0B2-414BF70E50B5}|WIDESEAWCS_TaskInfoService\\WIDESEAWCS_TaskInfoService.csproj|solutionrelative:wideseawcs_taskinfoservice\\taskservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_tasks\\conveyorlinejob\\commonconveyorlinejob.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|solutionrelative:wideseawcs_tasks\\conveyorlinejob\\commonconveyorlinejob.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_server\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|solutionrelative:wideseawcs_server\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{C2D3D138-9109-481B-8BEB-A27597890B2C}|WIDESEAWCS_DTO\\WIDESEAWCS_DTO.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_dto\\enum\\taskstatusenum.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{C2D3D138-9109-481B-8BEB-A27597890B2C}|WIDESEAWCS_DTO\\WIDESEAWCS_DTO.csproj|solutionrelative:wideseawcs_dto\\enum\\taskstatusenum.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_tasks\\testjob.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|solutionrelative:wideseawcs_tasks\\testjob.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{8C2CC25B-DE5D-433E-A550-63864C7A716D}|WIDESEAWCS_IBasicInfoService\\WIDESEAWCS_IBasicInfoService.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_ibasicinfoservice\\idt_stationmanagerservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{8C2CC25B-DE5D-433E-A550-63864C7A716D}|WIDESEAWCS_IBasicInfoService\\WIDESEAWCS_IBasicInfoService.csproj|solutionrelative:wideseawcs_ibasicinfoservice\\idt_stationmanagerservice.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_tasks\\conveyorlinejob\\conveyorlinetaskcommand.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|solutionrelative:wideseawcs_tasks\\conveyorlinejob\\conveyorlinetaskcommand.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{7F200FE8-CAF6-4131-BD25-8D438FE0ABAC}|WIDESEAWCS_Model\\WIDESEAWCS_Model.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_model\\models\\basicinfo\\dt_stationmanager.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{7F200FE8-CAF6-4131-BD25-8D438FE0ABAC}|WIDESEAWCS_Model\\WIDESEAWCS_Model.csproj|solutionrelative:wideseawcs_model\\models\\basicinfo\\dt_stationmanager.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_server\\appsettings.json||{90A6B3A7-C1A3-4009-A288-E2FF89E96FA0}", |
| | | "RelativeMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|solutionrelative:wideseawcs_server\\appsettings.json||{90A6B3A7-C1A3-4009-A288-E2FF89E96FA0}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_tasks\\stackercranejob\\stackercranedbname.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{294E4915-0241-4C8C-BA99-7588B945863A}|WIDESEAWCS_Tasks\\WIDESEAWCS_Tasks.csproj|solutionrelative:wideseawcs_tasks\\stackercranejob\\stackercranedbname.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{7F200FE8-CAF6-4131-BD25-8D438FE0ABAC}|WIDESEAWCS_Model\\WIDESEAWCS_Model.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_model\\models\\taskinfo\\dt_task.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{7F200FE8-CAF6-4131-BD25-8D438FE0ABAC}|WIDESEAWCS_Model\\WIDESEAWCS_Model.csproj|solutionrelative:wideseawcs_model\\models\\taskinfo\\dt_task.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | }, |
| | | { |
| | | "AbsoluteMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|e:\\get\\jiangxijiujiang\\\u9879\u76EE\u4EE3\u7801\\wcs\\wideseawcs_server\\wideseawcs_server\\controllers\\system\\sys_dictionarycontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", |
| | | "RelativeMoniker": "D:0:0:{487FA45B-EA1A-4ACA-BB5B-0F6708F462C0}|WIDESEAWCS_Server\\WIDESEAWCS_Server.csproj|solutionrelative:wideseawcs_server\\controllers\\system\\sys_dictionarycontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" |
| | | } |
| | | ], |
| | | "DocumentGroupContainers": [ |
| | | { |
| | | "Orientation": 0, |
| | | "VerticalTabListWidth": 256, |
| | | "DocumentGroups": [ |
| | | { |
| | | "DockedWidth": 200, |
| | | "SelectedChildIndex": 2, |
| | | "Children": [ |
| | | { |
| | | "$type": "Bookmark", |
| | | "Name": "ST:128:0:{1fc202d4-d401-403c-9834-5b218574bb67}" |
| | | }, |
| | | { |
| | | "$type": "Bookmark", |
| | | "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 0, |
| | | "Title": "CommonStackerCrane.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_QuartzJob\\StackerCrane\\Common\\CommonStackerCrane.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_QuartzJob\\StackerCrane\\Common\\CommonStackerCrane.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_QuartzJob\\StackerCrane\\Common\\CommonStackerCrane.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_QuartzJob\\StackerCrane\\Common\\CommonStackerCrane.cs", |
| | | "ViewState": "AgIAABcAAAAAAAAAAADwvycAAAAVAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-12T01:50:11.447Z", |
| | | "EditorCaption": "" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 2, |
| | | "Title": "TaskController.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\Controllers\\Task\\TaskController.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Server\\Controllers\\Task\\TaskController.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\Controllers\\Task\\TaskController.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Server\\Controllers\\Task\\TaskController.cs", |
| | | "ViewState": "AgIAAAoAAAAAAAAAAAAYwBkAAAAMAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-12T01:30:32.857Z", |
| | | "EditorCaption": "" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 1, |
| | | "Title": "CommonStackerCraneJob.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\StackerCraneJob\\CommonStackerCraneJob.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Tasks\\StackerCraneJob\\CommonStackerCraneJob.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\StackerCraneJob\\CommonStackerCraneJob.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Tasks\\StackerCraneJob\\CommonStackerCraneJob.cs", |
| | | "ViewState": "AgIAACoAAAAAAAAAAAAAADYAAAAiAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-10T07:20:51.488Z", |
| | | "EditorCaption": "" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 4, |
| | | "Title": "CommonConveyorLineJob.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\ConveyorLineJob\\CommonConveyorLineJob.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Tasks\\ConveyorLineJob\\CommonConveyorLineJob.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\ConveyorLineJob\\CommonConveyorLineJob.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Tasks\\ConveyorLineJob\\CommonConveyorLineJob.cs", |
| | | "ViewState": "AgIAADkBAAAAAAAAAAAiwFcBAAATAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T00:33:00.02Z", |
| | | "EditorCaption": "" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 3, |
| | | "Title": "TaskService.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_TaskInfoService\\TaskService.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_TaskInfoService\\TaskService.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_TaskInfoService\\TaskService.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_TaskInfoService\\TaskService.cs", |
| | | "ViewState": "AgIAAAQCAAAAAAAAAAAAACACAAAIAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T02:52:33.157Z", |
| | | "EditorCaption": "" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 5, |
| | | "Title": "Program.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\Program.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Server\\Program.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\Program.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Server\\Program.cs", |
| | | "ViewState": "AgIAAHgAAAAAAAAAAADwvwAAAAAAAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T05:42:49.47Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 12, |
| | | "Title": "StackerCraneDBName.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\StackerCraneJob\\StackerCraneDBName.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Tasks\\StackerCraneJob\\StackerCraneDBName.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\StackerCraneJob\\StackerCraneDBName.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Tasks\\StackerCraneJob\\StackerCraneDBName.cs", |
| | | "ViewState": "AgIAAEIAAAAAAAAAAAAAAF0AAAAOAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-10T09:13:25.087Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 13, |
| | | "Title": "Dt_Task.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Model\\Models\\TaskInfo\\Dt_Task.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Model\\Models\\TaskInfo\\Dt_Task.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Model\\Models\\TaskInfo\\Dt_Task.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Model\\Models\\TaskInfo\\Dt_Task.cs", |
| | | "ViewState": "AgIAAAAAAAAAAAAAAAAAAB8AAAAHAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-10T08:43:01.804Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 6, |
| | | "Title": "TaskStatusEnum.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_DTO\\Enum\\TaskStatusEnum.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_DTO\\Enum\\TaskStatusEnum.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_DTO\\Enum\\TaskStatusEnum.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_DTO\\Enum\\TaskStatusEnum.cs", |
| | | "ViewState": "AgIAAJUAAAAAAAAAAAAnwJ8AAAAMAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-10T08:33:01.088Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 8, |
| | | "Title": "IDt_StationManagerService.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_IBasicInfoService\\IDt_StationManagerService.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_IBasicInfoService\\IDt_StationManagerService.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_IBasicInfoService\\IDt_StationManagerService.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_IBasicInfoService\\IDt_StationManagerService.cs", |
| | | "ViewState": "AgIAABsAAAAAAAAAAAAnwDIAAAAnAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T01:09:00.319Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 9, |
| | | "Title": "ConveyorLineTaskCommand.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\ConveyorLineJob\\ConveyorLineTaskCommand.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Tasks\\ConveyorLineJob\\ConveyorLineTaskCommand.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\ConveyorLineJob\\ConveyorLineTaskCommand.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Tasks\\ConveyorLineJob\\ConveyorLineTaskCommand.cs", |
| | | "ViewState": "AgIAAAAAAAAAAAAAAAAuwBwAAAA1AAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T01:17:59.023Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 7, |
| | | "Title": "TestJob.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\TestJob.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Tasks\\TestJob.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Tasks\\TestJob.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Tasks\\TestJob.cs", |
| | | "ViewState": "AgIAAAAAAAAAAAAAAADwvwAAAAAAAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-11T01:43:47.806Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 10, |
| | | "Title": "Dt_StationManager.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Model\\Models\\BasicInfo\\Dt_StationManager.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Model\\Models\\BasicInfo\\Dt_StationManager.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Model\\Models\\BasicInfo\\Dt_StationManager.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Model\\Models\\BasicInfo\\Dt_StationManager.cs", |
| | | "ViewState": "AgIAAC8AAAAAAAAAAAAhwD8AAAAgAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-10T08:42:55.586Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 14, |
| | | "Title": "Sys_DictionaryController.cs", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\Controllers\\System\\Sys_DictionaryController.cs", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Server\\Controllers\\System\\Sys_DictionaryController.cs", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\Controllers\\System\\Sys_DictionaryController.cs", |
| | | "RelativeToolTip": "WIDESEAWCS_Server\\Controllers\\System\\Sys_DictionaryController.cs", |
| | | "ViewState": "AgIAACIBAAAAAAAAAADwv1MBAABEAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", |
| | | "WhenOpened": "2025-06-10T08:32:07.315Z" |
| | | }, |
| | | { |
| | | "$type": "Document", |
| | | "DocumentIndex": 11, |
| | | "Title": "appsettings.json", |
| | | "DocumentMoniker": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\appsettings.json", |
| | | "RelativeDocumentMoniker": "WIDESEAWCS_Server\\appsettings.json", |
| | | "ToolTip": "E:\\GET\\JiangXiJiuJiang\\\u9879\u76EE\u4EE3\u7801\\WCS\\WIDESEAWCS_Server\\WIDESEAWCS_Server\\appsettings.json", |
| | | "RelativeToolTip": "WIDESEAWCS_Server\\appsettings.json", |
| | | "ViewState": "AgIAAAAAAAAAAAAAAAAAAAgAAABSAAAAAAAAAA==", |
| | | "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001642|", |
| | | "WhenOpened": "2025-06-10T07:20:02.074Z" |
| | | } |
| | | ] |
| | | } |
| | | ] |
| | | } |
| | | ] |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | { |
| | | // ä½¿ç¨ IntelliSense äºè§£ç¸å
³å±æ§ã |
| | | // æ¬å以æ¥çç°æå±æ§çæè¿°ã |
| | | // 欲äºè§£æ´å¤ä¿¡æ¯ï¼è¯·è®¿é®: https://go.microsoft.com/fwlink/?linkid=830387 |
| | | "version": "0.2.0", |
| | | "configurations": [] |
| | | } |
ÎļþÃû´Ó ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemRepository/AgvStationRepository.cs ÐÞ¸Ä |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_ISystemRepository; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | using WIDESEAWCS_Model.Models.BasicInfo; |
| | | |
| | | namespace WIDESEAWCS_SystemRepository |
| | | namespace WIDESEAWCS_BasicInfoRepository |
| | | { |
| | | public class AgvStationRepository : RepositoryBase<AGVStation>, IAgvStationRepository |
| | | public class Dt_StationManagerRepository : RepositoryBase<Dt_StationManager>, IDt_StationManagerRepository |
| | | { |
| | | public AgvStationRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage) |
| | | public Dt_StationManagerRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage) |
| | | { |
| | | } |
| | | } |
| | |
| | | <Project Sdk="Microsoft.NET.Sdk"> |
| | | <Project Sdk="Microsoft.NET.Sdk"> |
| | | |
| | | <PropertyGroup> |
| | | <TargetFramework>net6.0</TargetFramework> |
| | | <ImplicitUsings>enable</ImplicitUsings> |
| | | <Nullable>enable</Nullable> |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="WIDESEAWCS_Core" Version="1.0.7" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\WIDESEAWCS_IBasicInfoRepository\WIDESEAWCS_IBasicInfoRepository.csproj" /> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_TaskInfoService |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using AutoMapper; |
| | | using Microsoft.AspNetCore.Mvc.RazorPages; |
| | | using NetTaste; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Diagnostics; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Linq; |
| | | using System.Linq.Expressions; |
| | | using System.Reflection; |
| | | using System.Reflection.Metadata; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_DTO.Enum; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_IBasicInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.BasicInfo; |
| | | |
| | | namespace WIDESEAWCS_BasicInfoService |
| | | { |
| | | public class Dt_StationManagerService : ServiceBase<Dt_StationManager, IDt_StationManagerRepository>, IDt_StationManagerService |
| | | { |
| | | public Dt_StationManagerService(IDt_StationManagerRepository BaseDal) : base(BaseDal) |
| | | { |
| | | |
| | | } |
| | | public class Station_materialList |
| | | { |
| | | /// <summary> |
| | | /// 䏿ä½-ãã䏿æåæ¾ |
| | | /// </summary> |
| | | public static List<int> BoardLoadList = new List<int>() { (int)AgvStationEnum.BoardLoad, (int)AgvStationEnum.PadUse }; |
| | | |
| | | /// <summary> |
| | | /// 䏿ï¼ä¸æï¼å«æ¿ä½¿ç¨ï¼å«æ¿åæ¶ |
| | | /// </summary> |
| | | public static List<int> UsebitsList = new List<int>() { (int)AgvStationEnum.BoardUnload,(int)AgvStationEnum.PadRecycle}; |
| | | |
| | | |
| | | public static List<string> StationareaList = new List<string>() {"1003","1004" , "1005","1006","1007" }; |
| | | } |
| | | public List<Dt_StationManager> QuerypLatform(string deviceNo,List<string> task) |
| | | { |
| | | return BaseDal.QueryData(x=>x.DeviceCode == deviceNo && x.stationEnable==1 && Station_materialList.UsebitsList.Contains(x.stationMaterial) && !task.Contains(x.stationName)).ToList(); |
| | | } |
| | | |
| | | public List<Dt_StationManager> QuerypLatformarer(string deviceNo) |
| | | { |
| | | return BaseDal.QueryData((x => x.DeviceCode == deviceNo && x.stationEnable == 1 && Station_materialList.BoardLoadList.Contains(x.stationMaterial)), x=>x.stationMaterial).ToList(); |
| | | } |
| | | |
| | | public List<Dt_StationManager> QuerypLatformmaterial(int Station_Area) |
| | | { |
| | | return BaseDal.QueryData(x => x.stationArea == Station_Area && x.stationEnable == 1 && (x.stationMaterial == (int)AgvStationEnum.BoardStore || x.stationMaterial == (int)AgvStationEnum.PadStore) ).ToList(); |
| | | } |
| | | |
| | | public List<Dt_StationManager> QuerypStation_Area(int Station_Area) |
| | | { |
| | | return BaseDal.QueryData(x => x.stationArea == Station_Area && x.stationEnable == 1 && x.stationMaterial == (int)AgvStationEnum.PadStore).ToList(); |
| | | } |
| | | |
| | | public List<Dt_StationManager> QuerypStation_Area2(string Station_remark) |
| | | { |
| | | return BaseDal.QueryData(x => Station_remark.Contains(x.stationRemark) && x.stationEnable == 1 && x.stationMaterial == (int)AgvStationEnum.PadStore).ToList(); |
| | | } |
| | | |
| | | public List<Dt_StationManager> GetAllStationByDeviceCode(string DeviceCode) |
| | | { |
| | | return BaseDal.QueryData(x => x.DeviceCode == DeviceCode && x.stationEnable == 1).ToList(); |
| | | } |
| | | } |
| | | } |
| | |
| | | <Project Sdk="Microsoft.NET.Sdk"> |
| | | <Project Sdk="Microsoft.NET.Sdk"> |
| | | |
| | | <PropertyGroup> |
| | | <TargetFramework>net6.0</TargetFramework> |
| | |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="WIDESEAWCS_Core" Version="1.0.7" /> |
| | | <PackageReference Include="WIDESEAWCS_QuartzJob" Version="2.1.2" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\WIDESEAWCS_IBasicInfoService\WIDESEAWCS_IBasicInfoService.csproj" /> |
| | | <ProjectReference Include="..\WIDESEAWCS_QuartzJob\WIDESEAWCS_QuartzJob.csproj" /> |
| | | </ItemGroup> |
| | | |
| | | </Project> |
| | |
| | |  |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json; |
| | | using System.Net; |
| | | using System.Text; |
| | | using WIDESEA_Common.Log; |
| | |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> |
| | | <PackageReference Include="WIDESEAWCS_Core" Version="1.0.7" /> |
| | | </ItemGroup> |
| | | |
| | | </Project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_Communicator |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼åºç¡é讯æ½è±¡ç±»ï¼å°è£
è¿æ¥ãæå¼è¿æ¥ã读åãåå
¥çæ¹æ³ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using HslCommunication; |
| | | using HslCommunication.LogNet; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | |
| | | namespace WIDESEAWCS_Communicator |
| | | { |
| | | public abstract class BaseCommunicator: IDisposable |
| | | { |
| | | /// <summary> |
| | | /// æé 彿° |
| | | /// </summary> |
| | | protected BaseCommunicator() |
| | | { |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥å¿è®°å½å®ä¾å¯¹è±¡ |
| | | /// </summary> |
| | | public abstract ILogNet LogNet { get; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤åç§° |
| | | /// </summary> |
| | | public abstract string Name { get; } |
| | | |
| | | /// <summary> |
| | | /// è·åå½åéè®¯å¨æ¯å¦å·²è¿æ¥å°PLCã |
| | | /// </summary> |
| | | public abstract bool IsConnected { get; } |
| | | |
| | | /// <summary> |
| | | /// è¿æ¥å°PLCã |
| | | /// </summary> |
| | | /// <returns>å¦æè¿æ¥æååè¿åtrueï¼å¦åè¿åfalseã</returns> |
| | | public abstract bool Connect(); |
| | | |
| | | /// <summary> |
| | | /// æå¼ä¸å·¥ä¸è®¾å¤çè¿æ¥ã |
| | | /// </summary> |
| | | /// <returns>妿æåæå¼è¿æ¥åè¿åtrueï¼å¦æå·²ç»æ¯æå¼ç¶æåè¿åfalseã</returns> |
| | | public abstract bool Disconnect(); |
| | | |
| | | /// <summary> |
| | | /// ä»PLCè¯»åæ°æ®ã |
| | | /// </summary> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <param name="length">è¦è¯»åçæ°æ®é¿åº¦ã</param> |
| | | /// <returns>读åå°çæ°æ®ï¼å¦æè¯»å失败åå¯è½è¿ånullæç©ºæ°ç»ã</returns> |
| | | public abstract byte[] Read(string address, int length); |
| | | |
| | | /// <summary> |
| | | /// ä»PLCè¯»åæ°æ®ã |
| | | /// </summary> |
| | | /// <typeparam name="T">è¯»åæ°æ®çç±»åæ³åã</typeparam> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <returns>读åå°çæ°æ®ï¼å¦æè¯»å失败åå¯è½è¿ånullææåºå¼å¸¸ã</returns> |
| | | public abstract T Read<T>(string address); |
| | | |
| | | /// <summary> |
| | | /// ä»PLCè¯»åæ°æ®ã |
| | | /// </summary> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <param name="dataType">æ°æ®ç±»åã</param> |
| | | /// <returns>读åå°çæ°æ®ï¼å¦æè¯»å失败åå¯è½è¿ånullææåºå¼å¸¸ã</returns> |
| | | public abstract object ReadAsObj(string address, string dataType); |
| | | |
| | | /// <summary> |
| | | /// åPLCåå
¥æ°æ®ã |
| | | /// </summary> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <param name="data">è¦åå
¥çæ°æ®ã</param> |
| | | /// <returns>妿åå
¥æååè¿åtrueï¼å¦åæåºå¼å¸¸ã</returns> |
| | | public abstract bool Write(string address, byte[] data); |
| | | |
| | | /// <summary> |
| | | /// åPLCåå
¥æ°æ®ã |
| | | /// </summary> |
| | | /// <typeparam name="T">è¯»åæ°æ®çç±»åæ³åã</typeparam> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <param name="value">è¦åå
¥çæ°æ®ã</param> |
| | | /// <returns>妿åå
¥æååè¿åtrueï¼å¦åæåºå¼å¸¸ã</returns> |
| | | public abstract bool Write<T>(string address, T value) where T : notnull; |
| | | |
| | | /// <summary> |
| | | /// åPLCåå
¥æ°æ®ã |
| | | /// </summary> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <param name="dataType">è¦åå
¥çæ°æ®ç±»åã</param> |
| | | /// <param name="value">è¦åå
¥çæ°æ®ã</param> |
| | | /// <returns>妿åå
¥æååè¿åtrueï¼å¤±è´¥åæåºå¼å¸¸ã</returns> |
| | | /// <exception cref="CommunicationException"></exception> |
| | | public abstract bool WriteObj(string address, string dataType, object value); |
| | | |
| | | /// <summary> |
| | | /// çå¾
æå®å°åçæ³åç±»åå¼ä¸ºæå®çå¼ |
| | | /// </summary> |
| | | /// <typeparam name="T">æå®çå¼çç±»åæ³åã</typeparam> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <param name="readInterval">读åçé¢çã</param> |
| | | /// <param name="waitTimeout">çå¾
çè¶
æ¶æ¶é´ï¼å¦æè¶
æ¶æ¶é´ä¸º-1çè¯ï¼åæ¯æ æéçå¾
ã</param> |
| | | /// <param name="value">çå¾
æ£æµçå¼</param> |
| | | /// <returns>æ¯å¦çå¾
æåçç»æå¯¹è±¡ï¼ä¸æ¦éä¿¡å¤±è´¥ï¼ææ¯çå¾
è¶
æ¶å°±è¿å失败ãå¦åè¿åæåï¼å¹¶åç¥è°ç¨æ¹çå¾
äºå¤ä¹
ã</returns> |
| | | public abstract OperateResult<TimeSpan> Wait<T>(string address, int readInterval, int waitTimeout, T value) where T : struct; |
| | | |
| | | /// <summary> |
| | | /// 读åèªå®ä¹çæ°æ®ç±»åï¼éè¦ç»§æ¿èªIDataTransferæ¥å£ï¼è¿åä¸ä¸ªæ°çç±»åçå®ä¾å¯¹è±¡ã |
| | | /// </summary> |
| | | /// <typeparam name="T">èªå®ä¹çæ°æ®ç±»åæ³åã</typeparam> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <returns>æåè¿åèªå®ä¹ç±»åæ°æ®ï¼å¤±è´¥æåºå¼å¸¸ã</returns> |
| | | public abstract T ReadCustomer<T>(string address) where T : IDataTransfer, new(); |
| | | |
| | | /// <summary> |
| | | /// åå
¥èªå®ä¹ç±»åçæ°æ®ï¼è¯¥ç±»åå¿
须继æ¿èªIDataTransferæ¥å£ã |
| | | /// </summary> |
| | | /// <typeparam name="T">èªå®ä¹çæ°æ®ç±»åæ³åã</typeparam> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <param name="value">è¦åå
¥æ°æ®ã</param> |
| | | /// <returns>妿åå
¥æååè¿åtrueï¼å¤±è´¥åæåºå¼å¸¸ã</returns> |
| | | public abstract bool WriteCustomer<T>(string address, [NotNull] T value) where T : IDataTransfer, new(); |
| | | |
| | | /// <summary> |
| | | /// éæ¾å¯¹è±¡èµæºçæ¥å£ã |
| | | /// </summary> |
| | | public abstract void Dispose(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_Communicator |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼èªå®ä¹é讯å¼å¸¸ç±»ï¼å®ä¹äºé误类åãé误代ç (ææ¶æ²¡å®ä¹é误代ç 表) |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using HslCommunication.LogNet; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Communicator |
| | | { |
| | | /// <summary> |
| | | /// å·¥ä¸éä¿¡é误类ï¼å°è£
äºä¸PLCéä¿¡æ¶å¯è½åççé误ã |
| | | /// </summary> |
| | | [Serializable] // ç¡®ä¿ç±»æ¯æåºåå |
| | | public class CommunicationException : Exception |
| | | { |
| | | //public static ILogNet logNet = new LogNetFileSize() |
| | | |
| | | /// <summary> |
| | | /// é误代ç ã |
| | | /// </summary> |
| | | public int? ErrorCode { get; } |
| | | |
| | | /// <summary> |
| | | /// éä¿¡é误çç±»åã |
| | | /// </summary> |
| | | public CommunicationErrorType ErrorType { get; } |
| | | |
| | | /// <summary> |
| | | /// éè¯¯ä¿¡æ¯ |
| | | /// </summary> |
| | | public override string Message => _message; |
| | | |
| | | private string _message; |
| | | |
| | | /// <summary> |
| | | /// åå§åä¸ä¸ªæ°ç CommunicationException å®ä¾ã |
| | | /// </summary> |
| | | /// <param name="message">é误çæè¿°ã</param> |
| | | /// <param name="plcErrorCode">é误代ç ï¼å¯éï¼ã</param> |
| | | /// <param name="innerException">导è´å½åå¼å¸¸çå¼å¸¸ï¼å¯éï¼ã</param> |
| | | public CommunicationException(string message, CommunicationErrorType errorType, int? plcErrorCode = null, Exception innerException = null) |
| | | : base(message, innerException) |
| | | { |
| | | ErrorCode = plcErrorCode; |
| | | ErrorType = errorType; |
| | | _message = message; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æä¾ä¸ä¸ªæ´å好çå符串表示形å¼ï¼å
å«PLCé误代ç ï¼å¦æå¯ç¨ï¼åä»»ä½å
é¨å¼å¸¸ä¿¡æ¯ã |
| | | /// </summary> |
| | | /// <returns>å¼å¸¸çå符串表示形å¼ã</returns> |
| | | public override string ToString() |
| | | { |
| | | //string plcCodeInfo = ErrorCode.HasValue ? $"PLC Error Code: {ErrorCode.Value}" : "No PLC Error Code"; |
| | | string innerExceptionInfo = InnerException != null ? $"\nInner Exception: {InnerException.Message}" : ""; |
| | | return $"{GetType().Name}: {Message}\n{innerExceptionInfo}"; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å·¥ä¸éä¿¡é误类åæä¸¾ã |
| | | /// </summary> |
| | | public enum CommunicationErrorType |
| | | { |
| | | /// <summary> |
| | | /// IPå°åé误 |
| | | /// </summary> |
| | | IpAddressError, |
| | | /// <summary> |
| | | /// è¿æ¥PLCé误 |
| | | /// </summary> |
| | | ConnectionFailed, |
| | | /// <summary> |
| | | /// æªç¥ç±»åé误 |
| | | /// </summary> |
| | | Unknown, |
| | | /// <summary> |
| | | /// 读å失败 |
| | | /// </summary> |
| | | ReadFailed, |
| | | /// <summary> |
| | | /// åå
¥å¤±è´¥ |
| | | /// </summary> |
| | | WriteFailed, |
| | | /// <summary> |
| | | /// ç±»åé误 |
| | | /// </summary> |
| | | TypeError, |
| | | /// <summary> |
| | | /// 读åå¼å¸¸ |
| | | /// </summary> |
| | | ReadException |
| | | } |
| | | |
| | | public class CommunicationExceptionMessage |
| | | { |
| | | /// <summary> |
| | | /// Ipå°åé误,åæ°ãIPã |
| | | /// </summary> |
| | | public const string IpAddressErrorException = "Ipå°åé误ï¼ã{0}ã"; |
| | | |
| | | /// <summary> |
| | | /// æ°æ®è¯»å失败,åæ°ãæ°æ®ç±»åï¼åè®®å°åï¼é误信æ¯ã |
| | | /// </summary> |
| | | public const string ReadFailedException = "æ°æ®è¯»åå¤±è´¥ï¼æ°æ®ç±»åï¼ã{0}ãï¼å°åï¼ã{1}ãï¼é误信æ¯ï¼ã{2}ã"; |
| | | |
| | | /// <summary> |
| | | /// æ°æ®åå
¥å¤±è´¥,åæ°ãæ°æ®ç±»åï¼åè®®å°åï¼åå
¥çæ°æ®ï¼é误信æ¯ã |
| | | /// </summary> |
| | | public const string WriteFailedException = "æ°æ®åå
¥å¤±è´¥ï¼æ°æ®ç±»åï¼ã{0}ãï¼å°åï¼ã{1}ãï¼åå
¥çæ°æ®ï¼ã{2}ãï¼é误信æ¯ï¼ã{3}ã"; |
| | | |
| | | /// <summary> |
| | | /// æ°æ®ç±»åé误,åæ°ãæ°æ®ç±»åï¼åè®®å°åã |
| | | /// </summary> |
| | | public const string DataTypeErrorException = "æ°æ®ç±»åéè¯¯ï¼æªå®ä¹è¯¥PLCæ°æ®ç±»åï¼ã{0}ãï¼å°åï¼ã{1}ã"; |
| | | |
| | | /// <summary> |
| | | /// æ°æ®è¯»åå¼å¸¸,åæ°ãæ°æ®ç±»åï¼åè®®å°åï¼é误信æ¯ã |
| | | /// </summary> |
| | | public const string ReadException = "æ°æ®è¯»åå¤±è´¥ï¼æ°æ®ç±»åï¼ã{0}ãï¼å°åï¼ã{1}ãï¼é误信æ¯ï¼ã{2}ã"; |
| | | |
| | | /// <summary> |
| | | /// æ°æ®è¯»å失败,åæ°ãæ°æ®ç±»åï¼åè®®å°åï¼é误信æ¯ã |
| | | /// </summary> |
| | | public const string WriteAndReadCheckFaild = "æ°æ®åå
¥åè¯»åæ ¡éªå¤±è´¥ï¼å°åï¼ã{0}ãï¼åå
¥çæ°æ®ï¼ã{1}ãï¼è¯»åçæ°æ®ï¼ã{2}ã"; |
| | | |
| | | /// <summary> |
| | | /// æ°æ®è¯»åé误,ç»æä¸ºnull,åæ°ãåè®®å°åã |
| | | /// </summary> |
| | | public const string ReadDataIsNull = "æ°æ®è¯»åéè¯¯ï¼æªåå°æ°æ®ç»æï¼å°åï¼ã{0}ã"; |
| | | |
| | | /// <summary> |
| | | /// è¿æ¥å¤±è´¥,åæ°ãIPï¼Portï¼é误信æ¯ã |
| | | /// </summary> |
| | | public const string ConnectFaild = "PLCè¿æ¥å¤±è´¥ï¼IPï¼ã{0}ãï¼Portï¼ã{1}ãï¼é误信æ¯ï¼ã{2}ã"; |
| | | |
| | | /// <summary> |
| | | /// è¿æ¥å¼å¸¸,åæ°ãIPï¼Portï¼é误信æ¯ã |
| | | /// </summary> |
| | | public const string ConnectException = "PLCè¿æ¥å¼å¸¸ï¼IPï¼ã{0}ãï¼Portï¼ã{1}ãï¼é误信æ¯ï¼ã{2}ã"; |
| | | |
| | | /// <summary> |
| | | /// æ°æ®ç±»å转åé误,åæ°ãæ°æ®ç±»åï¼åè®®å°åï¼åå
¥çæ°æ®ï¼é误信æ¯ã |
| | | /// </summary> |
| | | public const string TypeConvertError = "æ°æ®ç±»å转æ¢éè¯¯ï¼æ°æ®ç±»åï¼ã{0}ãï¼å°åï¼ã{1}ãï¼åå
¥çæ°æ®ï¼ã{2}ãï¼é误信æ¯ï¼ã{3}ã"; |
| | | } |
| | | |
| | | public class CommunicationInfoMessage |
| | | { |
| | | /// <summary> |
| | | /// æ°æ®åå
¥,åæ°ãåè®®å°åï¼åå
¥çæ°æ®ã |
| | | /// </summary> |
| | | public const string WriteData = "æ°æ®åå
¥ï¼å°åï¼ã{0}ãï¼åå
¥çæ°æ®ï¼ã{1}ã"; |
| | | |
| | | /// <summary> |
| | | /// æ°æ®åå
¥å读å,åæ°ãåè®®å°åï¼è¯»åçæ°æ®ã |
| | | /// </summary> |
| | | public const string WriteAfterRead = "æ°æ®åå
¥å读åï¼å°åï¼ã{0}ãï¼è¯»åçæ°æ®ï¼ã{1}ã"; |
| | | |
| | | /// <summary> |
| | | /// æ°æ®åå
¥åè¯»åæ ¡éªæå,åæ°ãåè®®å°åï¼åå
¥çæ°æ®ï¼è¯»åçæ°æ®ã |
| | | /// </summary> |
| | | public const string WriteAndReadCheckSuccess = "æ°æ®åå
¥åè¯»åæ ¡éªæåï¼å°åï¼ã{0}ãï¼åå
¥çæ°æ®ï¼ã{1}ãï¼è¯»åçæ°æ®ï¼ã{2}ã"; |
| | | |
| | | /// <summary> |
| | | /// è¿æ¥æå,åæ°ãIPï¼Portã |
| | | /// </summary> |
| | | public const string ConnectSuccess = "PLCè¿æ¥æåï¼IPï¼ã{0}ãï¼Portï¼ã{1}ã"; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_Communicator |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è¥¿é¨åPLCçæ°æ®ç±»å |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Communicator |
| | | { |
| | | /// <summary> |
| | | /// 西é¨åPLCçæ°æ®ç±»å |
| | | /// </summary> |
| | | public class SiemensDBDataType |
| | | { |
| | | #region <Const> |
| | | /// <summary> |
| | | /// 32ä½æç¬¦å·æ´å |
| | | /// </summary> |
| | | public const string DataType_DInt = "dint"; |
| | | |
| | | /// <summary> |
| | | /// å¸å° |
| | | /// </summary> |
| | | public const string DataType_Bool = "bool"; |
| | | |
| | | /// <summary> |
| | | /// å符串 |
| | | /// </summary> |
| | | public const string DataType_String = "string"; |
| | | |
| | | /// <summary> |
| | | /// 16ä½æç¬¦å·æ´å |
| | | /// </summary> |
| | | public const string DataType_Int = "int"; |
| | | |
| | | /// <summary> |
| | | /// åè |
| | | /// </summary> |
| | | public const string DataType_Byte = "byte"; |
| | | |
| | | /// <summary> |
| | | /// 32使 ç¬¦å·æ´å |
| | | /// </summary> |
| | | public const string DataType_DW = "dw"; |
| | | |
| | | /// <summary> |
| | | /// 16使 ç¬¦å·æ´å |
| | | /// </summary> |
| | | public const string DataType_W = "w"; |
| | | |
| | | /// <summary> |
| | | /// æµ®ç¹å |
| | | /// </summary> |
| | | public const string DataType_Float = "float"; |
| | | |
| | | /// <summary> |
| | | /// å符 |
| | | /// </summary> |
| | | public const string DataType_Char = "char"; |
| | | #endregion <Const> |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è¥¿é¨åPLCçæ°æ®ç±»åè·å对åºC#çç±»åç¼å·æä¸¾ |
| | | /// </summary> |
| | | /// <param name="dataType">西é¨åPLCçæ°æ®ç±»å</param> |
| | | /// <returns>è¿å对åºC#çç±»åç¼å·æä¸¾</returns> |
| | | /// <exception cref="CommunicationException"></exception> |
| | | public static TypeCode GetTypeCode(string dataType) |
| | | { |
| | | return dataType.ToLower() switch |
| | | { |
| | | DataType_DInt => TypeCode.Int32, |
| | | DataType_DW => TypeCode.UInt32, |
| | | DataType_Int => TypeCode.Int16, |
| | | DataType_W => TypeCode.UInt16, |
| | | DataType_Float => TypeCode.Single, |
| | | DataType_Bool => TypeCode.Boolean, |
| | | DataType_Byte => TypeCode.Byte, |
| | | DataType_String => TypeCode.String, |
| | | DataType_Char => TypeCode.Char, |
| | | _ => throw new CommunicationException($"æ°æ®ç±»åé误:ã{dataType}ã", CommunicationErrorType.TypeError), |
| | | }; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_Communicator |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è¥¿é¨åS7é讯类çå°è£
,ç»§æ¿BaseCommunicatoræ½è±¡ç±» |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using HslCommunication; |
| | | using HslCommunication.Core; |
| | | using HslCommunication.LogNet; |
| | | using HslCommunication.Profinet.Siemens; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Net.NetworkInformation; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Xml.Linq; |
| | | |
| | | namespace WIDESEAWCS_Communicator |
| | | { |
| | | /// <summary> |
| | | /// 西é¨åS7é讯类 |
| | | /// </summary> |
| | | [Description("西é¨åS7")] |
| | | public class SiemensS7 : BaseCommunicator |
| | | { |
| | | #region Private Member |
| | | /// <summary> |
| | | /// HSLCommunicationç西é¨åçS7åè®®çé讯类 |
| | | /// </summary> |
| | | private SiemensS7Net plc; |
| | | |
| | | /// <summary> |
| | | /// 设å¤çIPå°åã |
| | | /// </summary> |
| | | private string _ipAddress; |
| | | |
| | | /// <summary> |
| | | /// è¿æ¥ä½¿ç¨ç端å£å·ã |
| | | /// </summary> |
| | | private int _port; |
| | | |
| | | /// <summary> |
| | | /// å½åéè®¯å¨æ¯å¦å·²è¿æ¥å°PLCã |
| | | /// </summary> |
| | | private bool _connected; |
| | | |
| | | /// <summary> |
| | | /// PLCåç§° |
| | | /// </summary> |
| | | private string _name; |
| | | |
| | | private ILogNet _logNet; |
| | | |
| | | private bool _isPing = true; |
| | | #endregion Private Member |
| | | |
| | | #region Public Member |
| | | /// <summary> |
| | | /// è·åå½åéè®¯å¨æ¯å¦å·²è¿æ¥å°PLCã |
| | | /// </summary> |
| | | public override bool IsConnected => _connected; |
| | | |
| | | /// <summary> |
| | | /// PLCåç§° |
| | | /// </summary> |
| | | public override string Name => _name; |
| | | |
| | | public override ILogNet LogNet => _logNet; |
| | | #endregion Public Member |
| | | |
| | | #region Constructor Function |
| | | /// <summary> |
| | | /// æé 彿° |
| | | /// </summary> |
| | | /// <param name="ipAddress">设å¤çIPå°å</param> |
| | | /// <param name="port">è¿æ¥ä½¿ç¨ç端å£å·</param> |
| | | /// <param name="name">设å¤åç§°</param> |
| | | public SiemensS7(string ipAddress, int port, string name) |
| | | { |
| | | string path = AppDomain.CurrentDomain.BaseDirectory + $"Log_PLCReadWrite\\{name}"; |
| | | _logNet = new LogNetFileSize(path, 10 * 1024 * 1024, 100); |
| | | |
| | | bool ipCheck = IPAddress.TryParse(ipAddress, out IPAddress? address); |
| | | if (!ipCheck) |
| | | { |
| | | _logNet.WriteError(name, string.Format(CommunicationExceptionMessage.IpAddressErrorException, ipAddress)); |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.IpAddressErrorException, ipAddress), CommunicationErrorType.IpAddressError); |
| | | } |
| | | |
| | | _ipAddress = ipAddress;//éè¿æé 彿°èµå¼è®¾å¤çIPå°å |
| | | _port = port;//éè¿æé 彿°èµå¼è¿æ¥ä½¿ç¨ç端å£å· |
| | | _name = name; |
| | | } |
| | | #endregion |
| | | |
| | | #region Private Method |
| | | /// <summary> |
| | | /// ä»OperateResult对象ä¸è·å读åçæ°æ®ã |
| | | /// </summary> |
| | | /// <typeparam name="T">读åçæ°æ®ç±»åã</typeparam> |
| | | /// <param name="operateResult">HSLCommunication读åçOperateResult<T>对象</param> |
| | | /// <returns>å¦æè¯»åæåï¼è¿å读åç»æï¼è¯»åå¤±è´¥ï¼æåºèªå®ä¹é讯å¼å¸¸</returns> |
| | | /// <exception cref="CommunicationException">èªå®ä¹é讯å¼å¸¸ç±»</exception> |
| | | private object GetContent<T>(OperateResult<T> operateResult, string address) |
| | | { |
| | | try |
| | | { |
| | | if (!operateResult.IsSuccess) |
| | | { |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.ReadFailedException, typeof(T).Name, address, operateResult.Message), CommunicationErrorType.ReadFailed); |
| | | } |
| | | return operateResult.Content ?? throw new CommunicationException(string.Format(CommunicationExceptionMessage.ReadDataIsNull, address), CommunicationErrorType.ReadFailed); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogNet.WriteException(Name, ex.Message, ex); |
| | | throw new CommunicationException(ex.Message, CommunicationErrorType.ReadFailed, innerException: ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="operateResult"></param> |
| | | /// <param name="address"></param> |
| | | /// <param name="value"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="CommunicationException"></exception> |
| | | private bool GetResult<T>(OperateResult operateResult, string address, T value) where T : notnull |
| | | { |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | try |
| | | { |
| | | stringBuilder.AppendLine(string.Format(CommunicationInfoMessage.WriteData, address, value)); |
| | | if (!operateResult.IsSuccess) |
| | | { |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.WriteFailedException, typeof(T).Name, address, value, operateResult.Message), CommunicationErrorType.WriteFailed); |
| | | } |
| | | else |
| | | { |
| | | //return true; |
| | | object? obj = null; |
| | | for (int i = 0; i < 5; i++) |
| | | { |
| | | T readValue = Read<T>(address); |
| | | stringBuilder.AppendLine(string.Format(CommunicationInfoMessage.WriteAfterRead, readValue, value)); |
| | | obj = readValue; |
| | | if (readValue.Equals(value)) |
| | | { |
| | | stringBuilder.AppendLine(string.Format(CommunicationInfoMessage.WriteAndReadCheckSuccess, address, value, readValue)); |
| | | return true; |
| | | } |
| | | else if (i < 4) |
| | | { |
| | | Write(address, value); |
| | | } |
| | | } |
| | | stringBuilder.AppendLine(string.Format(CommunicationExceptionMessage.WriteAndReadCheckFaild, address, value, obj)); |
| | | throw new CommunicationException(stringBuilder.ToString(), CommunicationErrorType.WriteFailed); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogNet.WriteException(Name, ex.Message, ex); |
| | | throw new CommunicationException(ex.Message, CommunicationErrorType.WriteFailed, innerException: ex); |
| | | } |
| | | finally |
| | | { |
| | | LogNet.WriteInfo(Name, stringBuilder.ToString()); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åå
¥æ°æ® |
| | | /// </summary> |
| | | /// <param name="address"></param> |
| | | /// <param name="value"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="CommunicationException"></exception> |
| | | private OperateResult Write(string address, object value) |
| | | { |
| | | try |
| | | { |
| | | Type type = value.GetType(); |
| | | |
| | | switch (Type.GetTypeCode(type)) |
| | | { |
| | | case TypeCode.Int32: |
| | | return plc.Write(address, Convert.ToInt32(value)); |
| | | case TypeCode.UInt32: |
| | | return plc.Write(address, Convert.ToUInt32(value)); |
| | | case TypeCode.Int16: |
| | | return plc.Write(address, Convert.ToInt16(value)); |
| | | case TypeCode.UInt16: |
| | | return plc.Write(address, Convert.ToUInt16(value)); |
| | | case TypeCode.Single: |
| | | return plc.Write(address, Convert.ToSingle(value)); |
| | | case TypeCode.Boolean: |
| | | return plc.Write(address, Convert.ToBoolean(value)); |
| | | case TypeCode.Byte: |
| | | return plc.Write(address, Convert.ToByte(value)); |
| | | case TypeCode.String: |
| | | return plc.Write(address, Convert.ToString(value)); |
| | | case TypeCode.Char: |
| | | return plc.Write(address, Convert.ToChar(value)); |
| | | default: |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.DataTypeErrorException, type.Name, address), CommunicationErrorType.TypeError); |
| | | } |
| | | } |
| | | catch (CommunicationException ex) |
| | | { |
| | | throw new CommunicationException(ex.Message, ex.ErrorType); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //读åå¼å¸¸æ¶æåºèªå®ä¹é讯å¼å¸¸ç±» |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.DataTypeErrorException, address, value), CommunicationErrorType.TypeError, innerException: ex); |
| | | } |
| | | } |
| | | |
| | | private object Read(string address, TypeCode typeCode) |
| | | { |
| | | try |
| | | { |
| | | switch (typeCode) |
| | | { |
| | | case TypeCode.Int32: |
| | | return (int)GetContent(plc.ReadInt32(address), address); |
| | | case TypeCode.UInt32: |
| | | return (uint)GetContent(plc.ReadUInt32(address), address); |
| | | case TypeCode.Int16: |
| | | return (short)GetContent(plc.ReadInt16(address), address); |
| | | case TypeCode.UInt16: |
| | | return (ushort)GetContent(plc.ReadUInt16(address), address); |
| | | case TypeCode.Single: |
| | | return (float)GetContent(plc.ReadFloat(address), address); |
| | | case TypeCode.Boolean: |
| | | return (bool)GetContent(plc.ReadBool(address), address); |
| | | case TypeCode.Byte: |
| | | return (byte)GetContent(plc.ReadByte(address), address); |
| | | case TypeCode.String: |
| | | return (string)GetContent(plc.ReadString(address), address); |
| | | case TypeCode.Char: |
| | | return (char)GetContent(plc.ReadByte(address), address); |
| | | default: |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.DataTypeErrorException, typeCode.ToString(), address), CommunicationErrorType.TypeError); |
| | | } |
| | | } |
| | | catch (CommunicationException ex) |
| | | { |
| | | //读åå¼å¸¸æ¶æåºèªå®ä¹é讯å¼å¸¸ç±» |
| | | throw new CommunicationException(ex.Message, ex.ErrorType); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //读åå¼å¸¸æ¶æåºèªå®ä¹é讯å¼å¸¸ç±» |
| | | throw new CommunicationException($"è¯»åæ°æ®å¼å¸¸,é误信æ¯:{ex.Message}", CommunicationErrorType.ReadException, innerException: ex); |
| | | } |
| | | } |
| | | |
| | | private void Ping() |
| | | { |
| | | Task.Run(() => |
| | | { |
| | | while (_isPing) |
| | | { |
| | | try |
| | | { |
| | | IPStatus status = plc.IpAddressPing(); |
| | | if (status == IPStatus.Success) |
| | | _connected = true; |
| | | else |
| | | _connected = false; |
| | | } |
| | | finally |
| | | { |
| | | Thread.Sleep(100); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | #region Public Method |
| | | /// <summary> |
| | | /// è¿æ¥å°PLCã |
| | | /// </summary> |
| | | /// <returns>å¦æè¿æ¥æååè¿åtrueï¼å¦åè¿åfalseã</returns> |
| | | /// <exception cref="CommunicationException">èªå®ä¹é讯å¼å¸¸ç±»</exception> |
| | | public override bool Connect() |
| | | { |
| | | try |
| | | { |
| | | |
| | | //å®ä¾åä¸ä¸ªè¥¿é¨åçS7åè®®çé讯对象 |
| | | plc = new SiemensS7Net(SiemensPLCS.S1500) |
| | | { |
| | | IpAddress = _ipAddress, |
| | | Port = _port |
| | | }; |
| | | OperateResult operateResult = plc.ConnectServer();//è¿æ¥PLC |
| | | _connected = operateResult.IsSuccess;//å°è¿æ¥æ¯å¦æåèµå¼ç»å½åéè®¯å¨æ¯å¦å·²è¿æ¥å°PLC |
| | | |
| | | if (_connected) |
| | | LogNet.WriteInfo(Name, string.Format(CommunicationInfoMessage.ConnectSuccess, _ipAddress, _port)); |
| | | else |
| | | LogNet.WriteError(Name, string.Format(CommunicationExceptionMessage.ConnectFaild, _ipAddress, _port, operateResult.Message)); |
| | | Ping(); |
| | | return operateResult.IsSuccess; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogNet.WriteException(Name, string.Format(CommunicationExceptionMessage.ConnectFaild, _ipAddress, _port, ex.Message), ex); |
| | | //è¿æ¥å¼å¸¸æ¶æåºèªå®ä¹å¼å¸¸ç±» |
| | | throw new CommunicationException(ex.Message, CommunicationErrorType.ConnectionFailed, innerException: ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå¼ä¸å·¥ä¸è®¾å¤çè¿æ¥ã |
| | | /// </summary> |
| | | /// <returns>妿æåæå¼è¿æ¥åè¿åtrueï¼å¦æå·²ç»æ¯æå¼ç¶æåè¿åfalseã</returns> |
| | | public override bool Disconnect() |
| | | { |
| | | try |
| | | { |
| | | if (plc != null) |
| | | { |
| | | OperateResult operateResult = plc.ConnectClose();//æå¼ä¸PLCçè¿æ¥ |
| | | return operateResult.IsSuccess; |
| | | } |
| | | return false; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return false; |
| | | } |
| | | finally |
| | | { |
| | | _connected = false; |
| | | } |
| | | } |
| | | |
| | | #region Read |
| | | /// <summary> |
| | | /// ä»PLCè¯»åæ°æ®ã |
| | | /// </summary> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <param name="length">è¦è¯»åçæ°æ®é¿åº¦ã</param> |
| | | /// <returns>读åå°çæ°æ®ï¼å¦æè¯»å失败åå¯è½è¿ånullã空æ°ç»ææåºèªå®ä¹é讯å¼å¸¸ã</returns> |
| | | /// <exception cref="CommunicationException">èªå®ä¹é讯å¼å¸¸ç±»</exception> |
| | | public override byte[] Read(string address, int length) |
| | | { |
| | | return (byte[])GetContent(plc.Read(address, (ushort)length), address); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä»PLCè¯»åæ°æ®ã |
| | | /// </summary> |
| | | /// <typeparam name="T">读åçæ°æ®ç±»åã</typeparam> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <param name="length">è¦è¯»åçæ°æ®é¿åº¦ï¼å¯éï¼é»è®¤å¼ä¸º1ï¼ã</param> |
| | | /// <returns>å¦æè¯»åæåï¼è¿å读åçç»æï¼å¤±è´¥åæåºèªå®ä¹é讯å¼å¸¸</returns> |
| | | /// <exception cref="CommunicationException">èªå®ä¹é讯å¼å¸¸ç±»</exception> |
| | | public override T Read<T>(string address) |
| | | { |
| | | Type type = typeof(T); |
| | | return (T)Read(address, Type.GetTypeCode(type)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä»PLCè¯»åæ°æ®è¿åobjectã |
| | | /// </summary> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <param name="dataType">读åçæ°æ®ç±»åã</param> |
| | | /// <returns>å¦æè¯»åæåï¼è¿å读åçç»æï¼å¤±è´¥åæåºèªå®ä¹é讯å¼å¸¸</returns> |
| | | /// <exception cref="CommunicationException">èªå®ä¹é讯å¼å¸¸ç±»</exception> |
| | | public override object ReadAsObj(string address, string dataType) |
| | | { |
| | | return Read(address, SiemensDBDataType.GetTypeCode(dataType)); |
| | | } |
| | | #endregion |
| | | |
| | | #region Write |
| | | /// <summary> |
| | | /// åPLCåå
¥æ°æ®ã |
| | | /// </summary> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <param name="data">è¦åå
¥çæ°æ®ã</param> |
| | | /// <returns>妿åå
¥æååè¿åtrueï¼å¦æåå
¥å¤±è´¥åå¯è½è¿åfalseææåºèªå®ä¹é讯å¼å¸¸ã</returns> |
| | | /// <exception cref="CommunicationException">èªå®ä¹é讯å¼å¸¸ç±»</exception> |
| | | public override bool Write(string address, byte[] data) |
| | | { |
| | | try |
| | | { |
| | | OperateResult result = plc.Write(address, data); |
| | | if (result.IsSuccess) |
| | | { |
| | | return result.IsSuccess; |
| | | } |
| | | else |
| | | { |
| | | //todo åå
¥å¤±è´¥ |
| | | return false; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //åå
¥å¼å¸¸æ¶æåºèªå®ä¹é讯å¼å¸¸ç±» |
| | | throw new CommunicationException($"åå
¥æ°æ®å¼å¸¸,å°å:ã{address}ã,é误信æ¯: {ex.Message}", CommunicationErrorType.ReadFailed, innerException: ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="address"></param> |
| | | /// <param name="value"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="NotImplementedException"></exception> |
| | | public override bool Write<T>(string address, T value) |
| | | { |
| | | return GetResult(Write(address, value), address, value); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åPLCåå
¥æ°æ®ã |
| | | /// </summary> |
| | | /// <param name="address">æºå°åï¼å
·ä½æ ¼å¼åå³äºä½¿ç¨çå·¥ä¸åè®®ã</param> |
| | | /// <param name="dataType">è¦åå
¥çæ°æ®ç±»åï¼PLCçæ°æ®ç±»åï¼ã</param> |
| | | /// <param name="value">è¦åå
¥çæ°æ®ã</param> |
| | | /// <returns>妿åå
¥æååè¿åtrueï¼å¤±è´¥åæåºèªå®ä¹é讯å¼å¸¸ã</returns> |
| | | /// <exception cref="CommunicationException"></exception> |
| | | public override bool WriteObj(string address, string dataType, [NotNull] object value) |
| | | { |
| | | bool obj = false; |
| | | switch (dataType.ToLower()) |
| | | { |
| | | case SiemensDBDataType.DataType_DInt: |
| | | { |
| | | int writeVal; |
| | | try |
| | | { |
| | | writeVal = Convert.ToInt32(value); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.TypeConvertError, dataType, address, value, ex.Message), CommunicationErrorType.TypeError, innerException: ex); |
| | | } |
| | | obj = GetResult(Write(address, writeVal), address, writeVal); |
| | | } |
| | | break; |
| | | case SiemensDBDataType.DataType_DW: |
| | | { |
| | | uint writeVal; |
| | | try |
| | | { |
| | | writeVal = Convert.ToUInt32(value); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.TypeConvertError, dataType, address, value, ex.Message), CommunicationErrorType.TypeError, innerException: ex); |
| | | } |
| | | obj = GetResult(Write(address, writeVal), address, writeVal); |
| | | } |
| | | break; |
| | | case SiemensDBDataType.DataType_Int: |
| | | { |
| | | short writeVal; |
| | | try |
| | | { |
| | | writeVal = Convert.ToInt16(value); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.TypeConvertError, dataType, address, value, ex.Message), CommunicationErrorType.TypeError, innerException: ex); |
| | | } |
| | | obj = GetResult(Write(address, writeVal), address, writeVal); |
| | | } |
| | | break; |
| | | case SiemensDBDataType.DataType_W: |
| | | { |
| | | ushort writeVal; |
| | | try |
| | | { |
| | | writeVal = Convert.ToUInt16(value); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.TypeConvertError, dataType, address, value, ex.Message), CommunicationErrorType.TypeError, innerException: ex); |
| | | } |
| | | obj = GetResult(Write(address, writeVal), address, writeVal); |
| | | } |
| | | break; |
| | | case SiemensDBDataType.DataType_Float: |
| | | { |
| | | float writeVal; |
| | | try |
| | | { |
| | | writeVal = Convert.ToSingle(value); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.TypeConvertError, dataType, address, value, ex.Message), CommunicationErrorType.TypeError, innerException: ex); |
| | | } |
| | | obj = GetResult(Write(address, writeVal), address, writeVal); |
| | | } |
| | | break; |
| | | case SiemensDBDataType.DataType_Bool: |
| | | { |
| | | bool writeVal; |
| | | try |
| | | { |
| | | writeVal = Convert.ToBoolean(value); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.TypeConvertError, dataType, address, value, ex.Message), CommunicationErrorType.TypeError, innerException: ex); |
| | | } |
| | | obj = GetResult(Write(address, writeVal), address, writeVal); |
| | | } |
| | | break; |
| | | case SiemensDBDataType.DataType_Byte: |
| | | { |
| | | byte writeVal; |
| | | try |
| | | { |
| | | writeVal = Convert.ToByte(value); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.TypeConvertError, dataType, address, value, ex.Message), CommunicationErrorType.TypeError, innerException: ex); |
| | | } |
| | | obj = GetResult(Write(address, writeVal), address, writeVal); |
| | | } |
| | | break; |
| | | case SiemensDBDataType.DataType_String: |
| | | { |
| | | string writeVal; |
| | | try |
| | | { |
| | | writeVal = value.ToString(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.TypeConvertError, dataType, address, value, ex.Message), CommunicationErrorType.TypeError, innerException: ex); |
| | | } |
| | | obj = GetResult(Write(address, writeVal), address, writeVal); |
| | | } |
| | | |
| | | break; |
| | | case SiemensDBDataType.DataType_Char: |
| | | |
| | | break; |
| | | default: |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.DataTypeErrorException, dataType, address), CommunicationErrorType.TypeError); |
| | | } |
| | | return obj; |
| | | } |
| | | #endregion |
| | | |
| | | #region ReadCustomer |
| | | public override T ReadCustomer<T>(string address) |
| | | { |
| | | try |
| | | { |
| | | return plc.ReadCustomer<T>(address).Content; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogNet.WriteException(Name, $"ã{Name}ãPLC读åå¼å¸¸ï¼å°åï¼ã{address}ãï¼é误信æ¯ï¼ã{ex.Message}ã", ex); |
| | | throw new CommunicationException(ex.Message, CommunicationErrorType.ReadException, innerException: ex); |
| | | } |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | #region WriteCustomer |
| | | public override bool WriteCustomer<T>(string address, [NotNull] T value) |
| | | { |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | try |
| | | { |
| | | OperateResult operateResult = plc.WriteCustomer(address, value); |
| | | stringBuilder.AppendLine(string.Format(CommunicationInfoMessage.WriteData, address, JsonConvert.SerializeObject(value))); |
| | | if (operateResult.IsSuccess) |
| | | { |
| | | object? obj = null; |
| | | for (int i = 0; i < 5; i++) |
| | | { |
| | | T readValue = ReadCustomer<T>(address); |
| | | stringBuilder.AppendLine(string.Format(CommunicationInfoMessage.WriteAfterRead, address, JsonConvert.SerializeObject(readValue))); |
| | | obj = readValue; |
| | | PropertyInfo[] propertyInfos = typeof(T).GetProperties(); |
| | | for (int j = 0; j < propertyInfos.Length; j++) |
| | | { |
| | | object? writeValueItem = propertyInfos[j].GetValue(value); |
| | | object? readValueItem = propertyInfos[j].GetValue(readValue); |
| | | if (writeValueItem.Equals(readValueItem)) |
| | | { |
| | | stringBuilder.AppendLine(string.Format(CommunicationInfoMessage.WriteAndReadCheckSuccess, address, JsonConvert.SerializeObject(value), JsonConvert.SerializeObject(readValue))); |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | if (j == propertyInfos.Length - 1) |
| | | return true; |
| | | } |
| | | plc.WriteCustomer(address, value); |
| | | } |
| | | stringBuilder.AppendLine(string.Format(CommunicationExceptionMessage.WriteAndReadCheckFaild, address, JsonConvert.SerializeObject(value), JsonConvert.SerializeObject(obj))); |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.WriteAndReadCheckFaild, address, JsonConvert.SerializeObject(value), JsonConvert.SerializeObject(obj)), CommunicationErrorType.WriteFailed); |
| | | } |
| | | else |
| | | { |
| | | throw new CommunicationException(string.Format(CommunicationExceptionMessage.WriteFailedException, typeof(T).Name, address, JsonConvert.SerializeObject(value), operateResult.Message), CommunicationErrorType.WriteFailed); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogNet.WriteException(Name, ex.Message, ex); |
| | | throw new CommunicationException(ex.Message, CommunicationErrorType.WriteFailed, innerException: ex); |
| | | } |
| | | finally |
| | | { |
| | | LogNet.WriteInfo(Name, stringBuilder.ToString()); |
| | | } |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | // æ¾å¼å®ç°IDisposableæ¥å£ä»¥æä¾åå¾åæ¶æ¶çæ¸
ç |
| | | public override void Dispose() |
| | | { |
| | | _isPing = false; |
| | | Disconnect(); |
| | | plc.Dispose(); |
| | | GC.SuppressFinalize(this); |
| | | } |
| | | |
| | | public override OperateResult<TimeSpan> Wait<T>(string address, int readInterval, int waitTimeout, T value) |
| | | { |
| | | TypeCode typeCode = Type.GetTypeCode(typeof(T)); |
| | | switch (typeCode) |
| | | { |
| | | case TypeCode.Byte: |
| | | DateTime start = DateTime.Now; |
| | | while (true) |
| | | { |
| | | OperateResult<byte> read = plc.ReadByte(address); |
| | | if (!read.IsSuccess) return OperateResult.CreateFailedResult<TimeSpan>(read); |
| | | |
| | | if (read.Content == Convert.ToByte(value)) return OperateResult.CreateSuccessResult(DateTime.Now - start); |
| | | if (waitTimeout > 0 && (DateTime.Now - start).TotalMilliseconds > waitTimeout) |
| | | { |
| | | return new OperateResult<TimeSpan>(StringResources.Language.CheckDataTimeout + waitTimeout); |
| | | } |
| | | HslHelper.ThreadSleep(readInterval); |
| | | } |
| | | case TypeCode.Int16: |
| | | OperateResult<TimeSpan> operateResultShort = plc.Wait(address, Convert.ToInt16(value), readInterval, waitTimeout); |
| | | return operateResultShort; |
| | | case TypeCode.Int32: |
| | | OperateResult<TimeSpan> operateResultInt = plc.Wait(address, Convert.ToInt16(value), readInterval, waitTimeout); |
| | | return operateResultInt; |
| | | case TypeCode.UInt16: |
| | | OperateResult<TimeSpan> operateResultUShort = plc.Wait(address, Convert.ToInt16(value), readInterval, waitTimeout); |
| | | return operateResultUShort; |
| | | case TypeCode.UInt32: |
| | | OperateResult<TimeSpan> operateResultUInt = plc.Wait(address, Convert.ToInt16(value), readInterval, waitTimeout); |
| | | return operateResultUInt; |
| | | default: |
| | | throw new NotSupportedException(); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region Destruction Function |
| | | /// <summary> |
| | | /// ææå½æ°ï¼ç¡®ä¿å¨ä¸åéè¦æ¶å
³éè¿æ¥ |
| | | /// </summary> |
| | | ~SiemensS7() |
| | | { |
| | | Dispose(); |
| | | } |
| | | #endregion |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <Project Sdk="Microsoft.NET.Sdk"> |
| | | |
| | | <PropertyGroup> |
| | | <TargetFramework>net6.0</TargetFramework> |
| | | <ImplicitUsings>enable</ImplicitUsings> |
| | | <Nullable>enable</Nullable> |
| | | <Version>1.0.0</Version> |
| | | <Description>å·¥ä¸è®¾å¤é讯</Description> |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="HslCommunication" Version="11.6.4" /> |
| | | </ItemGroup> |
| | | |
| | | </Project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Castle.DynamicProxy; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.AspNetCore.SignalR; |
| | | using Newtonsoft.Json; |
| | | using StackExchange.Profiling; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | |
| | | namespace WIDESEAWCS_Core.AOP |
| | | { |
| | | /// <summary> |
| | | /// æ¦æªå¨BlogLogAOP ç»§æ¿IInterceptoræ¥å£ |
| | | /// </summary> |
| | | public class LogAOP : IInterceptor |
| | | { |
| | | private readonly IHttpContextAccessor _accessor; |
| | | |
| | | public LogAOP(IHttpContextAccessor accessor) |
| | | { |
| | | _accessor = accessor; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å®ä¾åIInterceptorå¯ä¸æ¹æ³ |
| | | /// </summary> |
| | | /// <param name="invocation">å
å«è¢«æ¦æªæ¹æ³çä¿¡æ¯</param> |
| | | public void Intercept(IInvocation invocation) |
| | | { |
| | | string UserName = _accessor.HttpContext?.User?.Identity?.Name; |
| | | string json; |
| | | try |
| | | { |
| | | if (invocation.Arguments.Any()) |
| | | { |
| | | json = JsonConvert.SerializeObject(invocation.Arguments); |
| | | } |
| | | else |
| | | { |
| | | json = "æ åæ°"; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | json = "æ æ³åºååï¼å¯è½æ¯å
°å§è¾¾è¡¨è¾¾å¼çåå é æï¼æç
§æ¡æ¶ä¼å代ç " + ex.ToString(); |
| | | } |
| | | |
| | | DateTime startTime = DateTime.Now; |
| | | AOPLogInfo apiLogAopInfo = new AOPLogInfo |
| | | { |
| | | RequestTime = startTime.ToString("yyyy-MM-dd hh:mm:ss fff"), |
| | | OpUserName = "ãå½åæä½ç¨æ·ãï¼" + UserName, |
| | | RequestMethodName = "ãå½åæ§è¡æ¹æ³ãï¼" + invocation.Method.Name, |
| | | RequestParamsName = "ãæºå¸¦çåæ°æãï¼" + string.Join(", ", invocation.Arguments.Select(a => (a ?? "").ToString()).ToArray()), |
| | | RequestParamsData = json |
| | | }; |
| | | |
| | | var dataIntercept = $""; |
| | | |
| | | try |
| | | { |
| | | MiniProfiler.Current.Step($"æ§è¡{invocation.InvocationTarget}.{invocation.Method.Name}()æ¹æ³ -> "); |
| | | //å¨è¢«æ¦æªçæ¹æ³æ§è¡å®æ¯å ç»§ç»æ§è¡å½åæ¹æ³ï¼æ³¨ææ¯è¢«æ¦æªçæ¯å¼æ¥ç |
| | | invocation.Proceed(); |
| | | |
| | | // 弿¥è·åå¼å¸¸ï¼å
æ§è¡ |
| | | if (IsAsyncMethod(invocation.Method)) |
| | | { |
| | | if (invocation.Method.ReturnType == typeof(Task)) |
| | | { |
| | | invocation.ReturnValue = InternalAsyncHelper.AwaitTaskWithPostActionAndFinally( |
| | | (Task)invocation.ReturnValue, |
| | | async () => await SuccessAction(invocation, apiLogAopInfo, startTime), /*æåæ¶æ§è¡*/ |
| | | ex => |
| | | { |
| | | LogEx(ex, apiLogAopInfo); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | invocation.ReturnValue = InternalAsyncHelper.CallAwaitTaskWithPostActionAndFinallyAndGetResult( |
| | | invocation.Method.ReturnType.GenericTypeArguments[0], |
| | | invocation.ReturnValue, |
| | | async (o) => await SuccessAction(invocation, apiLogAopInfo, startTime, o), /*æåæ¶æ§è¡*/ |
| | | ex => |
| | | { |
| | | LogEx(ex, apiLogAopInfo); |
| | | }); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // 忥1 |
| | | string jsonResult; |
| | | try |
| | | { |
| | | jsonResult = JsonConvert.SerializeObject(invocation.ReturnValue); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | jsonResult = "æ æ³åºååï¼å¯è½æ¯å
°å§è¾¾è¡¨è¾¾å¼çåå é æï¼æç
§æ¡æ¶ä¼å代ç " + ex.ToString(); |
| | | } |
| | | |
| | | var type = invocation.Method.ReturnType; |
| | | var resultProperty = type.GetProperty("Result"); |
| | | DateTime endTime = DateTime.Now; |
| | | string ResponseTime = (endTime - startTime).Milliseconds.ToString(); |
| | | apiLogAopInfo.ResponseTime = endTime.ToString("yyyy-MM-dd hh:mm:ss fff"); |
| | | apiLogAopInfo.ResponseIntervalTime = ResponseTime + "ms"; |
| | | apiLogAopInfo.ResponseJsonData = jsonResult; |
| | | Parallel.For(0, 1, e => |
| | | { |
| | | LogLock.OutLogAOP("AOPLog", new string[] { apiLogAopInfo.GetType().ToString(), JsonConvert.SerializeObject(apiLogAopInfo) }); |
| | | }); |
| | | } |
| | | } |
| | | catch (Exception ex) // 忥2 |
| | | { |
| | | LogEx(ex, apiLogAopInfo); |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | private async Task SuccessAction(IInvocation invocation, AOPLogInfo apiLogAopInfo, DateTime startTime, object o = null) |
| | | { |
| | | DateTime endTime = DateTime.Now; |
| | | string ResponseTime = (endTime - startTime).Milliseconds.ToString(); |
| | | apiLogAopInfo.ResponseTime = endTime.ToString("yyyy-MM-dd hh:mm:ss fff"); |
| | | apiLogAopInfo.ResponseIntervalTime = ResponseTime + "ms"; |
| | | apiLogAopInfo.ResponseJsonData = JsonConvert.SerializeObject(o); |
| | | |
| | | await Task.Run(() => |
| | | { |
| | | Parallel.For(0, 1, e => |
| | | { |
| | | LogLock.OutLogAOP("AOPLog", new string[] { apiLogAopInfo.GetType().ToString(), JsonConvert.SerializeObject(apiLogAopInfo) }); |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | private void LogEx(Exception ex, AOPLogInfo dataIntercept) |
| | | { |
| | | if (ex != null) |
| | | { |
| | | //æ§è¡ç service ä¸ï¼æ¶å½å¼å¸¸ |
| | | MiniProfiler.Current.CustomTiming("Errorsï¼", ex.Message); |
| | | //æ§è¡ç service ä¸ï¼æè·å¼å¸¸ |
| | | AOPLogExInfo apiLogAopExInfo = new AOPLogExInfo |
| | | { |
| | | ExMessage = ex.Message, |
| | | InnerException = "InnerException-å
é¨å¼å¸¸:\r\n" + (ex.InnerException == null ? "" : ex.InnerException.InnerException.ToString()) + |
| | | "\r\nStackTrace-å æ è·è¸ª:\r\n" + (ex.StackTrace == null ? "" : ex.StackTrace.ToString()), |
| | | ApiLogAopInfo = dataIntercept |
| | | }; |
| | | // å¼å¸¸æ¥å¿éæè¯¦ç»çå æ ä¿¡æ¯ |
| | | Parallel.For(0, 1, e => |
| | | { |
| | | LogLock.OutLogAOP("AOPLogEx", new string[] { apiLogAopExInfo.GetType().ToString(), JsonConvert.SerializeObject(apiLogAopExInfo) }); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | public static bool IsAsyncMethod(MethodInfo method) |
| | | { |
| | | return method.ReturnType == typeof(Task) || method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task<>); |
| | | } |
| | | } |
| | | |
| | | |
| | | internal static class InternalAsyncHelper |
| | | { |
| | | public static async Task AwaitTaskWithPostActionAndFinally(Task actualReturnValue, Func<Task> postAction, Action<Exception> finalAction) |
| | | { |
| | | Exception exception = null; |
| | | |
| | | try |
| | | { |
| | | await actualReturnValue; |
| | | await postAction(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | exception = ex; |
| | | } |
| | | finally |
| | | { |
| | | finalAction(exception); |
| | | } |
| | | } |
| | | |
| | | public static async Task<T> AwaitTaskWithPostActionAndFinallyAndGetResult<T>(Task<T> actualReturnValue, Func<object, Task> postAction, |
| | | Action<Exception> finalAction) |
| | | { |
| | | Exception exception = null; |
| | | try |
| | | { |
| | | var result = await actualReturnValue; |
| | | await postAction(result); |
| | | return result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | exception = ex; |
| | | throw; |
| | | } |
| | | finally |
| | | { |
| | | finalAction(exception); |
| | | } |
| | | } |
| | | |
| | | public static object CallAwaitTaskWithPostActionAndFinallyAndGetResult(Type taskReturnType, object actualReturnValue, |
| | | Func<object, Task> action, Action<Exception> finalAction) |
| | | { |
| | | return typeof(InternalAsyncHelper) |
| | | .GetMethod(nameof(AwaitTaskWithPostActionAndFinallyAndGetResult), BindingFlags.Public | BindingFlags.Static) |
| | | .MakeGenericMethod(taskReturnType) |
| | | .Invoke(null, new object[] { actualReturnValue, action, finalAction }); |
| | | } |
| | | } |
| | | |
| | | public class AOPLogInfo |
| | | { |
| | | /// <summary> |
| | | /// è¯·æ±æ¶é´ |
| | | /// </summary> |
| | | [Description("è¯·æ±æ¶é´")] |
| | | public string RequestTime { get; set; } = string.Empty; |
| | | /// <summary> |
| | | /// æä½äººå |
| | | /// </summary> |
| | | [Description("æä½äººå")] |
| | | public string OpUserName { get; set; } = string.Empty; |
| | | /// <summary> |
| | | /// è¯·æ±æ¹æ³å |
| | | /// </summary> |
| | | [Description("è¯·æ±æ¹æ³å")] |
| | | public string RequestMethodName { get; set; } = string.Empty; |
| | | /// <summary> |
| | | /// 请æ±åæ°å |
| | | /// </summary> |
| | | [Description("请æ±åæ°å")] |
| | | public string RequestParamsName { get; set; } = string.Empty; |
| | | /// <summary> |
| | | /// 请æ±åæ°æ°æ®JSON |
| | | /// </summary> |
| | | [Description("请æ±åæ°æ°æ®JSON")] |
| | | public string RequestParamsData { get; set; } = string.Empty; |
| | | /// <summary> |
| | | /// 请æ±ååºé´éæ¶é´ |
| | | /// </summary> |
| | | [Description("请æ±ååºé´éæ¶é´")] |
| | | public string ResponseIntervalTime { get; set; } = string.Empty; |
| | | /// <summary> |
| | | /// ååºæ¶é´ |
| | | /// </summary> |
| | | [Description("ååºæ¶é´")] |
| | | public string ResponseTime { get; set; } = string.Empty; |
| | | /// <summary> |
| | | /// ååºç»æ |
| | | /// </summary> |
| | | [Description("ååºç»æ")] |
| | | public string ResponseJsonData { get; set; } = string.Empty; |
| | | } |
| | | |
| | | public class AOPLogExInfo |
| | | { |
| | | public AOPLogInfo ApiLogAopInfo { get; set; } |
| | | /// <summary> |
| | | /// å¼å¸¸ |
| | | /// </summary> |
| | | [Description("å¼å¸¸")] |
| | | public string InnerException { get; set; } = string.Empty; |
| | | /// <summary> |
| | | /// å¼å¸¸ä¿¡æ¯ |
| | | /// </summary> |
| | | [Description("å¼å¸¸ä¿¡æ¯")] |
| | | public string ExMessage { get; set; } = string.Empty; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.DB.Models; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.HttpContextUser; |
| | | using WIDESEAWCS_Core.Tenants; |
| | | |
| | | namespace WIDESEAWCS_Core.AOP |
| | | { |
| | | public static class SqlSugarAop |
| | | { |
| | | public static void DataExecuting(object oldValue, DataFilterModel entityInfo) |
| | | { |
| | | if (entityInfo.EntityValue is BaseEntity baseEntity) |
| | | { |
| | | // æ°å¢æä½ |
| | | if (entityInfo.OperationType == DataFilterType.InsertByObject) |
| | | { |
| | | if (entityInfo.PropertyName == nameof(BaseEntity.CreateDate)) |
| | | { |
| | | baseEntity.CreateDate = DateTime.Now; |
| | | } |
| | | } |
| | | |
| | | else if (entityInfo.OperationType == DataFilterType.UpdateByObject) |
| | | { |
| | | baseEntity.ModifyDate = DateTime.Now; |
| | | } |
| | | |
| | | try |
| | | { |
| | | if (App.User?.UserId > 0) |
| | | { |
| | | switch (entityInfo.OperationType) |
| | | { |
| | | case DataFilterType.UpdateByObject: |
| | | baseEntity.Modifier = App.User.UserName; |
| | | break; |
| | | case DataFilterType.InsertByObject: |
| | | baseEntity.Creater = App.User.UserName; |
| | | break; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | switch (entityInfo.OperationType) |
| | | { |
| | | case DataFilterType.UpdateByObject: |
| | | baseEntity.Modifier = "System"; |
| | | break; |
| | | case DataFilterType.InsertByObject: |
| | | baseEntity.Creater = "System"; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | catch (NullReferenceException) |
| | | { |
| | | switch (entityInfo.OperationType) |
| | | { |
| | | case DataFilterType.UpdateByObject: |
| | | baseEntity.Modifier = "System"; |
| | | break; |
| | | case DataFilterType.InsertByObject: |
| | | baseEntity.Creater = "System"; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | private static string GetWholeSql(SugarParameter[] paramArr, string sql) |
| | | { |
| | | foreach (var param in paramArr) |
| | | { |
| | | sql = sql.Replace(param.ParameterName, $@"'{param.Value.ObjToString()}'"); |
| | | } |
| | | |
| | | return sql; |
| | | } |
| | | |
| | | private static string GetParas(SugarParameter[] pars) |
| | | { |
| | | string key = "ãSQLåæ°ãï¼"; |
| | | foreach (var param in pars) |
| | | { |
| | | key += $"{param.ParameterName}:{param.Value}\n"; |
| | | } |
| | | |
| | | return key; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Hosting; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.Extensions.Configuration; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Microsoft.Extensions.Hosting; |
| | | using Microsoft.Extensions.Options; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Core; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.HttpContextUser; |
| | | |
| | | namespace WIDESEAWCS_Core |
| | | { |
| | | public class App |
| | | { |
| | | static App() |
| | | { |
| | | EffectiveTypes = Assemblies.SelectMany(GetTypes); |
| | | } |
| | | |
| | | private static bool _isRun; |
| | | |
| | | /// <summary>æ¯å¦æ£å¨è¿è¡</summary> |
| | | public static bool IsBuild { get; set; } |
| | | |
| | | public static bool IsRun |
| | | { |
| | | get => _isRun; |
| | | set => _isRun = IsBuild = value; |
| | | } |
| | | |
| | | /// <summary>åºç¨ææç¨åºé</summary> |
| | | public static readonly IEnumerable<Assembly> Assemblies = RuntimeExtension.GetAllAssemblies(); |
| | | |
| | | /// <summary>ææç¨åºéç±»å</summary> |
| | | public static readonly IEnumerable<Type> EffectiveTypes; |
| | | |
| | | /// <summary>ä¼å
使ç¨App.GetService()æå¨è·åæå¡</summary> |
| | | public static IServiceProvider RootServices => IsRun || IsBuild ? InternalApp.RootServices : null; |
| | | |
| | | /// <summary>è·åWeb主æºç¯å¢ï¼å¦ï¼æ¯å¦æ¯å¼åç¯å¢ï¼ç产ç¯å¢ç</summary> |
| | | public static IWebHostEnvironment WebHostEnvironment => InternalApp.WebHostEnvironment; |
| | | |
| | | /// <summary>è·åæ³å主æºç¯å¢ï¼å¦ï¼æ¯å¦æ¯å¼åç¯å¢ï¼ç产ç¯å¢ç</summary> |
| | | public static IHostEnvironment HostEnvironment => InternalApp.HostEnvironment; |
| | | |
| | | /// <summary>å
¨å±é
ç½®é项</summary> |
| | | public static IConfiguration Configuration => InternalApp.Configuration; |
| | | |
| | | /// <summary> |
| | | /// è·å请æ±ä¸ä¸æ |
| | | /// </summary> |
| | | public static HttpContext HttpContext => RootServices?.GetService<IHttpContextAccessor>()?.HttpContext; |
| | | |
| | | public static IUser User => GetService<IUser>(); |
| | | |
| | | #region Service |
| | | |
| | | /// <summary>è§£ææå¡æä¾å¨</summary> |
| | | /// <param name="serviceType"></param> |
| | | /// <param name="mustBuild"></param> |
| | | /// <param name="throwException"></param> |
| | | /// <returns></returns> |
| | | public static IServiceProvider GetServiceProvider(Type serviceType, bool mustBuild = false, bool throwException = true) |
| | | { |
| | | if (App.HostEnvironment == null || App.RootServices != null && |
| | | InternalApp.InternalServices |
| | | .Where((u => |
| | | u.ServiceType == |
| | | (serviceType.IsGenericType ? serviceType.GetGenericTypeDefinition() : serviceType))) |
| | | .Any((u => u.Lifetime == ServiceLifetime.Singleton))) |
| | | return App.RootServices; |
| | | |
| | | //è·å请æ±çå卿çæå¡ |
| | | if (HttpContext?.RequestServices != null) |
| | | return HttpContext.RequestServices; |
| | | |
| | | if (RootServices != null) |
| | | { |
| | | IServiceScope scope = RootServices.CreateScope(); |
| | | return scope.ServiceProvider; |
| | | } |
| | | |
| | | if (mustBuild) |
| | | { |
| | | if (throwException) |
| | | { |
| | | throw new ApplicationException("å½åä¸å¯ç¨ï¼å¿
é¡»è¦çå° WebApplication Buildå"); |
| | | } |
| | | |
| | | return default; |
| | | } |
| | | |
| | | ServiceProvider serviceProvider = InternalApp.InternalServices.BuildServiceProvider(); |
| | | return serviceProvider; |
| | | } |
| | | |
| | | public static TService GetService<TService>(bool mustBuild = true) where TService : class |
| | | { |
| | | TService test = GetService(typeof(TService), null, mustBuild) as TService; |
| | | return test; |
| | | } |
| | | |
| | | /// <summary>è·å请æ±çå卿çæå¡</summary> |
| | | /// <typeparam name="TService"></typeparam> |
| | | /// <param name="serviceProvider"></param> |
| | | /// <param name="mustBuild"></param> |
| | | /// <returns></returns> |
| | | public static TService GetService<TService>(IServiceProvider serviceProvider, bool mustBuild = true) |
| | | where TService : class => (serviceProvider ?? App.GetServiceProvider(typeof(TService), mustBuild, false))?.GetService<TService>(); |
| | | |
| | | /// <summary>è·å请æ±çå卿çæå¡</summary> |
| | | /// <param name="type"></param> |
| | | /// <param name="serviceProvider"></param> |
| | | /// <param name="mustBuild"></param> |
| | | /// <returns></returns> |
| | | public static object GetService(Type type, IServiceProvider serviceProvider = null, bool mustBuild = true) |
| | | { |
| | | object obj = (serviceProvider ?? GetServiceProvider(type, mustBuild, false))?.GetService(type); |
| | | return obj; |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region private |
| | | |
| | | /// <summary>å è½½ç¨åºéä¸çææç±»å</summary> |
| | | /// <param name="ass"></param> |
| | | /// <returns></returns> |
| | | private static IEnumerable<Type> GetTypes(Assembly ass) |
| | | { |
| | | Type[] source = Array.Empty<Type>(); |
| | | try |
| | | { |
| | | source = ass.GetTypes(); |
| | | } |
| | | catch |
| | | { |
| | | //$@"Error load `{ass.FullName}` assembly.".WriteErrorLine(); |
| | | } |
| | | |
| | | return source.Where(u => u.IsPublic); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Options |
| | | |
| | | /// <summary>è·åé
ç½®</summary> |
| | | /// <typeparam name="TOptions">强类åé项类</typeparam> |
| | | /// <returns>TOptions</returns> |
| | | public static TOptions GetConfig<TOptions>() |
| | | where TOptions : class, IConfigurableOptions |
| | | { |
| | | TOptions instance = App.Configuration |
| | | .GetSection(ConfigurableOptions.GetConfigurationPath(typeof(TOptions))) |
| | | .Get<TOptions>(); |
| | | return instance; |
| | | } |
| | | |
| | | /// <summary>è·åé项</summary> |
| | | /// <typeparam name="TOptions">强类åé项类</typeparam> |
| | | /// <param name="serviceProvider"></param> |
| | | /// <returns>TOptions</returns> |
| | | public static TOptions GetOptions<TOptions>(IServiceProvider serviceProvider = null) where TOptions : class, new() |
| | | { |
| | | IOptions<TOptions> service = App.GetService<IOptions<TOptions>>(serviceProvider ?? App.RootServices, false); |
| | | return service?.Value; |
| | | } |
| | | |
| | | /// <summary>è·åé项</summary> |
| | | /// <typeparam name="TOptions">强类åé项类</typeparam> |
| | | /// <param name="serviceProvider"></param> |
| | | /// <returns>TOptions</returns> |
| | | public static TOptions GetOptionsMonitor<TOptions>(IServiceProvider serviceProvider = null) |
| | | where TOptions : class, new() |
| | | { |
| | | IOptionsMonitor<TOptions> service = |
| | | App.GetService<IOptionsMonitor<TOptions>>(serviceProvider ?? App.RootServices, false); |
| | | return service?.CurrentValue; |
| | | } |
| | | |
| | | /// <summary>è·åé项</summary> |
| | | /// <typeparam name="TOptions">强类åé项类</typeparam> |
| | | /// <param name="serviceProvider"></param> |
| | | /// <returns>TOptions</returns> |
| | | public static TOptions GetOptionsSnapshot<TOptions>(IServiceProvider serviceProvider = null) |
| | | where TOptions : class, new() |
| | | { |
| | | IOptionsSnapshot<TOptions> service = App.GetService<IOptionsSnapshot<TOptions>>(serviceProvider, false); |
| | | return service?.Value; |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Attributes |
| | | { |
| | | [AttributeUsage(AttributeTargets.Property)] |
| | | public class PropertyValidateAttribute : Attribute |
| | | { |
| | | public int MaxValue { get; set; } = int.MaxValue; |
| | | |
| | | public int MinValue { get; set; } = int.MinValue; |
| | | |
| | | public bool NotNullAndEmpty { get; set; } = true; |
| | | |
| | | public bool IsContainMaxValue { get; set; } = false; |
| | | |
| | | public bool IsContainMinValue { get; set; } = false; |
| | | |
| | | public string Description { get; set; } |
| | | |
| | | public PropertyValidateAttribute(string description) |
| | | { |
| | | if (!string.IsNullOrEmpty(description)) |
| | | Description = description; |
| | | } |
| | | } |
| | | |
| | | [AttributeUsage(AttributeTargets.Class)] |
| | | public class ModelValidateAttribute : Attribute |
| | | { |
| | | public ModelValidateType ModelValidateType { get; } = ModelValidateType.SimpleValidate; |
| | | |
| | | public ModelValidateAttribute() |
| | | { |
| | | } |
| | | } |
| | | |
| | | public enum ModelValidateType |
| | | { |
| | | SimpleValidate, |
| | | CustomValidate, |
| | | SimpleAndCustom |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Mvc.Filters; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IdentityModel.Tokens.Jwt; |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Security.Claims; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.Const; |
| | | |
| | | namespace WIDESEAWCS_Core.Authorization |
| | | { |
| | | public static class AuthorizationResponse |
| | | { |
| | | public static AuthorizationFilterContext FilterResult( |
| | | this AuthorizationFilterContext context, |
| | | HttpStatusCode statusCode, |
| | | string? message = null) |
| | | { |
| | | context.Result = new ContentResult() |
| | | { |
| | | Content = new { message, status = false, code = (int)statusCode }.Serialize(), |
| | | ContentType = "application/json", |
| | | StatusCode = (int)statusCode |
| | | }; |
| | | //Logger.Info(LoggerType.ApiAuthorize, message); |
| | | return context; |
| | | } |
| | | public static AuthorizationFilterContext Unauthorized(this AuthorizationFilterContext context, string? message = null) |
| | | { |
| | | return context.FilterResult(HttpStatusCode.Unauthorized, message); |
| | | } |
| | | //ä¸éè¿JWTéªè¯çï¼ç´æ¥å°ç¨æ·ä¿¡æ¯ç¼åèµ·æ¥ |
| | | public static void AddIdentity(this AuthorizationFilterContext context, int? userId = null) |
| | | { |
| | | int _userId = userId ?? JwtHelper.GetUserId(context.HttpContext.Request.Headers[AppSecret.TokenHeaderName]); |
| | | if (_userId <= 0) return; |
| | | //å°ç¨æ·Idç¼åå°ä¸ä¸æ(æè
èªå®ä¸ä¸ªå¯¹è±¡ï¼éè¿DI以AddScopedæ¹å¼æ³¨å
¥ä¸ä¸ææ¥ç®¡çç¨æ·ä¿¡æ¯) |
| | | var claims = new Claim[] { new Claim(JwtRegisteredClaimNames.Jti, _userId.ToString()) }; |
| | | context.HttpContext.User.AddIdentity(new ClaimsIdentity(claims)); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Authentication.JwtBearer; |
| | | using Microsoft.AspNetCore.Authorization; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Microsoft.IdentityModel.Tokens; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Security.Claims; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.Helper; |
| | | |
| | | namespace WIDESEAWCS_Core.Authorization |
| | | { |
| | | /// <summary> |
| | | /// ç³»ç» æææå¡ é
ç½® |
| | | /// </summary> |
| | | public static class AuthorizationSetup |
| | | { |
| | | /// <summary> |
| | | /// ç³»ç» æææå¡ é
ç½® |
| | | /// </summary> |
| | | /// <param name="services"></param> |
| | | /// <exception cref="ArgumentNullException"></exception> |
| | | public static void AddAuthorizationSetup(this IServiceCollection services) |
| | | { |
| | | if (services == null) throw new ArgumentNullException(nameof(services)); |
| | | |
| | | services.AddAuthentication(options => |
| | | { |
| | | options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; |
| | | options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; |
| | | options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; |
| | | }) |
| | | .AddJwtBearer(options => |
| | | { |
| | | options.TokenValidationParameters = new TokenValidationParameters |
| | | { |
| | | SaveSigninToken = true,//ä¿åtoken,åå°éªè¯tokenæ¯å¦çæ(éè¦) |
| | | ValidateIssuer = true,//æ¯å¦éªè¯Issuer |
| | | ValidateAudience = true,//æ¯å¦éªè¯Audience |
| | | ValidateLifetime = true,//æ¯å¦éªè¯å¤±ææ¶é´ |
| | | ValidateIssuerSigningKey = true,//æ¯å¦éªè¯SecurityKey |
| | | ValidAudience = AppSecret.Audience,//Audience |
| | | ValidIssuer = AppSecret.Issuer,//Issuerï¼è¿ä¸¤é¡¹ååé¢ç¾åjwtç设置ä¸è´ |
| | | IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(AppSecret.JWT)) |
| | | }; |
| | | options.Events = new JwtBearerEvents() |
| | | { |
| | | OnChallenge = context => |
| | | { |
| | | context.HandleResponse(); |
| | | context.Response.Clear(); |
| | | context.Response.ContentType = "application/json"; |
| | | context.Response.StatusCode = 401; |
| | | context.Response.WriteAsync(new { message = "æææªéè¿", status = false, code = 401 }.Serialize()); |
| | | return Task.CompletedTask; |
| | | } |
| | | }; |
| | | }); |
| | | |
| | | services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.IdentityModel.Tokens; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IdentityModel.Tokens.Jwt; |
| | | using System.Linq; |
| | | using System.Security.Claims; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.HttpContextUser; |
| | | |
| | | namespace WIDESEAWCS_Core.Authorization |
| | | { |
| | | public class JwtHelper |
| | | { |
| | | |
| | | /// <summary> |
| | | /// çæJWT |
| | | /// </summary> |
| | | /// <param name="serInfo"></param> |
| | | /// <returns></returns> |
| | | public static string IssueJwt(TokenModelJwt tokenModel) |
| | | { |
| | | string exp = $"{new DateTimeOffset(DateTime.Now.AddMinutes(/*tokenModel.UserId == 1 ? 43200 : */AppSettings.app("ExpMinutes").ObjToInt())).ToUnixTimeSeconds()}"; |
| | | List<Claim> claims = new List<Claim> |
| | | { |
| | | new Claim(JwtRegisteredClaimNames.Jti, tokenModel.UserId.ToString()), |
| | | new Claim(JwtRegisteredClaimNames.Iat, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"), |
| | | new Claim(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}") , |
| | | //JWTè¿ææ¶é´ |
| | | //é»è®¤è®¾ç½®jwtè¿ææ¶é´120åé |
| | | new Claim (JwtRegisteredClaimNames.Exp, exp), |
| | | new Claim(JwtRegisteredClaimNames.Iss, AppSecret.Issuer), |
| | | new Claim(JwtRegisteredClaimNames.Aud, AppSecret.Audience), |
| | | new Claim(ClaimTypes.Role, tokenModel.RoleId.ToString()), |
| | | new Claim(ClaimTypes.Name, tokenModel.UserName), |
| | | new Claim(nameof(TokenModelJwt.TenantId), tokenModel.TenantId.ToString()) |
| | | }; |
| | | |
| | | // å¯ä»¥å°ä¸ä¸ªç¨æ·çå¤ä¸ªè§è²å
¨é¨èµäºï¼ |
| | | // ä½è
ï¼DX æä¾ææ¯æ¯æï¼ |
| | | //ç§é¥16ä½ |
| | | var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(AppSecret.JWT)); |
| | | var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); |
| | | JwtSecurityToken securityToken = new JwtSecurityToken(issuer: AppSecret.Issuer, claims: claims, signingCredentials: creds); |
| | | string jwt = new JwtSecurityTokenHandler().WriteToken(securityToken); |
| | | return jwt; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è§£æ |
| | | /// </summary> |
| | | /// <param name="jwtStr"></param> |
| | | /// <returns></returns> |
| | | public static UserInfo SerializeJwt(string jwtStr) |
| | | { |
| | | var jwtHandler = new JwtSecurityTokenHandler(); |
| | | JwtSecurityToken jwtToken = jwtHandler.ReadJwtToken(jwtStr); |
| | | UserInfo userInfo = new UserInfo |
| | | { |
| | | UserId = Convert.ToInt32(jwtToken.Id), |
| | | RoleId = (jwtToken.Payload[ClaimTypes.Role] ?? 0).ObjToInt(), |
| | | }; |
| | | return userInfo; |
| | | } |
| | | /// <summary> |
| | | /// è·åè¿ææ¶é´ |
| | | /// </summary> |
| | | /// <param name="jwtStr"></param> |
| | | /// <returns></returns> |
| | | public static DateTime GetExp(string jwtStr) |
| | | { |
| | | var jwtHandler = new JwtSecurityTokenHandler(); |
| | | JwtSecurityToken jwtToken = jwtHandler.ReadJwtToken(jwtStr); |
| | | |
| | | DateTime expDate = (jwtToken.Payload[JwtRegisteredClaimNames.Exp] ?? 0).ObjToInt().GetTimeSpmpToDate(); |
| | | return expDate; |
| | | } |
| | | public static bool IsExp(string jwtStr) |
| | | { |
| | | return GetExp(jwtStr) < DateTime.Now; |
| | | } |
| | | |
| | | public static int GetUserId(string jwtStr) |
| | | { |
| | | try |
| | | { |
| | | if (jwtStr.IsNullOrEmpty()) return 0; |
| | | jwtStr = jwtStr.Replace("Bearer ", ""); |
| | | return new JwtSecurityTokenHandler().ReadJwtToken(jwtStr).Id.ObjToInt(); |
| | | } |
| | | catch |
| | | { |
| | | return 0; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 令ç |
| | | /// </summary> |
| | | public class TokenModelJwt |
| | | { |
| | | /// <summary> |
| | | /// UserId |
| | | /// </summary> |
| | | public long UserId { get; set; } |
| | | /// <summary> |
| | | /// è§è² |
| | | /// </summary> |
| | | public int RoleId { get; set; } |
| | | /// <summary> |
| | | /// èè½ |
| | | /// </summary> |
| | | public string UserName { get; set; } |
| | | |
| | | public long TenantId { get; set; } |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Authorization; |
| | | using Microsoft.AspNetCore.DataProtection.KeyManagement; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Microsoft.Extensions.Options; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | |
| | | namespace WIDESEAWCS_Core.BaseController |
| | | { |
| | | [Authorize, ApiController] |
| | | public class ApiBaseController<IService, TEntity> : Controller |
| | | { |
| | | protected IService Service; |
| | | |
| | | public ApiBaseController(IService service) |
| | | { |
| | | Service = service; |
| | | } |
| | | |
| | | [HttpPost, Route("GetPageData")] |
| | | public virtual ActionResult GetPageData([FromBody] PageDataOptions options) |
| | | { |
| | | return Json(InvokeService("GetPageData", new object[] { options })); |
| | | } |
| | | |
| | | [HttpPost, Route("GetDetailPage")] |
| | | public virtual ActionResult GetDetailPage([FromBody] PageDataOptions pageData) |
| | | { |
| | | return Json(InvokeService("GetDetailPage", new object[] { pageData })); |
| | | } |
| | | |
| | | [HttpPost, Route("AddData")] |
| | | public virtual ActionResult AddData([FromBody] TEntity options) |
| | | { |
| | | return Json(InvokeService("AddData", new object[] { options })); |
| | | } |
| | | |
| | | [HttpPost, Route("Add")] |
| | | public virtual ActionResult Add([FromBody] SaveModel options) |
| | | { |
| | | return Json(InvokeService("AddData", new object[] { options })); |
| | | } |
| | | |
| | | [HttpPost, Route("Update")] |
| | | public virtual ActionResult Update([FromBody] SaveModel options) |
| | | { |
| | | return Json(InvokeService("UpdateData", new object[] { options })); |
| | | } |
| | | |
| | | [HttpPost, Route("UpdateData")] |
| | | public virtual ActionResult UpdateData([FromBody] TEntity options) |
| | | { |
| | | return Json(InvokeService("UpdateData", new object[] { options })); |
| | | } |
| | | |
| | | [HttpPost, Route("Del")] |
| | | public virtual ActionResult Del([FromBody] object[] key) |
| | | { |
| | | return Json(InvokeService("DeleteData", new object[] { key })); |
| | | } |
| | | |
| | | [HttpPost, Route("Export")] |
| | | public virtual ActionResult Export([FromBody] PageDataOptions loadData) |
| | | { |
| | | WebResponseContent result = InvokeService("Export", new object[] { loadData }) as WebResponseContent; |
| | | if (result.Status) |
| | | return File( |
| | | System.IO.File.ReadAllBytes(result.Data.ToString()), |
| | | System.Net.Mime.MediaTypeNames.Application.Octet, |
| | | Path.GetFileName(result.Data.ToString()) |
| | | ); |
| | | return Json(result); |
| | | } |
| | | |
| | | [HttpPost,HttpGet, Route("DownLoadTemplate")] |
| | | public virtual ActionResult DownLoadTemplate() |
| | | { |
| | | WebResponseContent result = InvokeService("DownLoadTemplate", new object[] { }) as WebResponseContent; |
| | | if (result.Status) |
| | | return File( |
| | | System.IO.File.ReadAllBytes(result.Data.ToString()), |
| | | System.Net.Mime.MediaTypeNames.Application.Octet, |
| | | Path.GetFileName(result.Data.ToString()) |
| | | ); |
| | | return Json(result); |
| | | } |
| | | |
| | | [HttpPost, Route("Import")] |
| | | public virtual ActionResult Import(List<IFormFile> fileInput) |
| | | { |
| | | return Json(InvokeService("Import", new object[] { fileInput })); |
| | | } |
| | | |
| | | [HttpPost, Route("ExportSeedData"), AllowAnonymous] |
| | | public ActionResult ExportSeedData() |
| | | { |
| | | return Json(InvokeService("ExportSeedData", new object[] { })); |
| | | } |
| | | |
| | | private object InvokeService(string methodName, object[] parameters) |
| | | { |
| | | Type t = Service.GetType(); |
| | | List<Type> types = new List<Type>(); |
| | | foreach (var param in parameters) |
| | | { |
| | | types.Add(param.GetType()); |
| | | } |
| | | MethodInfo method = t.GetMethod(methodName, types.ToArray()); |
| | | return method.Invoke(Service, parameters); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core |
| | | { |
| | | public class PageDataOptions |
| | | { |
| | | public int Page { get; set; } |
| | | public int Rows { get; set; } |
| | | public int Total { get; set; } |
| | | public string TableName { get; set; } |
| | | public string Sort { get; set; } |
| | | /// <summary> |
| | | /// æåºæ¹å¼ |
| | | /// </summary> |
| | | public string Order { get; set; } |
| | | public string Wheres { get; set; } |
| | | public bool Export { get; set; } |
| | | public object Value { get; set; } |
| | | /// <summary> |
| | | /// æ¥è¯¢æ¡ä»¶ |
| | | /// </summary> |
| | | public List<SearchParameters> Filter { get; set; } |
| | | } |
| | | public class SearchParameters |
| | | { |
| | | public string Name { get; set; } |
| | | public string Value { get; set; } |
| | | //æ¥è¯¢ç±»åï¼LinqExpressionType |
| | | public string DisplayType { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core |
| | | { |
| | | public class PageGridData<T> |
| | | { |
| | | public int Total { get; set; } |
| | | public List<T> Rows { get; set; } |
| | | public object Summary { get; set; } |
| | | |
| | | public PageGridData() |
| | | { |
| | | |
| | | } |
| | | |
| | | public PageGridData(int total, List<T> rows) |
| | | { |
| | | Total = total; |
| | | Rows = rows; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core |
| | | { |
| | | public class Permissions |
| | | { |
| | | public int MenuId { get; set; } |
| | | public int ParentId { get; set; } |
| | | public string TableName { get; set; } |
| | | public string MenuAuth { get; set; } |
| | | public string UserAuth { get; set; } |
| | | /// <summary> |
| | | /// å½åç¨æ·æé,åå¨çæ¯æéçå¼ï¼å¦:Add,Searchç |
| | | /// </summary> |
| | | public string[] UserAuthArr { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 2022.03.26 |
| | | /// èåç±»å1:ç§»å¨ç«¯ï¼0:PC端 |
| | | /// </summary> |
| | | public int MenuType { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core |
| | | { |
| | | public class SaveModel |
| | | { |
| | | public Dictionary<string, object> MainData { get; set; } |
| | | public List<Dictionary<string, object>> DetailData { get; set; } |
| | | public List<object> DelKeys { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ä»åå°ä¼ å
¥çå
¶ä»åæ°(èªå®ä¹æ©å±å¯ä»¥ä½¿ç¨) |
| | | /// </summary> |
| | | public object Extra { get; set; } |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core |
| | | { |
| | | public class WebResponseContent |
| | | { |
| | | public WebResponseContent() |
| | | { |
| | | } |
| | | public WebResponseContent(bool status) |
| | | { |
| | | Status = status; |
| | | } |
| | | public bool Status { get; set; } |
| | | |
| | | public int Code { get; set; } |
| | | |
| | | public string Message { get; set; } |
| | | |
| | | public object Data { get; set; } |
| | | |
| | | public string DevMessage { get; set; } |
| | | |
| | | public WebResponseContent OK() |
| | | { |
| | | Status = true; |
| | | return this; |
| | | } |
| | | |
| | | public static WebResponseContent Instance |
| | | { |
| | | get { return new WebResponseContent(); } |
| | | } |
| | | public WebResponseContent OK(string message = null, object data = null) |
| | | { |
| | | Status = true; |
| | | Message = message; |
| | | Data = data; |
| | | return this; |
| | | } |
| | | |
| | | public WebResponseContent Error(string message = null) |
| | | { |
| | | Status = false; |
| | | Message = message; |
| | | return this; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Data.SqlClient; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Linq; |
| | | using System.Linq.Expressions; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.BaseRepository |
| | | { |
| | | public interface IRepository<TEntity> : IDependency where TEntity : class, new() |
| | | { |
| | | /// <summary> |
| | | /// SqlsugarClientå®ä½ |
| | | /// </summary> |
| | | ISqlSugarClient Db { get; } |
| | | /// <summary> |
| | | /// éè¿ä¸»é®æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="id">主é®</param> |
| | | /// <returns>æ¥è¯¢ç»æ</returns> |
| | | TEntity QureyDataById(object id); |
| | | |
| | | Task<TEntity> QureyDataByIdAsync(object id); |
| | | |
| | | /// <summary> |
| | | /// éè¿ä¸»é®æ°ç»æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="lstIds">䏻鮿°ç»</param> |
| | | /// <returns>æ¥è¯¢ç»æéå</returns> |
| | | List<TEntity> QureyDataByIds(object[] lstIds); |
| | | |
| | | Task<List<TEntity>> QureyDataByIdsAsync(object[] lstIds); |
| | | |
| | | /// <summary> |
| | | /// éè¿ä¸»é®éåæ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="lstIds">主é®éå</param> |
| | | /// <returns>æ¥è¯¢ç»æéå</returns> |
| | | List<TEntity> QureyDataByIds(List<object> lstIds); |
| | | |
| | | Task<List<TEntity>> QureyDataByIdsAsync(List<object> lstIds); |
| | | |
| | | /// <summary> |
| | | /// æ·»å åæ¡æ°æ® |
| | | /// </summary> |
| | | /// <param name="entity"></param> |
| | | /// <returns>å½±åè¡æ°</returns> |
| | | int AddData(TEntity entity); |
| | | |
| | | Task<int> AddDataAsync(TEntity entity); |
| | | |
| | | /// <summary> |
| | | /// æ·»å 夿¡æ°æ® |
| | | /// </summary> |
| | | /// <param name="listEntity"></param> |
| | | /// <returns>å½±åè¡æ°</returns> |
| | | int AddData(List<TEntity> listEntity); |
| | | |
| | | Task<int> AddDataAsync(List<TEntity> listEntity); |
| | | |
| | | /// <summary> |
| | | /// éè¿ä¸»é®å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="id">主é®</param> |
| | | /// <returns>å é¤ç»æ</returns> |
| | | bool DeleteDataById(object id); |
| | | |
| | | Task<bool> DeleteDataByIdAsync(object id); |
| | | |
| | | /// <summary> |
| | | /// éè¿ä¸»é®æ°æ®å é¤å¤æ¡æ°æ® |
| | | /// </summary> |
| | | /// <param name="ids">䏻鮿°ç»</param> |
| | | /// <returns>å é¤ç»æ</returns> |
| | | bool DeleteDataByIds(object[] ids); |
| | | |
| | | Task<bool> DeleteDataByIdsAsync(object[] ids); |
| | | |
| | | /// <summary> |
| | | /// éè¿å®ä½æ°æ®å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="ids">䏻鮿°ç»</param> |
| | | /// <returns>å é¤ç»æ</returns> |
| | | bool DeleteData(TEntity entity); |
| | | |
| | | Task<bool> DeleteDataAsync(TEntity entity); |
| | | |
| | | /// <summary> |
| | | /// éè¿å®ä½éåæ°æ®å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="ids">䏻鮿°ç»</param> |
| | | /// <returns>å é¤ç»æ</returns> |
| | | bool DeleteData(List<TEntity> listEntity); |
| | | |
| | | Task<bool> DeleteDataAsync(List<TEntity> listEntity); |
| | | |
| | | /// <summary> |
| | | /// æ´æ°åæ¡æ°æ® |
| | | /// </summary> |
| | | /// <param name="entity"></param> |
| | | /// <returns></returns> |
| | | bool UpdateData(TEntity entity); |
| | | |
| | | Task<bool> UpdateDataAsync(TEntity entity); |
| | | |
| | | /// <summary> |
| | | /// æ´æ°å¤æ¡æ°æ® |
| | | /// </summary> |
| | | /// <param name="listEntity"></param> |
| | | /// <returns></returns> |
| | | bool UpdateData(List<TEntity> listEntity); |
| | | |
| | | Task<bool> UpdateDataAsync(List<TEntity> listEntity); |
| | | |
| | | /// <summary> |
| | | /// æå®åæ´æ°æ°æ® |
| | | /// </summary> |
| | | /// <param name="entity"></param> |
| | | /// <param name="lstColumns"></param> |
| | | /// <param name="lstIgnoreColumns"></param> |
| | | /// <returns></returns> |
| | | bool UpdateData(TEntity entity, List<string> lstColumns, List<string>? lstIgnoreColumns = null); |
| | | |
| | | Task<bool> UpdateDataAsync(TEntity entity, List<string> lstColumns, List<string>? lstIgnoreColumns = null); |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢æææ°æ® |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | List<TEntity> QueryData(); |
| | | |
| | | Task<List<TEntity>> QueryDataAsync(); |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="where"></param> |
| | | /// <returns></returns> |
| | | List<TEntity> QueryData(string where); |
| | | |
| | | Task<List<TEntity>> QueryDataAsync(string where); |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <returns></returns> |
| | | List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression); |
| | | |
| | | Task<List<TEntity>> QueryDataAsync(Expression<Func<TEntity, bool>> whereExpression); |
| | | |
| | | TEntity QueryFirst(Expression<Func<TEntity, bool>> whereExpression); |
| | | |
| | | Task<TEntity> QueryFirstAsync(Expression<Func<TEntity, bool>> whereExpression); |
| | | |
| | | TResult QueryFirst<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> expression); |
| | | |
| | | Task<TResult> QueryFirstAsync<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> expression); |
| | | |
| | | TResult QueryFirst<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> expression, Dictionary<string, OrderByType> orderBy); |
| | | |
| | | Task<TResult> QueryFirstAsync<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> expression, Dictionary<string, OrderByType> orderBy); |
| | | |
| | | TEntity QueryFirst(Expression<Func<TEntity, bool>> whereExpression, Dictionary<string, OrderByType> orderBy); |
| | | |
| | | Task<TEntity> QueryFirstAsync(Expression<Func<TEntity, bool>> whereExpression, Dictionary<string, OrderByType> orderBy); |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ®å¹¶æåº |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression, Dictionary<string, OrderByType> orderBy); |
| | | |
| | | Task<List<TEntity>> QueryDataAsync(Expression<Func<TEntity, bool>> whereExpression, string orderByFields); |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ®å¹¶æåº |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="where"></param> |
| | | /// <returns></returns> |
| | | List<TEntity> QueryData(string where, Dictionary<string, OrderByType> orderBy); |
| | | |
| | | Task<List<TEntity>> QueryDataAsync(string where, Dictionary<string, OrderByType> orderBy); |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢æå®æ°æ®å¯¹è±¡ |
| | | /// </summary> |
| | | /// <typeparam name="TResult"></typeparam> |
| | | /// <param name="expression"></param> |
| | | /// <returns></returns> |
| | | List<TResult> QueryData<TResult>(Expression<Func<TEntity, TResult>> expression); |
| | | |
| | | Task<List<TResult>> QueryDataAsync<TResult>(Expression<Func<TEntity, TResult>> expression); |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æå®æ°æ®å¯¹è±¡ |
| | | /// </summary> |
| | | /// <typeparam name="TResult"></typeparam> |
| | | /// <param name="expression"></param> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | List<TResult> QueryData<TResult>(Expression<Func<TEntity, TResult>> expression, Expression<Func<TEntity, bool>> whereExpression, string orderByFields = ""); |
| | | |
| | | Task<List<TResult>> QueryDataAsync<TResult>(Expression<Func<TEntity, TResult>> expression, Expression<Func<TEntity, bool>> whereExpression, string orderByFields); |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ®å¹¶æåº |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="orderByExpression"></param> |
| | | /// <param name="isAsc"></param> |
| | | /// <returns></returns> |
| | | List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true); |
| | | |
| | | Task<List<TEntity>> QueryDataAsync(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true); |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ®å¹¶æåº |
| | | /// </summary> |
| | | /// <param name="where"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | List<TEntity> QueryData(string where, string orderByFields); |
| | | |
| | | Task<List<TEntity>> QueryDataAsync(string where, string orderByFields); |
| | | |
| | | /// <summary> |
| | | /// åçSqlè¯å¥æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="sql"></param> |
| | | /// <param name="parameters"></param> |
| | | /// <returns></returns> |
| | | List<TEntity> QueryDataBySql(string sql, SugarParameter[]? parameters = null); |
| | | |
| | | Task<List<TEntity>> QueryDataBySqlAsync(string sql, SugarParameter[]? parameters = null); |
| | | |
| | | /// <summary> |
| | | /// åçSqlè¯å¥æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="sql"></param> |
| | | /// <param name="parameters"></param> |
| | | /// <returns></returns> |
| | | List<dynamic> QueryDynamicDataBySql(string sql, SugarParameter[]? parameters = null); |
| | | |
| | | Task<List<dynamic>> QueryDynamicDataBySqlAsync(string sql, SugarParameter[]? parameters = null); |
| | | |
| | | List<object> QueryObjectDataBySql(string sql, SugarParameter[]? parameters = null); |
| | | |
| | | Task<List<object>> QueryObjectDataBySqlAsync(string sql, SugarParameter[]? parameters = null); |
| | | |
| | | /// <summary> |
| | | /// åçSqlè¯å¥æ§è¡æä½ |
| | | /// </summary> |
| | | /// <param name="sql"></param> |
| | | /// <param name="sqlParameters"></param> |
| | | /// <returns></returns> |
| | | int ExecuteSqlCommand(string sql, params SqlParameter[] sqlParameters); |
| | | |
| | | Task<int> ExecuteSqlCommandAsync(string sql, params SqlParameter[] sqlParameters); |
| | | |
| | | /// <summary> |
| | | /// åçSqlè¯å¥æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="sql"></param> |
| | | /// <param name="parameters"></param> |
| | | /// <returns></returns> |
| | | DataTable QueryTable(string sql, SugarParameter[]? parameters = null); |
| | | |
| | | Task<DataTable> QueryTableAsync(string sql, SugarParameter[]? parameters = null); |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ®æå®æ°éçè¡ |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="top"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression, int top, string orderByFields); |
| | | |
| | | Task<List<TEntity>> QueryDataAsync(Expression<Func<TEntity, bool>> whereExpression, int top, string orderByFields); |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æå®æ°éçè¡ |
| | | /// </summary> |
| | | /// <param name="where"></param> |
| | | /// <param name="top"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | List<TEntity> QueryData(string where, int top, string orderByFields); |
| | | |
| | | Task<List<TEntity>> QueryDataAsync(string where, int top, string orderByFields); |
| | | |
| | | /// <summary> |
| | | /// å页æ¥è¯¢ |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pageSize, string orderByFields); |
| | | |
| | | Task<List<TEntity>> QueryDataAsync(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pageSize, string orderByFields); |
| | | |
| | | /// <summary> |
| | | /// å页æ¥è¯¢ |
| | | /// </summary> |
| | | /// <param name="where"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | List<TEntity> QueryData(string where, int pageIndex, int pageSize, string orderByFields); |
| | | |
| | | Task<List<TEntity>> QueryDataAsync(string where, int pageIndex, int pageSize, string orderByFields); |
| | | |
| | | /// <summary> |
| | | /// å页æ¥è¯¢ |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | PageGridData<TEntity> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pageSize, string? orderByFields = null); |
| | | |
| | | /// <summary> |
| | | /// å页æ¥è¯¢ |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pagesize"></param> |
| | | /// <param name="orderBy"></param> |
| | | /// <returns></returns> |
| | | PageGridData<TEntity> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pagesize, Dictionary<string, OrderByType> orderBy); |
| | | |
| | | PageGridData<TEntity> QueryPage(string where, int pageIndex, int pageSize, Dictionary<string, OrderByType> orderBy); |
| | | |
| | | /// <summary> |
| | | /// ä¸¤è¡¨èæ¥ |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <typeparam name="T2"></typeparam> |
| | | /// <typeparam name="TResult"></typeparam> |
| | | /// <param name="joinExpression"></param> |
| | | /// <param name="selectExpression"></param> |
| | | /// <param name="whereExpression"></param> |
| | | /// <returns></returns> |
| | | List<TResult> QueryTabs<T, T2, TResult>( |
| | | Expression<Func<T, T2, object[]>> joinExpression, |
| | | Expression<Func<T, T2, TResult>> selectExpression, |
| | | Expression<Func<T,T2, bool>> whereExpressionT1, |
| | | Expression<Func<TResult, bool>> whereExpression); |
| | | |
| | | Task<List<TResult>> QueryTabsAsync<T, T2, TResult>( |
| | | Expression<Func<T, T2, object[]>> joinExpression, |
| | | Expression<Func<T, T2, TResult>> selectExpression, |
| | | Expression<Func<TResult, bool>> whereExpression); |
| | | |
| | | /// <summary> |
| | | /// ä¸¤è¡¨èæ¥-å页 |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <typeparam name="T2"></typeparam> |
| | | /// <typeparam name="TResult"></typeparam> |
| | | /// <param name="joinExpression"></param> |
| | | /// <param name="selectExpression"></param> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | PageGridData<TResult> QueryTabsPage<T, T2, TResult>( |
| | | Expression<Func<T, T2, object[]>> joinExpression, |
| | | Expression<Func<T, T2, TResult>> selectExpression, |
| | | Expression<Func<TResult, bool>> whereExpression, |
| | | int pageIndex = 1, |
| | | int pageSize = 20, |
| | | string? orderByFields = null); |
| | | |
| | | /// <summary> |
| | | /// 两表èåæ¥è¯¢-å页-åç» |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <typeparam name="T2"></typeparam> |
| | | /// <typeparam name="TResult"></typeparam> |
| | | /// <param name="joinExpression"></param> |
| | | /// <param name="selectExpression"></param> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="groupExpression"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | PageGridData<TResult> QueryTabsPage<T, T2, TResult>( |
| | | Expression<Func<T, T2, object[]>> joinExpression, |
| | | Expression<Func<T, T2, TResult>> selectExpression, |
| | | Expression<Func<TResult, bool>> whereExpression, |
| | | Expression<Func<T, object>> groupExpression, |
| | | int pageIndex = 1, |
| | | int pageSize = 20, |
| | | string? orderByFields = null); |
| | | |
| | | |
| | | //List<TResult> QueryMuch<T, T2, T3, TResult>( |
| | | // Expression<Func<T, T2, T3, object[]>> joinExpression, |
| | | // Expression<Func<T, T2, T3, TResult>> selectExpression, |
| | | // Expression<Func<T, T2, T3, bool>> whereLambda = null) where T : class, new(); |
| | | //Task<PageModel<TEntity>> QueryPage(PaginationModel pagination); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System.Data; |
| | | using System.Linq.Expressions; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Reflection; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using Microsoft.Data.SqlClient; |
| | | using System.Drawing.Printing; |
| | | using WIDESEAWCS_Core.Tenants; |
| | | using WIDESEAWCS_Core.Seed; |
| | | using WIDESEAWCS_Core.DB; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.AOP; |
| | | using OfficeOpenXml.FormulaParsing.ExpressionGraph; |
| | | |
| | | namespace WIDESEAWCS_Core.BaseRepository |
| | | { |
| | | public class RepositoryBase<TEntity> : IRepository<TEntity> where TEntity : class, new() |
| | | { |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly SqlSugarScope _dbBase; |
| | | |
| | | private ISqlSugarClient _db |
| | | { |
| | | get |
| | | { |
| | | ISqlSugarClient db = _dbBase; |
| | | |
| | | //å¤ç§æ· |
| | | var mta = typeof(TEntity).GetCustomAttribute<MultiTenantAttribute>(); |
| | | if (mta is { TenantType: TenantTypeEnum.Db }) |
| | | { |
| | | //è·åç§æ·ä¿¡æ¯ ç§æ·ä¿¡æ¯å¯ä»¥æåç¼å䏿¥ |
| | | if (App.User is { TenantId: > 0 }) |
| | | { |
| | | dynamic tenant = db.Queryable(MainDb.TenantTableName, "x").Where(MainDb.TenantId, "=", App.User.TenantId).First(); |
| | | if (tenant != null) |
| | | { |
| | | var iTenant = db.AsTenant(); |
| | | if (!iTenant.IsAnyConnection(tenant.TenantId)) |
| | | { |
| | | string conStr = tenant.ConnectionString; |
| | | ConnectionConfig connectionConfig = new ConnectionConfig() |
| | | { |
| | | ConfigId = tenant.TenantId, |
| | | ConnectionString = conStr.DecryptDES(AppSecret.DB), |
| | | DbType = (SqlSugar.DbType)tenant.DbType, |
| | | IsAutoCloseConnection = true, |
| | | AopEvents = new AopEvents() |
| | | { |
| | | DataExecuting = SqlSugarAop.DataExecuting |
| | | } |
| | | }; |
| | | iTenant.AddConnection(connectionConfig); |
| | | } |
| | | |
| | | return iTenant.GetConnection(tenant.TenantId); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return db; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// åå»ºæ°æ®åºè¿æ¥å¯¹è±¡ |
| | | /// </summary> |
| | | public ISqlSugarClient Db => _db; |
| | | |
| | | public RepositoryBase(IUnitOfWorkManage unitOfWorkManage) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _dbBase = unitOfWorkManage.GetDbClient(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éè¿ä¸»é®æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="id">主é®</param> |
| | | /// <returns>æ¥è¯¢ç»æ</returns> |
| | | public virtual TEntity QureyDataById(object id) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().In(id).Single(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éè¿ä¸»é®æ°ç»æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="lstIds">䏻鮿°ç»</param> |
| | | /// <returns>æ¥è¯¢ç»æéå</returns> |
| | | public virtual List<TEntity> QureyDataByIds(object[] lstIds) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().In(lstIds).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éè¿ä¸»é®éåæ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="lstIds">主é®éå</param> |
| | | /// <returns>æ¥è¯¢ç»æéå</returns> |
| | | public virtual List<TEntity> QureyDataByIds(List<object> lstIds) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().In(lstIds).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ·»å åæ¡æ°æ® |
| | | /// </summary> |
| | | /// <param name="entity"></param> |
| | | /// <returns>å½±åè¡æ°</returns> |
| | | public virtual int AddData(TEntity entity) |
| | | { |
| | | IInsertable<TEntity> insert = _db.CopyNew().Insertable(entity); |
| | | return insert.ExecuteReturnIdentity(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ·»å 夿¡æ°æ® |
| | | /// </summary> |
| | | /// <param name="listEntity"></param> |
| | | /// <returns>å½±åè¡æ°</returns> |
| | | public virtual int AddData(List<TEntity> listEntity) |
| | | { |
| | | IInsertable<TEntity> insert = _db.CopyNew().Insertable(listEntity); |
| | | return insert.ExecuteCommand(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éè¿ä¸»é®å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="id">主é®</param> |
| | | /// <returns>å é¤ç»æ</returns> |
| | | public virtual bool DeleteDataById(object id) |
| | | { |
| | | return _db.CopyNew().Deleteable<TEntity>().In(id).ExecuteCommandHasChange(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éè¿ä¸»é®æ°æ®å é¤å¤æ¡æ°æ® |
| | | /// </summary> |
| | | /// <param name="ids">䏻鮿°ç»</param> |
| | | /// <returns>å é¤ç»æ</returns> |
| | | public virtual bool DeleteDataByIds(object[] ids) |
| | | { |
| | | return _db.CopyNew().Deleteable<TEntity>().In(ids).ExecuteCommandHasChange(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éè¿å®ä½æ°æ®å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="ids">䏻鮿°ç»</param> |
| | | /// <returns>å é¤ç»æ</returns> |
| | | public virtual bool DeleteData(TEntity entity) |
| | | { |
| | | return _db.CopyNew().Deleteable(entity).ExecuteCommandHasChange(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éè¿å®ä½éåæ°æ®å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="ids">䏻鮿°ç»</param> |
| | | /// <returns>å é¤ç»æ</returns> |
| | | public virtual bool DeleteData(List<TEntity> listEntity) |
| | | { |
| | | return _db.CopyNew().Deleteable(listEntity).ExecuteCommandHasChange(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°åæ¡æ°æ® |
| | | /// </summary> |
| | | /// <param name="entity"></param> |
| | | /// <returns></returns> |
| | | public virtual bool UpdateData(TEntity entity) |
| | | { |
| | | return _db.CopyNew().Updateable(entity).ExecuteCommandHasChange(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°å¤æ¡æ°æ® |
| | | /// </summary> |
| | | /// <param name="listEntity"></param> |
| | | /// <returns></returns> |
| | | public virtual bool UpdateData(List<TEntity> listEntity) |
| | | { |
| | | return _db.CopyNew().Updateable(listEntity).ExecuteCommandHasChange(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå®åæ´æ°æ°æ® |
| | | /// </summary> |
| | | /// <param name="entity"></param> |
| | | /// <param name="lstColumns"></param> |
| | | /// <param name="lstIgnoreColumns"></param> |
| | | /// <returns></returns> |
| | | public virtual bool UpdateData(TEntity entity, List<string> lstColumns, List<string>? lstIgnoreColumns = null) |
| | | { |
| | | IUpdateable<TEntity> update = _db.CopyNew().Updateable(entity); |
| | | |
| | | if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0) |
| | | { |
| | | update = update.IgnoreColumns(lstIgnoreColumns.ToArray()); |
| | | } |
| | | |
| | | if (lstColumns != null && lstColumns.Count > 0) |
| | | { |
| | | update = update.UpdateColumns(lstColumns.ToArray()); |
| | | } |
| | | |
| | | return update.ExecuteCommandHasChange(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢æææ°æ® |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public virtual List<TEntity> QueryData() |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="where"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TEntity> QueryData(string where) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(!string.IsNullOrEmpty(where), where).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).ToList(); |
| | | } |
| | | |
| | | public virtual TEntity QueryFirst(Expression<Func<TEntity, bool>> whereExpression) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).First(); |
| | | } |
| | | |
| | | public virtual TResult QueryFirst<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> expression) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).Select(expression).First(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ®å¹¶æåº |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression, Dictionary<string, OrderByType> orderBy) |
| | | { |
| | | List<OrderByModel> orderByModels = new List<OrderByModel>(); |
| | | foreach (var item in orderBy) |
| | | { |
| | | OrderByModel orderByModel = new OrderByModel() |
| | | { |
| | | FieldName = item.Key, |
| | | OrderByType = item.Value |
| | | }; |
| | | orderByModels.Add(orderByModel); |
| | | } |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderBy(orderByModels).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ®å¹¶æåº |
| | | /// </summary> |
| | | /// <param name="where"></param> |
| | | /// <param name="orderBy"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TEntity> QueryData(string where, Dictionary<string, OrderByType> orderBy) |
| | | { |
| | | List<OrderByModel> orderByModels = new List<OrderByModel>(); |
| | | foreach (var item in orderBy) |
| | | { |
| | | OrderByModel orderByModel = new OrderByModel() |
| | | { |
| | | FieldName = item.Key, |
| | | OrderByType = item.Value |
| | | }; |
| | | orderByModels.Add(orderByModel); |
| | | } |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(!string.IsNullOrEmpty(where), where).OrderBy(orderByModels).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢æå®æ°æ®å¯¹è±¡ |
| | | /// </summary> |
| | | /// <typeparam name="TResult"></typeparam> |
| | | /// <param name="expression"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TResult> QueryData<TResult>(Expression<Func<TEntity, TResult>> expression) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().Select(expression).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æå®æ°æ®å¯¹è±¡ |
| | | /// </summary> |
| | | /// <typeparam name="TResult"></typeparam> |
| | | /// <param name="expression"></param> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TResult> QueryData<TResult>(Expression<Func<TEntity, TResult>> expression, Expression<Func<TEntity, bool>> whereExpression, string orderByFields = "") |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(whereExpression != null, whereExpression).Select(expression).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ®å¹¶æåº |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="orderByExpression"></param> |
| | | /// <param name="isAsc"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ®å¹¶æåº |
| | | /// </summary> |
| | | /// <param name="where"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TEntity> QueryData(string where, string orderByFields) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(!string.IsNullOrEmpty(where), where).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åçSqlè¯å¥æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="sql"></param> |
| | | /// <param name="parameters"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TEntity> QueryDataBySql(string sql, SugarParameter[]? parameters = null) |
| | | { |
| | | return _db.Ado.SqlQuery<TEntity>(sql, parameters); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åçSqlè¯å¥æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="sql"></param> |
| | | /// <param name="parameters"></param> |
| | | /// <returns></returns> |
| | | public virtual List<dynamic> QueryDynamicDataBySql(string sql, SugarParameter[]? parameters = null) |
| | | { |
| | | return _db.Ado.SqlQuery<dynamic>(sql, parameters); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åçSqlè¯å¥æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="sql"></param> |
| | | /// <param name="parameters"></param> |
| | | /// <returns></returns> |
| | | public virtual List<object> QueryObjectDataBySql(string sql, SugarParameter[]? parameters = null) |
| | | { |
| | | return _db.Ado.SqlQuery<object>(sql, parameters); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åçSqlè¯å¥æ§è¡æä½ |
| | | /// </summary> |
| | | /// <param name="sql"></param> |
| | | /// <param name="sqlParameters"></param> |
| | | /// <returns></returns> |
| | | public virtual int ExecuteSqlCommand(string sql, params SqlParameter[] sqlParameters) |
| | | { |
| | | return _db.Ado.ExecuteCommand(sql, sqlParameters); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åçSqlè¯å¥æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="sql"></param> |
| | | /// <param name="parameters"></param> |
| | | /// <returns></returns> |
| | | public virtual DataTable QueryTable(string sql, SugarParameter[]? parameters = null) |
| | | { |
| | | return _db.Ado.GetDataTable(sql, parameters); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æ°æ®æå®æ°éçè¡ |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="top"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression, int top, string orderByFields) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(whereExpression != null, whereExpression).Take(top).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¡ä»¶æ¥è¯¢æå®æ°éçè¡ |
| | | /// </summary> |
| | | /// <param name="where"></param> |
| | | /// <param name="top"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TEntity> QueryData(string where, int top, string orderByFields) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(!string.IsNullOrEmpty(where), where).Take(top).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å页æ¥è¯¢ |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TEntity> QueryData(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pageSize, string orderByFields) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields) |
| | | .WhereIF(whereExpression != null, whereExpression).ToPageList(pageIndex, pageSize); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å页æ¥è¯¢ |
| | | /// </summary> |
| | | /// <param name="where"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TEntity> QueryData(string where, int pageIndex, int pageSize, string orderByFields) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields) |
| | | .WhereIF(!string.IsNullOrEmpty(where), where).ToPageList(pageIndex, pageSize); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å页æ¥è¯¢ |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | public virtual PageGridData<TEntity> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pageSize, string? orderByFields = null) |
| | | { |
| | | int totalCount = 0; |
| | | var list = _db.CopyNew().Queryable<TEntity>() |
| | | .OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields) |
| | | .WhereIF(whereExpression != null, whereExpression) |
| | | .ToPageList(pageIndex, pageSize, ref totalCount); |
| | | |
| | | return new PageGridData<TEntity> { Rows = list, Total = totalCount }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å页æ¥è¯¢ |
| | | /// </summary> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="orderBy"></param> |
| | | /// <returns></returns> |
| | | public virtual PageGridData<TEntity> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pageSize, Dictionary<string, OrderByType> orderBy) |
| | | { |
| | | List<OrderByModel> orderByModels = new List<OrderByModel>(); |
| | | foreach (var item in orderBy) |
| | | { |
| | | OrderByModel orderByModel = new OrderByModel() |
| | | { |
| | | FieldName = item.Key, |
| | | OrderByType = item.Value |
| | | }; |
| | | orderByModels.Add(orderByModel); |
| | | } |
| | | int totalCount = 0; |
| | | List<TEntity> list = _db.CopyNew().Queryable<TEntity>() |
| | | .OrderBy(orderByModels) |
| | | .WhereIF(whereExpression != null, whereExpression) |
| | | .ToPageList(pageIndex, pageSize, ref totalCount); |
| | | |
| | | return new PageGridData<TEntity>(totalCount, list); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å页æ¥è¯¢ |
| | | /// </summary> |
| | | /// <param name="where"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | public virtual PageGridData<TEntity> QueryPage(string where, int pageIndex, int pageSize, Dictionary<string, OrderByType> orderBy) |
| | | { |
| | | List<OrderByModel> orderByModels = new List<OrderByModel>(); |
| | | foreach (var item in orderBy) |
| | | { |
| | | OrderByModel orderByModel = new OrderByModel() |
| | | { |
| | | FieldName = item.Key, |
| | | OrderByType = item.Value |
| | | }; |
| | | orderByModels.Add(orderByModel); |
| | | } |
| | | int totalCount = 0; |
| | | List<TEntity> list = _db.CopyNew().Queryable<TEntity>() |
| | | .WhereIF(!string.IsNullOrEmpty(where), where).OrderBy(orderByModels).ToPageList(pageIndex, pageSize, ref totalCount); |
| | | |
| | | return new PageGridData<TEntity>(totalCount, list); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¸¤è¡¨èæ¥ |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <typeparam name="T2"></typeparam> |
| | | /// <typeparam name="TResult"></typeparam> |
| | | /// <param name="joinExpression"></param> |
| | | /// <param name="selectExpression"></param> |
| | | /// <param name="whereExpression"></param> |
| | | /// <returns></returns> |
| | | public virtual List<TResult> QueryTabs<T, T2, TResult>( |
| | | Expression<Func<T, T2, object[]>> joinExpression, |
| | | Expression<Func<T, T2, TResult>> selectExpression, |
| | | Expression<Func<T,T2, bool>> whereExpressionT1, |
| | | Expression<Func<TResult, bool>> whereExpression) |
| | | { |
| | | List<TResult> list = _db.CopyNew().Queryable(joinExpression).WhereIF(whereExpressionT1 != null, whereExpressionT1) |
| | | .Select(selectExpression) |
| | | .WhereIF(whereExpression != null, whereExpression).ToList(); |
| | | return list; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¸¤è¡¨èæ¥-å页 |
| | | /// </summary> |
| | | /// <typeparam name="T1"></typeparam> |
| | | /// <typeparam name="T2"></typeparam> |
| | | /// <typeparam name="TResult"></typeparam> |
| | | /// <param name="joinExpression"></param> |
| | | /// <param name="selectExpression"></param> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="orderByFields"></param> |
| | | public virtual PageGridData<TResult> QueryTabsPage<T1, T2, TResult>(Expression<Func<T1, T2, object[]>> joinExpression, Expression<Func<T1, T2, TResult>> selectExpression, Expression<Func<TResult, bool>> whereExpression, int pageIndex, int pageSize, string? orderByFields = null) |
| | | { |
| | | int totalCount = 0; |
| | | List<TResult> list = _db.CopyNew().Queryable(joinExpression) |
| | | .Select(selectExpression) |
| | | .OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields) |
| | | .WhereIF(whereExpression != null, whereExpression) |
| | | .ToPageList(pageIndex, pageSize, ref totalCount); |
| | | return new PageGridData<TResult>(totalCount, list); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 两表èåæ¥è¯¢-å页-åç» |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <typeparam name="T2"></typeparam> |
| | | /// <typeparam name="TResult"></typeparam> |
| | | /// <param name="joinExpression"></param> |
| | | /// <param name="selectExpression"></param> |
| | | /// <param name="whereExpression"></param> |
| | | /// <param name="groupExpression"></param> |
| | | /// <param name="pageIndex"></param> |
| | | /// <param name="pageSize"></param> |
| | | /// <param name="orderByFields"></param> |
| | | /// <returns></returns> |
| | | public virtual PageGridData<TResult> QueryTabsPage<T1, T2, TResult>(Expression<Func<T1, T2, object[]>> joinExpression, Expression<Func<T1, T2, TResult>> selectExpression, Expression<Func<TResult, bool>> whereExpression, Expression<Func<T1, object>> groupExpression, int pageIndex, int pageSize, string? orderByFields = null) |
| | | { |
| | | int totalCount = 0; |
| | | List<TResult> list = _db.CopyNew().Queryable(joinExpression).GroupBy(groupExpression) |
| | | .Select(selectExpression) |
| | | .OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields) |
| | | .WhereIF(whereExpression != null, whereExpression) |
| | | .ToPageList(pageIndex, pageSize, ref totalCount); |
| | | return new PageGridData<TResult>(totalCount, list); |
| | | } |
| | | |
| | | public Task<TEntity> QureyDataByIdAsync(object id) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().In(id).SingleAsync(); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QureyDataByIdsAsync(object[] lstIds) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().In(lstIds).ToListAsync(); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QureyDataByIdsAsync(List<object> lstIds) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().In(lstIds).ToListAsync(); |
| | | } |
| | | |
| | | public Task<int> AddDataAsync(TEntity entity) |
| | | { |
| | | IInsertable<TEntity> insert = _db.CopyNew().Insertable(entity); |
| | | return insert.ExecuteReturnIdentityAsync(); |
| | | } |
| | | |
| | | public Task<int> AddDataAsync(List<TEntity> listEntity) |
| | | { |
| | | IInsertable<TEntity> insert = _db.CopyNew().Insertable(listEntity); |
| | | return insert.ExecuteReturnIdentityAsync(); |
| | | } |
| | | |
| | | public Task<bool> DeleteDataByIdAsync(object id) |
| | | { |
| | | return _db.CopyNew().Deleteable<TEntity>().In(id).ExecuteCommandHasChangeAsync(); |
| | | } |
| | | |
| | | public Task<bool> DeleteDataByIdsAsync(object[] ids) |
| | | { |
| | | return _db.CopyNew().Deleteable<TEntity>().In(ids).ExecuteCommandHasChangeAsync(); |
| | | } |
| | | |
| | | public Task<bool> DeleteDataAsync(TEntity entity) |
| | | { |
| | | return _db.CopyNew().Deleteable(entity).ExecuteCommandHasChangeAsync(); |
| | | } |
| | | |
| | | public Task<bool> DeleteDataAsync(List<TEntity> listEntity) |
| | | { |
| | | return _db.CopyNew().Deleteable(listEntity).ExecuteCommandHasChangeAsync(); |
| | | } |
| | | |
| | | public Task<bool> UpdateDataAsync(TEntity entity) |
| | | { |
| | | return _db.CopyNew().Updateable(entity).ExecuteCommandHasChangeAsync(); |
| | | } |
| | | |
| | | public Task<bool> UpdateDataAsync(List<TEntity> listEntity) |
| | | { |
| | | return _db.CopyNew().Updateable(listEntity).ExecuteCommandHasChangeAsync(); |
| | | } |
| | | |
| | | public Task<bool> UpdateDataAsync(TEntity entity, List<string> lstColumns, List<string>? lstIgnoreColumns = null) |
| | | { |
| | | IUpdateable<TEntity> update = _db.CopyNew().Updateable(entity); |
| | | |
| | | if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0) |
| | | { |
| | | update = update.IgnoreColumns(lstIgnoreColumns.ToArray()); |
| | | } |
| | | |
| | | if (lstColumns != null && lstColumns.Count > 0) |
| | | { |
| | | update = update.UpdateColumns(lstColumns.ToArray()); |
| | | } |
| | | |
| | | return update.ExecuteCommandHasChangeAsync(); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QueryDataAsync() |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().ToListAsync(); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QueryDataAsync(string where) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(!string.IsNullOrEmpty(where), where).ToListAsync(); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QueryDataAsync(Expression<Func<TEntity, bool>> whereExpression) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).ToListAsync(); |
| | | } |
| | | |
| | | public Task<TEntity> QueryFirstAsync(Expression<Func<TEntity, bool>> whereExpression) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).FirstAsync(); |
| | | } |
| | | |
| | | public Task<TResult> QueryFirstAsync<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> expression) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).Select(expression).FirstAsync(); |
| | | } |
| | | |
| | | public TResult QueryFirst<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> expression, Dictionary<string, OrderByType> orderBy) |
| | | { |
| | | List<OrderByModel> orderByModels = new List<OrderByModel>(); |
| | | foreach (var item in orderBy) |
| | | { |
| | | OrderByModel orderByModel = new OrderByModel() |
| | | { |
| | | FieldName = item.Key, |
| | | OrderByType = item.Value |
| | | }; |
| | | orderByModels.Add(orderByModel); |
| | | } |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderBy(orderByModels).Select(expression).First(); |
| | | } |
| | | |
| | | public Task<TResult> QueryFirstAsync<TResult>(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, TResult>> expression, Dictionary<string, OrderByType> orderBy) |
| | | { |
| | | List<OrderByModel> orderByModels = new List<OrderByModel>(); |
| | | foreach (var item in orderBy) |
| | | { |
| | | OrderByModel orderByModel = new OrderByModel() |
| | | { |
| | | FieldName = item.Key, |
| | | OrderByType = item.Value |
| | | }; |
| | | orderByModels.Add(orderByModel); |
| | | } |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderBy(orderByModels).Select(expression).FirstAsync(); |
| | | } |
| | | |
| | | public TEntity QueryFirst(Expression<Func<TEntity, bool>> whereExpression, Dictionary<string, OrderByType> orderBy) |
| | | { |
| | | List<OrderByModel> orderByModels = new List<OrderByModel>(); |
| | | foreach (var item in orderBy) |
| | | { |
| | | OrderByModel orderByModel = new OrderByModel() |
| | | { |
| | | FieldName = item.Key, |
| | | OrderByType = item.Value |
| | | }; |
| | | orderByModels.Add(orderByModel); |
| | | } |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderBy(orderByModels).First(); |
| | | } |
| | | |
| | | public Task<TEntity> QueryFirstAsync(Expression<Func<TEntity, bool>> whereExpression, Dictionary<string, OrderByType> orderBy) |
| | | { |
| | | List<OrderByModel> orderByModels = new List<OrderByModel>(); |
| | | foreach (var item in orderBy) |
| | | { |
| | | OrderByModel orderByModel = new OrderByModel() |
| | | { |
| | | FieldName = item.Key, |
| | | OrderByType = item.Value |
| | | }; |
| | | orderByModels.Add(orderByModel); |
| | | } |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderBy(orderByModels).FirstAsync(); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QueryDataAsync(Expression<Func<TEntity, bool>> whereExpression, string orderByFields) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(whereExpression != null, whereExpression).OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).ToListAsync(); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QueryDataAsync(string where, Dictionary<string, OrderByType> orderBy) |
| | | { |
| | | List<OrderByModel> orderByModels = new List<OrderByModel>(); |
| | | foreach (var item in orderBy) |
| | | { |
| | | OrderByModel orderByModel = new OrderByModel() |
| | | { |
| | | FieldName = item.Key, |
| | | OrderByType = item.Value |
| | | }; |
| | | orderByModels.Add(orderByModel); |
| | | } |
| | | return _db.CopyNew().Queryable<TEntity>().WhereIF(!string.IsNullOrEmpty(where), where).OrderBy(orderByModels).ToListAsync(); |
| | | } |
| | | |
| | | public Task<List<TResult>> QueryDataAsync<TResult>(Expression<Func<TEntity, TResult>> expression) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().Select(expression).ToListAsync(); |
| | | } |
| | | |
| | | public Task<List<TResult>> QueryDataAsync<TResult>(Expression<Func<TEntity, TResult>> expression, Expression<Func<TEntity, bool>> whereExpression, string orderByFields) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(whereExpression != null, whereExpression).Select(expression).ToListAsync(); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QueryDataAsync(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToListAsync(); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QueryDataAsync(string where, string orderByFields) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(!string.IsNullOrEmpty(where), where).ToListAsync(); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QueryDataBySqlAsync(string sql, SugarParameter[]? parameters = null) |
| | | { |
| | | return _db.Ado.SqlQueryAsync<TEntity>(sql, parameters); |
| | | } |
| | | |
| | | public Task<List<dynamic>> QueryDynamicDataBySqlAsync(string sql, SugarParameter[]? parameters = null) |
| | | { |
| | | return _db.Ado.SqlQueryAsync<dynamic>(sql, parameters); |
| | | } |
| | | |
| | | public Task<List<object>> QueryObjectDataBySqlAsync(string sql, SugarParameter[]? parameters = null) |
| | | { |
| | | return _db.Ado.SqlQueryAsync<object>(sql, parameters); |
| | | } |
| | | |
| | | public Task<int> ExecuteSqlCommandAsync(string sql, params SqlParameter[] sqlParameters) |
| | | { |
| | | return _db.Ado.ExecuteCommandAsync(sql, sqlParameters); |
| | | } |
| | | |
| | | public Task<DataTable> QueryTableAsync(string sql, SugarParameter[]? parameters = null) |
| | | { |
| | | return _db.Ado.GetDataTableAsync(sql, parameters); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QueryDataAsync(Expression<Func<TEntity, bool>> whereExpression, int top, string orderByFields) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(whereExpression != null, whereExpression).Take(top).ToListAsync(); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QueryDataAsync(string where, int top, string orderByFields) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields).WhereIF(!string.IsNullOrEmpty(where), where).Take(top).ToListAsync(); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QueryDataAsync(Expression<Func<TEntity, bool>> whereExpression, int pageIndex, int pageSize, string orderByFields) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields) |
| | | .WhereIF(whereExpression != null, whereExpression).ToPageListAsync(pageIndex, pageSize); |
| | | } |
| | | |
| | | public Task<List<TEntity>> QueryDataAsync(string where, int pageIndex, int pageSize, string orderByFields) |
| | | { |
| | | return _db.CopyNew().Queryable<TEntity>().OrderByIF(!string.IsNullOrEmpty(orderByFields), orderByFields) |
| | | .WhereIF(!string.IsNullOrEmpty(where), where).ToPageListAsync(pageIndex, pageSize); |
| | | } |
| | | |
| | | public Task<List<TResult>> QueryTabsAsync<T, T2, TResult>(Expression<Func<T, T2, object[]>> joinExpression, Expression<Func<T, T2, TResult>> selectExpression, Expression<Func<TResult, bool>> whereExpression) |
| | | { |
| | | return _db.CopyNew().Queryable(joinExpression) |
| | | .Select(selectExpression) |
| | | .WhereIF(whereExpression != null, whereExpression).ToListAsync(); |
| | | } |
| | | |
| | | //List<TResult> QueryMuch<T, T2, T3, TResult>( |
| | | // Expression<Func<T, T2, T3, object[]>> joinExpression, |
| | | // Expression<Func<T, T2, T3, TResult>> selectExpression, |
| | | // Expression<Func<T, T2, T3, bool>> whereLambda = null) where T : class, new(){throw new NotImplementedException();} |
| | | //Task<PageModel<TEntity>> QueryPage(PaginationModel pagination){throw new NotImplementedException();} |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.BaseRepository |
| | | { |
| | | public interface IUnitOfWorkManage |
| | | { |
| | | SqlSugarScope GetDbClient(); |
| | | int TranCount { get; } |
| | | |
| | | UnitOfWork CreateUnitOfWork(); |
| | | |
| | | void BeginTran(); |
| | | void BeginTran(MethodInfo method); |
| | | void CommitTran(); |
| | | void CommitTran(MethodInfo method); |
| | | void RollbackTran(); |
| | | void RollbackTran(MethodInfo method); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.Logging; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.BaseRepository |
| | | { |
| | | public class UnitOfWork : IDisposable |
| | | { |
| | | public ILogger Logger { get; set; } |
| | | public ISqlSugarClient Db { get; internal set; } |
| | | |
| | | public ITenant Tenant { get; internal set; } |
| | | |
| | | public bool IsTran { get; internal set; } |
| | | |
| | | public bool IsCommit { get; internal set; } |
| | | |
| | | public bool IsClose { get; internal set; } |
| | | |
| | | public void Dispose() |
| | | { |
| | | if (IsTran && !IsCommit) |
| | | { |
| | | Logger.LogDebug("UnitOfWork RollbackTran"); |
| | | this.Tenant.RollbackTran(); |
| | | } |
| | | |
| | | if (this.Db.Ado.Transaction != null || this.IsClose) |
| | | return; |
| | | this.Db.Close(); |
| | | } |
| | | |
| | | public bool Commit() |
| | | { |
| | | if (this.IsTran && !this.IsCommit) |
| | | { |
| | | Logger.LogDebug("UnitOfWork CommitTran"); |
| | | this.Tenant.CommitTran(); |
| | | this.IsCommit = true; |
| | | } |
| | | |
| | | if (this.Db.Ado.Transaction == null && !this.IsClose) |
| | | { |
| | | this.Db.Close(); |
| | | this.IsClose = true; |
| | | } |
| | | |
| | | return this.IsCommit; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.Logging; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Concurrent; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | |
| | | namespace WIDESEAWCS_Core.BaseRepository |
| | | { |
| | | public class UnitOfWorkManage : IUnitOfWorkManage |
| | | { |
| | | private readonly ILogger<UnitOfWorkManage> _logger; |
| | | private readonly ISqlSugarClient _sqlSugarClient; |
| | | |
| | | private int _tranCount { get; set; } |
| | | public int TranCount => _tranCount; |
| | | public readonly ConcurrentStack<string> TranStack = new(); |
| | | |
| | | public UnitOfWorkManage(ISqlSugarClient sqlSugarClient, ILogger<UnitOfWorkManage> logger) |
| | | { |
| | | _sqlSugarClient = sqlSugarClient; |
| | | _logger = logger; |
| | | _tranCount = 0; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åDBï¼ä¿è¯å¯ä¸æ§ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public SqlSugarScope GetDbClient() |
| | | { |
| | | // å¿
é¡»è¦asï¼åè¾¹ä¼ç¨å°åæ¢æ°æ®åºæä½ |
| | | return _sqlSugarClient as SqlSugarScope; |
| | | } |
| | | |
| | | |
| | | public UnitOfWork CreateUnitOfWork() |
| | | { |
| | | UnitOfWork uow = new UnitOfWork(); |
| | | uow.Logger = _logger; |
| | | uow.Db = _sqlSugarClient; |
| | | uow.Tenant = (ITenant)_sqlSugarClient; |
| | | uow.IsTran = true; |
| | | |
| | | uow.Db.Open(); |
| | | uow.Tenant.BeginTran(); |
| | | |
| | | _logger.LogDebug("UnitOfWork Begin"); |
| | | return uow; |
| | | } |
| | | |
| | | public void BeginTran() |
| | | { |
| | | lock (this) |
| | | { |
| | | _tranCount++; |
| | | GetDbClient().BeginTran(); |
| | | } |
| | | } |
| | | |
| | | public void BeginTran(MethodInfo method) |
| | | { |
| | | lock (this) |
| | | { |
| | | GetDbClient().BeginTran(); |
| | | TranStack.Push(method.GetFullName()); |
| | | _tranCount = TranStack.Count; |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent BeginTran(Func<WebResponseContent> func) |
| | | { |
| | | lock (this) |
| | | { |
| | | BeginTran(); |
| | | try |
| | | { |
| | | WebResponseContent content = func(); |
| | | if (content.Status) |
| | | { |
| | | CommitTran(); |
| | | } |
| | | else |
| | | { |
| | | RollbackTran(); |
| | | } |
| | | return content; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void CommitTran() |
| | | { |
| | | lock (this) |
| | | { |
| | | _tranCount--; |
| | | if (_tranCount == 0) |
| | | { |
| | | try |
| | | { |
| | | GetDbClient().CommitTran(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine(ex.Message); |
| | | GetDbClient().RollbackTran(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void CommitTran(MethodInfo method) |
| | | { |
| | | lock (this) |
| | | { |
| | | string result = ""; |
| | | while (!TranStack.IsEmpty && !TranStack.TryPeek(out result)) |
| | | { |
| | | Thread.Sleep(1); |
| | | } |
| | | |
| | | |
| | | if (result == method.GetFullName()) |
| | | { |
| | | try |
| | | { |
| | | GetDbClient().CommitTran(); |
| | | |
| | | _logger.LogDebug($"Commit Transaction"); |
| | | Console.WriteLine($"Commit Transaction"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine(ex.Message); |
| | | GetDbClient().RollbackTran(); |
| | | _logger.LogDebug($"Commit Error , Rollback Transaction"); |
| | | } |
| | | finally |
| | | { |
| | | while (!TranStack.TryPop(out _)) |
| | | { |
| | | Thread.Sleep(1); |
| | | } |
| | | |
| | | _tranCount = TranStack.Count; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void RollbackTran() |
| | | { |
| | | lock (this) |
| | | { |
| | | _tranCount--; |
| | | GetDbClient().RollbackTran(); |
| | | } |
| | | } |
| | | |
| | | public void RollbackTran(MethodInfo method) |
| | | { |
| | | lock (this) |
| | | { |
| | | string result = ""; |
| | | while (!TranStack.IsEmpty && !TranStack.TryPeek(out result)) |
| | | { |
| | | Thread.Sleep(1); |
| | | } |
| | | |
| | | if (result == method.GetFullName()) |
| | | { |
| | | GetDbClient().RollbackTran(); |
| | | _logger.LogDebug($"Rollback Transaction"); |
| | | Console.WriteLine($"Rollback Transaction"); |
| | | while (!TranStack.TryPop(out _)) |
| | | { |
| | | Thread.Sleep(1); |
| | | } |
| | | |
| | | _tranCount = TranStack.Count; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.BaseServices |
| | | { |
| | | public interface IService<TEntity>: IDependency where TEntity : class |
| | | { |
| | | ISqlSugarClient Db { get; } |
| | | |
| | | /// <summary> |
| | | /// å页æ¥è¯¢æ°æ® |
| | | /// </summary> |
| | | /// <param name="options"></param> |
| | | /// <returns></returns> |
| | | PageGridData<TEntity> GetPageData(PageDataOptions options); |
| | | |
| | | object GetDetailPage(PageDataOptions pageData); |
| | | |
| | | /// <summary> |
| | | /// æ·»å æ°æ® |
| | | /// </summary> |
| | | /// <param name="entity">å个å®ä½</param> |
| | | /// <returns></returns> |
| | | WebResponseContent AddData(TEntity entity); |
| | | |
| | | /// <summary> |
| | | /// æ·»å æ°æ® |
| | | /// </summary> |
| | | /// <param name="entities">å®ä½éå</param> |
| | | /// <returns></returns> |
| | | WebResponseContent AddData(List<TEntity> entities); |
| | | |
| | | /// <summary> |
| | | /// æ·»å æ°æ® |
| | | /// </summary> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | | WebResponseContent AddData(SaveModel saveModel); |
| | | |
| | | /// <summary> |
| | | /// ä¿®æ¹æ°æ® |
| | | /// </summary> |
| | | /// <param name="entity">å个å®ä½</param> |
| | | /// <returns></returns> |
| | | WebResponseContent UpdateData(TEntity entity); |
| | | |
| | | /// <summary> |
| | | /// ä¿®æ¹æ°æ® |
| | | /// </summary> |
| | | /// <param name="entities">å®ä½éå</param> |
| | | /// <returns></returns> |
| | | WebResponseContent UpdateData(List<TEntity> entities); |
| | | |
| | | /// <summary> |
| | | /// ä¿®æ¹æ°æ® |
| | | /// </summary> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | | WebResponseContent UpdateData(SaveModel saveModel); |
| | | |
| | | /// <summary> |
| | | /// å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="key">主é®</param> |
| | | /// <returns></returns> |
| | | WebResponseContent DeleteData(object key); |
| | | |
| | | /// <summary> |
| | | /// å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="keys">䏻鮿°ç»</param> |
| | | /// <returns></returns> |
| | | WebResponseContent DeleteData(object[] keys); |
| | | |
| | | /// <summary> |
| | | /// å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="entity">å个å®ä½</param> |
| | | /// <returns></returns> |
| | | WebResponseContent DeleteData(TEntity entity); |
| | | |
| | | /// <summary> |
| | | /// å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="entities">å®ä½éå</param> |
| | | /// <returns></returns> |
| | | WebResponseContent DeleteData(List<TEntity> entities); |
| | | |
| | | /// <summary> |
| | | /// å¯¼åºæ°æ® |
| | | /// </summary> |
| | | /// <param name="pageData"></param> |
| | | /// <returns></returns> |
| | | WebResponseContent Export(PageDataOptions pageData); |
| | | |
| | | /// <summary> |
| | | /// 导å
¥æ°æ® |
| | | /// </summary> |
| | | /// <param name="files"></param> |
| | | /// <returns></returns> |
| | | WebResponseContent Import(List<IFormFile> files); |
| | | |
| | | /// <summary> |
| | | /// ä¸ä¼ æä»¶ |
| | | /// </summary> |
| | | /// <param name="files"></param> |
| | | /// <returns></returns> |
| | | WebResponseContent Upload(List<IFormFile> files); |
| | | |
| | | /// <summary> |
| | | /// 模æ¿ä¸è½½ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | WebResponseContent DownLoadTemplate(); |
| | | |
| | | WebResponseContent ExportSeedData(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using Magicodes.ExporterAndImporter.Core.Models; |
| | | using Magicodes.ExporterAndImporter.Excel; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.AspNetCore.Mvc.RazorPages; |
| | | using Microsoft.Extensions.Options; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using SqlSugar; |
| | | using System.Drawing.Drawing2D; |
| | | using System.Dynamic; |
| | | using System.Linq.Expressions; |
| | | using System.Reflection; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.Utilities; |
| | | using static OfficeOpenXml.ExcelErrorValue; |
| | | |
| | | namespace WIDESEAWCS_Core.BaseServices |
| | | { |
| | | public class ServiceBase<TEntity, TRepository> : ServiceFunFilter<TEntity>, IService<TEntity> |
| | | where TEntity : class, new() |
| | | where TRepository : IRepository<TEntity> |
| | | |
| | | { |
| | | public ServiceBase(TRepository BaseDal) |
| | | { |
| | | this.BaseDal = BaseDal; |
| | | } |
| | | |
| | | public TRepository BaseDal { get; set; } //éè¿å¨åç±»çæé 彿°ä¸æ³¨å
¥ï¼è¿éæ¯åºç±»ï¼ä¸ç¨æé 彿° |
| | | |
| | | public ISqlSugarClient Db => BaseDal.Db; |
| | | |
| | | private PropertyInfo[] _propertyInfo { get; set; } = null; |
| | | private PropertyInfo[] TProperties |
| | | { |
| | | get |
| | | { |
| | | if (_propertyInfo != null) |
| | | { |
| | | return _propertyInfo; |
| | | } |
| | | _propertyInfo = typeof(TEntity).GetProperties(); |
| | | return _propertyInfo; |
| | | } |
| | | } |
| | | |
| | | public virtual PageGridData<TEntity> GetPageData(PageDataOptions options) |
| | | { |
| | | string wheres = ValidatePageOptions(options); |
| | | //è·åæåºå段 |
| | | Dictionary<string, OrderByType> orderbyDic = GetPageDataSort(options, TProperties); |
| | | |
| | | PageGridData<TEntity> pageGridData = new PageGridData<TEntity>(); |
| | | pageGridData = BaseDal.QueryPage(wheres, options.Page, options.Rows, orderbyDic); |
| | | |
| | | return pageGridData; |
| | | } |
| | | |
| | | |
| | | //protected string ValidatePageOptions(PageDataOptions options) |
| | | //{ |
| | | // options = options ?? new PageDataOptions(); |
| | | // string where = ""; |
| | | // List<SearchParameters> searchParametersList = new List<SearchParameters>(); |
| | | // if (options.Filter != null && options.Filter.Count > 0) |
| | | // { |
| | | // searchParametersList.AddRange(options.Filter); |
| | | // } |
| | | // else if (!string.IsNullOrEmpty(options.Wheres)) |
| | | // { |
| | | // try |
| | | // { |
| | | // searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>(); |
| | | // options.Filter = searchParametersList; |
| | | // } |
| | | // catch { } |
| | | // } |
| | | // QueryRelativeList?.Invoke(searchParametersList); |
| | | |
| | | // for (int i = 0; i < searchParametersList.Count; i++) |
| | | // { |
| | | // if (string.IsNullOrEmpty(searchParametersList[i].Value)) |
| | | // { |
| | | // continue; |
| | | // } |
| | | |
| | | // PropertyInfo property = TProperties.Where(c => c.Name.ToUpper() == searchParametersList[i].Name.ToUpper()).FirstOrDefault(); |
| | | |
| | | // if (property == null) continue; |
| | | |
| | | // List<(bool, string, object)> results = property.ValidationValueForDbType(searchParametersList[i].Value.Split(',')).ToList(); |
| | | // if (results == null || results.Count() == 0) |
| | | // { |
| | | // continue; |
| | | // } |
| | | // for (int j = 0; j < results.Count(); j++) |
| | | // { |
| | | // if (j == 0) |
| | | // { |
| | | // where += "("; |
| | | // } |
| | | // LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition(); |
| | | // if (expressionType == LinqExpressionType.Equal) |
| | | // { |
| | | // where += $"{searchParametersList[i].Name} like '%{results[j].Item3}%'"; |
| | | // } |
| | | // else |
| | | // { |
| | | // where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{results[j].Item3}'"; |
| | | // } |
| | | |
| | | // if (j == results.Count() - 1) |
| | | // { |
| | | // where += ")"; |
| | | // } |
| | | // else |
| | | // { |
| | | // where += " or "; |
| | | // } |
| | | // } |
| | | // if (i < searchParametersList.Count - 1) |
| | | // where += " and "; |
| | | // } |
| | | // return where; |
| | | //} |
| | | |
| | | protected string ValidatePageOptions(PageDataOptions options) |
| | | { |
| | | options = options ?? new PageDataOptions(); |
| | | string where = ""; |
| | | List<SearchParameters> searchParametersList = new List<SearchParameters>(); |
| | | if (options.Filter != null && options.Filter.Count > 0) |
| | | { |
| | | searchParametersList.AddRange(options.Filter); |
| | | } |
| | | else if (!string.IsNullOrEmpty(options.Wheres)) |
| | | { |
| | | try |
| | | { |
| | | searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>(); |
| | | options.Filter = searchParametersList; |
| | | } |
| | | catch { } |
| | | } |
| | | QueryRelativeList?.Invoke(searchParametersList); |
| | | |
| | | for (int i = 0; i < searchParametersList.Count; i++) |
| | | { |
| | | if (string.IsNullOrEmpty(searchParametersList[i].Value)) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | PropertyInfo property = TProperties.Where(c => c.Name.ToUpper() == searchParametersList[i].Name.ToUpper()).FirstOrDefault(); |
| | | |
| | | if (property == null) continue; |
| | | |
| | | (bool, string, object) result = property.ValidationVal(searchParametersList[i].Value); |
| | | if (!result.Item1) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition(); |
| | | if (expressionType == LinqExpressionType.Equal) |
| | | { |
| | | if (string.IsNullOrEmpty(where)) |
| | | { |
| | | // é对å符串类åçåæ®µä½¿ç¨æ¨¡ç³æ¥è¯¢ |
| | | //where += $"{searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'"; |
| | | if (searchParametersList[i].Value.ToLower() == "true" || searchParametersList[i].Value.ToLower() == "false") |
| | | { |
| | | where += $" {searchParametersList[i].Name} = '{searchParametersList[i].Value.ToLower()}'"; |
| | | } |
| | | else |
| | | { |
| | | where += $"{searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // é对å¸å°ç±»ååæ®µè¿è¡ç²¾ç¡®æ¥è¯¢ |
| | | if (searchParametersList[i].Value.ToLower() == "true" || searchParametersList[i].Value.ToLower() == "false") |
| | | { |
| | | where += $" and {searchParametersList[i].Name} = '{searchParametersList[i].Value.ToLower()}'"; |
| | | } |
| | | else |
| | | { |
| | | where += $" and {searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'"; |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (string.IsNullOrEmpty(where)) |
| | | where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{searchParametersList[i].Value}'"; |
| | | else |
| | | where += $" and {searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{searchParametersList[i].Value}'"; |
| | | } |
| | | } |
| | | return where; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åæåºå段 |
| | | /// </summary> |
| | | /// <param name="pageData"></param> |
| | | /// <param name="propertyInfo"></param> |
| | | /// <returns></returns> |
| | | private Dictionary<string, OrderByType> GetPageDataSort(PageDataOptions pageData, PropertyInfo[] propertyInfo) |
| | | { |
| | | if (!string.IsNullOrEmpty(pageData.Sort)) |
| | | { |
| | | if (pageData.Sort.Contains(",")) |
| | | { |
| | | List<string> sortArr = pageData.Sort.Split(",").Where(x => propertyInfo.Any(p => p.Name == x)).ToList(); |
| | | Dictionary<string, OrderByType> sortDic = new Dictionary<string, OrderByType>(); |
| | | foreach (var item in sortArr) |
| | | { |
| | | sortDic[item] = pageData.Order?.ToLower() == OrderByType.Asc.ToString() ? OrderByType.Asc : OrderByType.Desc; |
| | | } |
| | | return sortDic; |
| | | } |
| | | else if (propertyInfo.Any(x => x.Name == pageData.Sort.FirstLetterToLower() || x.Name == pageData.Sort.FirstLetterToUpper())) |
| | | { |
| | | return new Dictionary<string, OrderByType> { |
| | | { |
| | | pageData.Sort,pageData.Order?.ToLower() == OrderByType.Asc.ToString() ? OrderByType.Asc : OrderByType.Desc |
| | | } }; |
| | | } |
| | | } |
| | | return new Dictionary<string, OrderByType> { { "CreateDate", pageData.Order?.ToLower() == OrderByType.Asc.ToString() ? OrderByType.Asc : OrderByType.Desc } }; |
| | | } |
| | | |
| | | public virtual object GetDetailPage(PageDataOptions pageData) |
| | | { |
| | | Type t = typeof(TEntity); |
| | | |
| | | if (pageData.Value == null) return new PageGridData<object>(total: 0, null); |
| | | string keyName = t.GetKeyName(); |
| | | ////çææ¥è¯¢æ¡ä»¶ |
| | | //Expression<Func<TEntity, bool>> whereExpression = keyName.CreateExpression<TEntity>(pageData.Value, LinqExpressionType.Equal); |
| | | int totalCount = 0; |
| | | PropertyInfo propertyInfo = t.GetProperties().FirstOrDefault(x => x.GetCustomAttribute<Navigate>() != null); |
| | | if (propertyInfo != null) |
| | | { |
| | | Type detailType = propertyInfo.PropertyType.GetGenericArguments()[0]; |
| | | Navigate navigate = propertyInfo.GetCustomAttribute<Navigate>(); |
| | | List<ExpandoObject> list = BaseDal.Db.Queryable(detailType.Name, "detail").Where(navigate.GetName(), "=", pageData.Value).ToPageList(pageData.Page, pageData.Rows, ref totalCount); |
| | | return new PageGridData<ExpandoObject>(totalCount, list); |
| | | } |
| | | return new PageGridData<object>(total: 0, null); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ·»å æ°æ® |
| | | /// </summary> |
| | | /// <param name="entity">å个å®ä½</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent AddData(TEntity entity) |
| | | { |
| | | try |
| | | { |
| | | return BaseDal.AddData(entity) > 0 ? WebResponseContent.Instance.OK() : WebResponseContent.Instance.Error(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ·»å æ°æ® |
| | | /// </summary> |
| | | /// <param name="entities">å®ä½éå</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent AddData(List<TEntity> entities) |
| | | { |
| | | try |
| | | { |
| | | return BaseDal.AddData(entities) > 0 ? WebResponseContent.Instance.OK() : WebResponseContent.Instance.Error(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ·»å æ°æ® |
| | | /// </summary> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent AddData(SaveModel saveModel) |
| | | { |
| | | try |
| | | { |
| | | if (saveModel == null || saveModel.MainData == null || saveModel.MainData.Count == 0)//夿忰æ¯å¦ä¼ å
¥ |
| | | { |
| | | return WebResponseContent.Instance.Error("ä¼ åé误,åæ°ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | var x = saveModel.MainData; |
| | | |
| | | string validResult = typeof(TEntity).ValidateDicInEntity(x, true, TProperties); |
| | | |
| | | if (!string.IsNullOrEmpty(validResult)) |
| | | { |
| | | return WebResponseContent.Instance.Error(validResult); |
| | | } |
| | | |
| | | PropertyInfo keyPro = typeof(TEntity).GetKeyProperty(); |
| | | if (keyPro == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("请å
设置主é®"); |
| | | } |
| | | if (keyPro.PropertyType == typeof(Guid)) |
| | | { |
| | | saveModel.MainData.Add(keyPro.Name, Guid.NewGuid()); |
| | | } |
| | | else if (keyPro.PropertyType == typeof(int) || keyPro.PropertyType == typeof(long)) |
| | | { |
| | | SugarColumn sugarColumn = keyPro.GetCustomAttribute<SugarColumn>(); |
| | | if (sugarColumn.IsIdentity) |
| | | { |
| | | saveModel.MainData.Remove(keyPro.Name.FirstLetterToUpper()); |
| | | saveModel.MainData.Remove(keyPro.Name.FirstLetterToLower()); |
| | | } |
| | | } |
| | | TEntity entity = saveModel.MainData.DicToModel<TEntity>(); |
| | | if (saveModel.DetailData == null || saveModel.DetailData.Count == 0) |
| | | { |
| | | BaseDal.AddData(entity); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | if (typeof(TEntity).GetNavigatePro() == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªé
置导èªå±æ§"); |
| | | } |
| | | |
| | | Type detailType = typeof(TEntity).GetDetailType(); |
| | | MethodInfo? methodInfo = GetType().GetMethod(nameof(AddDataIncludesDetail)); |
| | | methodInfo = methodInfo?.MakeGenericMethod(new Type[] { detailType }); |
| | | object? obj = methodInfo?.Invoke(this, new object[] { entity, detailType, saveModel.DetailData }); |
| | | return obj as WebResponseContent; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent AddDataIncludesDetail<TDetail>(TEntity entity, Type detailType, List<Dictionary<string, object>> detailDics) where TDetail : class, new() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string name = typeof(TEntity).GetMainIdByDetail(); |
| | | string reslut = detailType.ValidateDicInEntity(detailDics, true, new string[] { name }); |
| | | if (reslut != string.Empty) |
| | | return WebResponseContent.Instance.Error(reslut); |
| | | |
| | | List<TDetail> list = detailDics.DicToIEnumerable<TDetail>(); |
| | | |
| | | ((SqlSugarScope)BaseDal.Db).BeginTran(); |
| | | |
| | | int id = BaseDal.Db.Insertable(entity).ExecuteReturnIdentity(); |
| | | |
| | | for (int i = 0; i < list.Count; i++) |
| | | { |
| | | TDetail detail = list[i]; |
| | | typeof(TDetail).SetDetailId(detail, id, name); |
| | | } |
| | | |
| | | BaseDal.Db.Insertable(list).ExecuteCommand(); |
| | | |
| | | ((SqlSugarScope)BaseDal.Db).CommitTran(); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ((SqlSugarScope)BaseDal.Db).RollbackTran(); |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¿®æ¹æ°æ® |
| | | /// </summary> |
| | | /// <param name="entity">å个å®ä½</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent UpdateData(TEntity entity) |
| | | { |
| | | try |
| | | { |
| | | return BaseDal.UpdateData(entity) ? WebResponseContent.Instance.OK() : WebResponseContent.Instance.Error(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¿®æ¹æ°æ® |
| | | /// </summary> |
| | | /// <param name="entities">å®ä½éå</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent UpdateData(List<TEntity> entities) |
| | | { |
| | | try |
| | | { |
| | | return BaseDal.UpdateData(entities) ? WebResponseContent.Instance.OK() : WebResponseContent.Instance.Error(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¿®æ¹æ°æ® |
| | | /// </summary> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent UpdateData(SaveModel saveModel) |
| | | { |
| | | try |
| | | { |
| | | List<string>? list = UpdateIgnoreColOnExecute?.Invoke(saveModel); |
| | | if (saveModel == null || saveModel.MainData == null || saveModel.MainData.Count == 0)//夿忰æ¯å¦ä¼ å
¥ |
| | | { |
| | | return WebResponseContent.Instance.Error("ä¼ åé误,åæ°ä¸è½ä¸ºç©º"); |
| | | } |
| | | string validResult = typeof(TEntity).ValidateDicInEntity(saveModel.MainData, false, TProperties, list?.ToArray()); |
| | | |
| | | if (!string.IsNullOrEmpty(validResult)) |
| | | { |
| | | return WebResponseContent.Instance.Error(validResult); |
| | | } |
| | | |
| | | PropertyInfo keyPro = typeof(TEntity).GetKeyProperty(); |
| | | if (keyPro == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("请å
设置主é®"); |
| | | } |
| | | |
| | | TEntity entity = saveModel.MainData.DicToModel<TEntity>(); |
| | | |
| | | //List<string> listCol = new List<string>(); |
| | | //foreach (var item in saveModel.MainData) |
| | | //{ |
| | | // PropertyInfo propertyInfo = typeof(TEntity).GetProperty(item.Key); |
| | | // if (propertyInfo == null) |
| | | // { |
| | | // propertyInfo = typeof(TEntity).GetProperty(item.Key.FirstLetterToLower()); |
| | | // if (propertyInfo == null) |
| | | // { |
| | | // propertyInfo = typeof(TEntity).GetProperty(item.Key.FirstLetterToUpper()); |
| | | // } |
| | | // } |
| | | |
| | | // listCol.Add(propertyInfo?.Name); |
| | | //} |
| | | |
| | | if (saveModel.DetailData == null || saveModel.DetailData.Count == 0) |
| | | { |
| | | //if (list != null) |
| | | // listCol = listCol.Where(x => !list.Contains(x)).ToList(); |
| | | bool result = BaseDal.UpdateData(entity); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | if (typeof(TEntity).GetNavigatePro() == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªé
置导èªå±æ§"); |
| | | } |
| | | |
| | | Type detailType = typeof(TEntity).GetDetailType(); |
| | | MethodInfo? methodInfo = GetType().GetMethod(nameof(UpdateDataInculdesDetail)); |
| | | methodInfo = methodInfo?.MakeGenericMethod(new Type[] { detailType }); |
| | | object? obj = methodInfo?.Invoke(this, new object[] { entity, detailType, saveModel.DetailData, saveModel.DelKeys }); |
| | | return obj as WebResponseContent; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent UpdateDataInculdesDetail<TDetail>(TEntity entity, Type detailType, List<Dictionary<string, object>> detailDics, List<object> delKeys) where TDetail : class, new() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string name = typeof(TEntity).GetMainIdByDetail(); |
| | | string reslut = detailType.ValidateDicInEntity(detailDics, true, new string[] { name }); |
| | | if (reslut != string.Empty) |
| | | return WebResponseContent.Instance.Error(reslut); |
| | | |
| | | List<TDetail> list = detailDics.DicToIEnumerable<TDetail>(); |
| | | |
| | | List<object> dynamicDelKeys = new List<object>(); |
| | | if (delKeys != null) |
| | | { |
| | | for (int i = 0; i < delKeys.Count; i++) |
| | | { |
| | | dynamicDelKeys.Add(delKeys[i]); |
| | | } |
| | | } |
| | | |
| | | List<TDetail> updateRows = new List<TDetail>(); |
| | | List<TDetail> addRows = new List<TDetail>(); |
| | | |
| | | for (int i = 0; i < list.Count; i++) |
| | | { |
| | | object detailId = typeof(TDetail).GetPropertyValue(list[i], typeof(TDetail).GetKeyName()); |
| | | if (detailId != null) |
| | | { |
| | | if (detailId.ToString() != "0") |
| | | { |
| | | updateRows.Add(list[i]); |
| | | } |
| | | else |
| | | { |
| | | addRows.Add(list[i]); |
| | | } |
| | | } |
| | | } |
| | | |
| | | object mainId = typeof(TEntity).GetPropertyValue(entity, typeof(TEntity).GetKeyName()); |
| | | if (mainId != null) |
| | | { |
| | | ((SqlSugarScope)BaseDal.Db).BeginTran(); |
| | | |
| | | if (dynamicDelKeys.Count > 0) |
| | | BaseDal.Db.Deleteable<object>().AS(detailType.Name).Where($"{detailType.GetKeyName()} in (@id)", new { id = dynamicDelKeys.ToArray() }).ExecuteCommandHasChange(); |
| | | |
| | | BaseDal.Db.Updateable(entity).ExecuteCommandHasChange(); |
| | | |
| | | BaseDal.Db.Updateable(updateRows).ExecuteCommand(); |
| | | |
| | | for (int i = 0; i < addRows.Count; i++) |
| | | { |
| | | TDetail detail = addRows[i]; |
| | | typeof(TDetail).SetDetailId(detail, mainId, name); |
| | | } |
| | | |
| | | BaseDal.Db.Insertable(addRows).ExecuteCommand(); |
| | | |
| | | ((SqlSugarScope)BaseDal.Db).CommitTran(); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | else |
| | | { |
| | | content = WebResponseContent.Instance.Error("æªæ¾å°ä¸»è¡¨ä¸»é®å¼"); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ((SqlSugarScope)BaseDal.Db).RollbackTran(); |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="key">主é®</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent DeleteData(object key) |
| | | { |
| | | try |
| | | { |
| | | return BaseDal.DeleteDataById(key) ? WebResponseContent.Instance.OK() : WebResponseContent.Instance.Error(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="keys">䏻鮿°ç»</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent DeleteData(object[] keys) |
| | | { |
| | | try |
| | | { |
| | | if (typeof(TEntity).GetNavigatePro() == null) |
| | | return BaseDal.DeleteDataByIds(keys) ? WebResponseContent.Instance.OK() : WebResponseContent.Instance.Error(); |
| | | else |
| | | { |
| | | if (keys != null) |
| | | { |
| | | Type detailType = typeof(TEntity).GetDetailType(); |
| | | string name = typeof(TEntity).GetMainIdByDetail(); |
| | | List<object> dynamicDelKeys = new List<object>(); |
| | | |
| | | for (int i = 0; i < keys.Length; i++) |
| | | { |
| | | dynamicDelKeys.Add(keys[i]); |
| | | } |
| | | ((SqlSugarScope)BaseDal.Db).BeginTran(); |
| | | |
| | | if (dynamicDelKeys.Count > 0) |
| | | BaseDal.Db.Deleteable<object>().AS(detailType.Name).Where($"{name} in (@id)", new { id = dynamicDelKeys.ToArray() }).ExecuteCommandHasChange(); |
| | | |
| | | BaseDal.DeleteDataByIds(keys); |
| | | |
| | | ((SqlSugarScope)BaseDal.Db).CommitTran(); |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | else |
| | | { |
| | | return WebResponseContent.Instance.Error("åæ°é误"); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ((SqlSugarScope)BaseDal.Db).RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="entity">å个å®ä½</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent DeleteData(TEntity entity) |
| | | { |
| | | try |
| | | { |
| | | return BaseDal.DeleteData(entity) ? WebResponseContent.Instance.OK() : WebResponseContent.Instance.Error(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å 餿°æ® |
| | | /// </summary> |
| | | /// <param name="entities">å®ä½éå</param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent DeleteData(List<TEntity> entities) |
| | | { |
| | | try |
| | | { |
| | | return BaseDal.DeleteData(entities) ? WebResponseContent.Instance.OK() : WebResponseContent.Instance.Error(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¯¼åºæ°æ® |
| | | /// </summary> |
| | | /// <param name="pageData"></param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent Export(PageDataOptions options) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Type t = typeof(TEntity); |
| | | |
| | | string savePath = AppDomain.CurrentDomain.BaseDirectory + $"ExcelExport"; |
| | | IExporter exporter = new ExcelExporter(); |
| | | string wheres = ValidatePageOptions(options); |
| | | //è·åæåºå段 |
| | | Dictionary<string, OrderByType> orderbyDic = GetPageDataSort(options, TProperties); |
| | | |
| | | List<TEntity> entities = BaseDal.QueryData(wheres, orderbyDic); |
| | | |
| | | byte[] data = exporter.ExportAsByteArray(entities).Result; |
| | | |
| | | string fileName = ""; |
| | | SugarTable sugarTable = t.GetCustomAttribute<SugarTable>(); |
| | | if (sugarTable != null) |
| | | { |
| | | fileName = sugarTable.TableDescription + ".xlsx"; |
| | | } |
| | | else |
| | | { |
| | | fileName = nameof(TEntity) + ".xlsx"; |
| | | } |
| | | |
| | | FileHelper.WriteFile(savePath, fileName, data); |
| | | |
| | | content = WebResponseContent.Instance.OK(data: savePath + "\\" + fileName); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 导å
¥æ°æ® |
| | | /// </summary> |
| | | /// <param name="files"></param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent Import(List<IFormFile> files) |
| | | { |
| | | try |
| | | { |
| | | if (files == null || files.Count == 0) |
| | | return new WebResponseContent { Status = true, Message = "è¯·éæ©ä¸ä¼ çæä»¶" }; |
| | | Microsoft.AspNetCore.Http.IFormFile formFile = files[0]; |
| | | string dicPath = AppDomain.CurrentDomain.BaseDirectory + $"ExcelImprot/{DateTime.Now.ToString("yyyMMdd")}/{typeof(TEntity).Name}/"; |
| | | if (!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath); |
| | | string fileName = $"{Guid.NewGuid()}_{formFile.FileName}"; |
| | | dicPath = $"{dicPath}{fileName}"; |
| | | using (FileStream stream = new FileStream(dicPath, FileMode.Create)) |
| | | { |
| | | formFile.CopyTo(stream); |
| | | } |
| | | ExcelImporter importer = new ExcelImporter(); |
| | | ImportResult<TEntity> importResult = importer.Import<TEntity>(dicPath, "").Result; |
| | | if (importResult.HasError) |
| | | { |
| | | return WebResponseContent.Instance.Error(importResult.TemplateErrors.Serialize()); |
| | | } |
| | | BaseDal.AddData(importResult.Data.ToList()); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¸ä¼ æä»¶ |
| | | /// </summary> |
| | | /// <param name="files"></param> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent Upload(List<IFormFile> files) |
| | | { |
| | | throw new NotImplementedException(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 模æ¿ä¸è½½ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public virtual WebResponseContent DownLoadTemplate() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | Type t = typeof(TEntity); |
| | | IExporter exporter = new ExcelExporter(); |
| | | byte[] data = exporter.ExportHeaderAsByteArray(new TEntity()).Result; |
| | | string fileName = ""; |
| | | SugarTable sugarTable = t.GetCustomAttribute<SugarTable>(); |
| | | if (sugarTable != null) |
| | | { |
| | | fileName = sugarTable.TableDescription + "导å
¥æ¨¡æ¿.xlsx"; |
| | | } |
| | | else |
| | | { |
| | | fileName = nameof(TEntity) + "导å
¥æ¨¡æ¿.xlsx"; |
| | | } |
| | | string savePath = AppDomain.CurrentDomain.BaseDirectory + $"ExcelImprotTemplate"; |
| | | FileHelper.WriteFile(savePath, fileName, data); |
| | | |
| | | content = WebResponseContent.Instance.OK(data: savePath + "\\" + fileName); |
| | | return content; |
| | | } |
| | | |
| | | public WebResponseContent ExportSeedData() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string seedDataFolder = $"WIDESEAWCS_DB.DBSeed.Json/{typeof(TEntity).Name}.tsv"; |
| | | List<TEntity> deviceInfos = BaseDal.QueryData(); |
| | | string str = JsonConvert.SerializeObject(deviceInfos, Formatting.Indented); |
| | | List<Dictionary<string, object>> keyValuePairs = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(str); |
| | | FileHelper.WriteFileAndDelOldFile($"{AppDomain.CurrentDomain.BaseDirectory}wwwroot/{seedDataFolder}", str); |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Linq.Expressions; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.BaseServices |
| | | { |
| | | public abstract class ServiceFunFilter<T> where T : class |
| | | { |
| | | /// <summary> |
| | | /// 2020.08.15æ¯å¦å¼å¯å¤ç§æ·åè½ |
| | | /// ä½¿ç¨æ¹æ³è§ææ¡£æSellOrderService.cs |
| | | /// </summary> |
| | | protected bool IsMultiTenancy { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢çé¢table ç»è®¡ãæ±åãå¹³åå¼ç |
| | | /// å®ç°æ¹å¼ |
| | | ///SummaryExpress = (IQueryable<App_TransactionAvgPrice> queryable) => |
| | | // { |
| | | // return queryable.GroupBy(x => 1).Select(x => new |
| | | // { |
| | | // AvgPrice = x.Average(o => o.AvgPrice), |
| | | // Enable = x.Sum(o => o.Enable) |
| | | // }).FirstOrDefault(); |
| | | //}; |
| | | /// </summary> |
| | | // protected Func<IGrouping<T, T>, object> SummaryExpress = null; |
| | | protected Func<IQueryable<T>, object> SummaryExpress = null; |
| | | |
| | | /// <summary> |
| | | /// æç»table ç»è®¡ãæ±åãå¹³åå¼ç |
| | | /// </summary> |
| | | /// <typeparam name="Detail"></typeparam> |
| | | /// <param name="queryeable"></param> |
| | | /// <returns></returns> |
| | | //protected abstract object GetDetailSummary<Detail>(IQueryable<Detail> queryeable); |
| | | |
| | | /// <summary> |
| | | /// æ¯å¦å¼å¯ç¨æ·æ°æ®æé,true=ç¨æ·åªè½æä½èªå·±(åä¸çº§è§è²)åå»ºçæ°æ®,å¦:æ¥è¯¢ãå é¤ãä¿®æ¹çæä½ |
| | | /// 注æï¼éè¦å¨ä»£ç çæå¨çé¢éæ©ãæ¯ãåçæModelæä¼çæ) |
| | | /// </summary> |
| | | protected bool LimitCurrentUserPermission { get; set; } = false; |
| | | |
| | | ///é»è®¤å¯¼åºæå¤§è¡¨æ°éï¼0ä¸éå¶ |
| | | protected int Limit { get; set; } = 0; |
| | | |
| | | /// <summary> |
| | | /// é»è®¤ä¸ä¼ æä»¶å¤§å°éå¶3M |
| | | /// </summary> |
| | | protected int LimitUpFileSizee { get; set; } = 3; |
| | | |
| | | |
| | | /// <summary> |
| | | /// 2020.08.15æ·»å èªå®ä¹åçæ¥è¯¢sql,è¿ä¸ªå¯¹äºä¸æ³å表达å¼å
³èæè
夿æ¥è¯¢é常æç¨ |
| | | /// ä¾ï¼QuerySql=$"select * from tb1 as a where a.name='xxxx' x.id in (select b.id from tb2 b)"; |
| | | /// select * è¿éå¯ä»¥èªå®ä¹ï¼ä½select å¿
é¡»è¿å表ææçåï¼ä¸è½å° |
| | | /// </summary> |
| | | protected string QuerySql = null; |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢å,对ç°å¨æçæ¥è¯¢å符串æ¡ä»¶å¢å æå é¤ |
| | | /// </summary> |
| | | protected Action<List<SearchParameters>> QueryRelativeList { get; set; } |
| | | |
| | | //æ¥è¯¢å,å¨ç°æçæ¥è¯¢æ¡ä»¶ä¸éè¿è¡¨è¾¾å¼ä¿®æ¹æ¥è¯¢æ¡ä»¶ |
| | | protected Func<IQueryable<T>, IQueryable<T>> QueryRelativeExpression { get; set; } |
| | | |
| | | |
| | | /// <summary> |
| | | /// æå®æ¥è¯¢çåï¼æ ¼å¼:Expression<Func<T, object>> exp = x => new { x.åæ®µ1, x.åæ®µ2 }(ææ¶æªå¯ç¨) |
| | | /// </summary> |
| | | protected Expression<Func<T, object>> Columns { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设置æ¥è¯¢æåºåæ°åæ¹å¼,åæ°æ ¼å¼ä¸ºï¼ |
| | | /// Expression<Func<T, Dictionary<object, bool>>> orderBy = x => new Dictionary<object, QueryOrderBy>() |
| | | /// {{ x.ID, QueryOrderBy.Asc },{ x.DestWarehouseName, QueryOrderBy.Desc } }; |
| | | /// è¿åçæ¯new Dictionary<object, bool>(){{}}key为æåºå段ï¼QueryOrderBy为æåºæ¹å¼ |
| | | /// </summary> |
| | | protected Expression<Func<T, Dictionary<object, OrderByType>>> OrderByExpression; |
| | | |
| | | /// <summary> |
| | | /// 设置æ¥è¯¢ç表å(å·²å¼ç¨) |
| | | /// </summary> |
| | | protected string TableName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 页颿¥è¯¢æå¯¼åºï¼ä»æ°æ®åºæ¥è¯¢åºæ¥çç»æ |
| | | /// </summary> |
| | | protected Action<PageGridData<T>> GetPageDataOnExecuted; |
| | | |
| | | /// <summary> |
| | | /// è°ç¨æ°å»ºå¤çå(SaveModelä¸ºä¼ å
¥çåçæ°æ®) |
| | | /// </summary> |
| | | protected Func<SaveModel, WebResponseContent> AddOnExecute; |
| | | |
| | | /// <summary> |
| | | /// è°ç¨æ°å»ºä¿åæ°æ®åºåå¤ç(å·²å°æäº¤çåçæ°æ®è½¬æ¢æäºå¯¹è±¡) |
| | | /// Func<T, object,ResponseData> Tä¸ºä¸»è¡¨æ°æ®ï¼object为æç»æ°æ®(妿éè¦ä½¿ç¨æç»å¯¹è±¡,è¯·ç¨ object as List<T>转æ¢) |
| | | /// </summary> |
| | | protected Func<T, object, WebResponseContent> AddOnExecuting; |
| | | |
| | | /// <summary> |
| | | /// è°ç¨æ°å»ºä¿åæ°æ®åºåå¤çã |
| | | /// **å®ç°å½åæ¹æ³æ¶ï¼å
é¨é»è®¤å·²ç»å¼å¯äºå¡ï¼å¦æå®ç°çæ¹æ³æä½çæ¯å䏿°æ®åº,åä¸éè¦å¨AddOnExecutedä¸äºå¡ |
| | | /// Func<T, object,ResponseData> Tä¸ºä¸»è¡¨æ°æ®ï¼object为æç»æ°æ®(妿éè¦ä½¿ç¨æç»å¯¹è±¡,è¯·ç¨ object as List<T>转æ¢) |
| | | /// æ¤å¤å·²å¼å¯äºDbContextäºå¡(éç¹),å¦æè¿æå
¶ä»ä¸å¡å¤äºï¼ç´æ¥å¨è¿éåEF代ç ,ä¸éè¦åå¼å¯äºå¡ |
| | | /// 妿æ§è¡çæ¯æåsql请ç¨repository.DbContext.Database.ExecuteSqlCommand()æ repository.DbContext.Set<T>().FromSqlæ§è¡å
·ä½sqlè¯å¥ |
| | | /// </summary> |
| | | protected Func<T, object, WebResponseContent> AddOnExecuted; |
| | | |
| | | /// <summary> |
| | | /// è¿å
¥å®¡æ¹æµç¨æ¹æ³ä¹å |
| | | /// </summary> |
| | | protected Func<T, bool> AddWorkFlowExecuting; |
| | | |
| | | /// <summary> |
| | | /// åå
¥å®¡æ¹æµç¨æ°æ®ä¹å |
| | | /// list:审æ¹ç人id |
| | | /// </summary> |
| | | protected Action<T, List<int>> AddWorkFlowExecuted; |
| | | |
| | | /// <summary> |
| | | /// è°ç¨æ´æ°æ¹æ³åå¤ç(SaveModelä¸ºä¼ å
¥çåçæ°æ®) |
| | | /// </summary> |
| | | protected Func<SaveModel, WebResponseContent> UpdateOnExecute; |
| | | |
| | | /// <summary> |
| | | /// è°ç¨æ´æ°æ¹æ³åå¤ç(SaveModelä¸ºä¼ å
¥çåçæ°æ®) |
| | | /// </summary> |
| | | protected Func<SaveModel, List<string>> UpdateIgnoreColOnExecute; |
| | | |
| | | /// <summary> |
| | | /// è°ç¨æ´æ°æ¹æ³ä¿åæ°æ®åºåå¤ç |
| | | /// (å·²å°æäº¤çåçæ°æ®è½¬æ¢æäºå¯¹è±¡,å°æç»æ°å¢ãä¿®æ¹ãå é¤çæ°æ®åå«ç¨object1/2/3æ è¯åºæ¥ ) |
| | | /// T=æ´æ°ç主表对象 |
| | | /// object1=为æ°å¢æç»ç对象ï¼ä½¿ç¨æ¶å°object as List<T>转æ¢ä¸ä¸ |
| | | /// object2=ä¸ºæ´æ°æç»ç对象 |
| | | /// List<object>=为å é¤çç»ç对象Key |
| | | /// </summary> |
| | | protected Func<T, object, object, List<object>, WebResponseContent> UpdateOnExecuting; |
| | | |
| | | /// <summary> |
| | | /// è°ç¨æ´æ°æ¹æ³ä¿åæ°æ®åºåå¤ç |
| | | /// **å®ç°å½åæ¹æ³æ¶ï¼å
é¨é»è®¤å·²ç»å¼å¯äºå¡ï¼å¦æå®ç°çæ¹æ³æä½çæ¯å䏿°æ®åº,åä¸éè¦å¨UpdateOnExecutedä¸äºå¡ |
| | | /// (å·²å°æäº¤çåçæ°æ®è½¬æ¢æäºå¯¹è±¡,å°æç»æ°å¢ãä¿®æ¹ãå é¤çæ°æ®åå«ç¨object1/2/3æ è¯åºæ¥ ) |
| | | /// T=æ´æ°ç主表对象 |
| | | /// object1=为æ°å¢æç»ç对象ï¼ä½¿ç¨æ¶å°object as List<T>转æ¢ä¸ä¸ |
| | | /// object2=ä¸ºæ´æ°æç»ç对象 |
| | | /// List<object>=为å é¤çç»ç对象Key |
| | | /// æ¤å¤å·²å¼å¯äºDbContextäºå¡(éç¹),å¦æè¿æå
¶ä»ä¸å¡å¤äºï¼ç´æ¥å¨è¿éåEF代ç ,ä¸éè¦åå¼å¯äºå¡ |
| | | /// 妿æ§è¡çæ¯æåsql请ç¨repository.DbContext.Database.ExecuteSqlCommand()æ repository.DbContext.Set<T>().FromSqlæ§è¡å
·ä½sqlè¯å¥ |
| | | /// </summary> |
| | | protected Func<T, object, object, List<object>, WebResponseContent> UpdateOnExecuted; |
| | | |
| | | /// <summary> |
| | | /// å é¤åå¤ç,object[]åå¤å é¤çä¸»é® |
| | | /// </summary> |
| | | protected Func<object[], WebResponseContent> DelOnExecuting; |
| | | |
| | | /// <summary> |
| | | /// å é¤åå¤ç,object[]å·²å é¤ç主é®,æ¤å¤å·²å¼å¯äºDbContextäºå¡(éç¹),å¦æè¿æå
¶ä»ä¸å¡å¤äºï¼ç´æ¥å¨è¿éåEF代ç ,ä¸éè¦åå¼å¯äºå¡ |
| | | /// 妿æ§è¡çæ¯æåsql请ç¨repository.DbContext.Database.ExecuteSqlCommand()æ repository.DbContext.Set<T>().FromSqlæ§è¡å
·ä½sqlè¯å¥ |
| | | /// </summary> |
| | | protected Func<object[], WebResponseContent> DelOnExecuted; |
| | | |
| | | /// <summary> |
| | | /// å®¡æ ¸åå¤ç |
| | | /// </summary> |
| | | protected Func<List<T>, WebResponseContent> AuditOnExecuting; |
| | | /// <summary> |
| | | /// å®¡æ ¸åå¤ç |
| | | /// </summary> |
| | | protected Func<List<T>, WebResponseContent> AuditOnExecuted; |
| | | |
| | | |
| | | /// <summary> |
| | | ///导åºåå¤ç,DataTable导åºçè¡¨æ°æ® |
| | | ///List<T>导åºçæ°æ®, List<string>忽ç¥ä¸éè¦å¯¼åºçåæ®µ |
| | | ///æ¤æ¹æ³ä¸å»ºè®®ä½¿ç¨,ç±ä¸é¢ExportColumnså§ææ¿ä»£2020.05.07 |
| | | /// </summary> |
| | | protected Func<List<T>, List<string>, WebResponseContent> ExportOnExecuting; |
| | | |
| | | /// <summary> |
| | | /// 2020.05.07 |
| | | /// 导åºè¡¨æ°æ®(çé¢ä¸å¯¼åºæä½),æå®è¦å¯¼åºçåï¼æ ¼å¼:Expression<Func<T, object>> exp = x => new { x.åæ®µ1, x.åæ®µ2 } |
| | | /// </summary> |
| | | protected Expression<Func<T, object>> ExportColumns { get; set; } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 2020.05.07 |
| | | /// 导åºä¸è½½æ¨¡æ¿ï¼æå®è¦å¯¼åºç模æ¿åï¼æ ¼å¼:Expression<Func<T, object>> exp = x => new { x.åæ®µ1, x.åæ®µ2 } |
| | | /// </summary> |
| | | protected Expression<Func<T, object>> DownLoadTemplateColumns { get; set; } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 导å
¥ä¿åå |
| | | /// </summary> |
| | | protected Func<List<T>, WebResponseContent> ImportOnExecuted; |
| | | |
| | | /// <summary> |
| | | /// 导å
¥ä¿åå |
| | | /// </summary> |
| | | protected Func<List<T>, WebResponseContent> ImportOnExecuting; |
| | | |
| | | /// <summary> |
| | | /// 导å
¥æ¶ä¸éªè¯ä¸ææ¡æ°æ®æºçåæ®µå¼2023.05.03 |
| | | /// </summary> |
| | | protected Expression<Func<T, object>> ImportIgnoreSelectValidationColumns; |
| | | |
| | | /// <summary> |
| | | /// 2022.06.20å¢å åçexcelè¯»åæ¹æ³(导å
¥æ¶å¯ä»¥èªå®ä¹è¯»åexcelå
容) |
| | | /// string=å½å读åçexcelåå
æ ¼çå¼ |
| | | /// ExcelWorksheet=excel对象 |
| | | /// ExcelRangeå½åexcelåå
æ ¼å¯¹è±¡ |
| | | /// int=å½å读åçç¬¬å æ° |
| | | /// int=å½å读åç第å å |
| | | /// string=è¿åçå¼ |
| | | /// </summary> |
| | | //protected Func<string, ExcelWorksheet, ExcelRange, int, int, string> ImportOnReadCellValue; |
| | | |
| | | |
| | | /// <summary> |
| | | /// èªå®ä¹ä¸ä¼ æä»¶å¤¹(2022.10.07) |
| | | /// </summary> |
| | | protected string UploadFolder = null; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.Caching.Distributed; |
| | | using Microsoft.Extensions.Caching.Memory; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Const; |
| | | |
| | | namespace WIDESEAWCS_Core.Caches |
| | | { |
| | | /// <summary> |
| | | /// å®ä¾åç¼åæ¥å£ICaching |
| | | /// </summary> |
| | | public class Caching : ICaching |
| | | { |
| | | private readonly IDistributedCache _cache; |
| | | |
| | | public Caching(IDistributedCache cache) |
| | | { |
| | | _cache = cache; |
| | | } |
| | | |
| | | private byte[] GetBytes<T>(T source) |
| | | { |
| | | return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(source)); |
| | | } |
| | | |
| | | public IDistributedCache Cache => _cache; |
| | | |
| | | public void AddCacheKey(string cacheKey) |
| | | { |
| | | var res = _cache.GetString(CacheConst.KeyAll); |
| | | var allkeys = string.IsNullOrWhiteSpace(res) ? new List<string>() : JsonConvert.DeserializeObject<List<string>>(res); |
| | | if (!allkeys.Any(m => m == cacheKey)) |
| | | { |
| | | allkeys.Add(cacheKey); |
| | | _cache.SetString(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¢å ç¼åKey |
| | | /// </summary> |
| | | /// <param name="cacheKey"></param> |
| | | /// <returns></returns> |
| | | public async Task AddCacheKeyAsync(string cacheKey) |
| | | { |
| | | var res = await _cache.GetStringAsync(CacheConst.KeyAll); |
| | | var allkeys = string.IsNullOrWhiteSpace(res) ? new List<string>() : JsonConvert.DeserializeObject<List<string>>(res); |
| | | if (!allkeys.Any(m => m == cacheKey)) |
| | | { |
| | | allkeys.Add(cacheKey); |
| | | await _cache.SetStringAsync(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); |
| | | } |
| | | } |
| | | |
| | | public void DelByPattern(string key) |
| | | { |
| | | var allkeys = GetAllCacheKeys(); |
| | | if (allkeys == null) return; |
| | | |
| | | var delAllkeys = allkeys.Where(u => u.Contains(key)).ToList(); |
| | | delAllkeys.ForEach(u => { _cache.Remove(u); }); |
| | | |
| | | // æ´æ°ææç¼åé® |
| | | allkeys = allkeys.Where(u => !u.Contains(key)).ToList(); |
| | | _cache.SetString(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å 餿ç¹å¾å
³é®åç¼å |
| | | /// </summary> |
| | | /// <param name="key"></param> |
| | | /// <returns></returns> |
| | | public async Task DelByPatternAsync(string key) |
| | | { |
| | | var allkeys = await GetAllCacheKeysAsync(); |
| | | if (allkeys == null) return; |
| | | |
| | | var delAllkeys = allkeys.Where(u => u.Contains(key)).ToList(); |
| | | delAllkeys.ForEach(u => { _cache.Remove(u); }); |
| | | |
| | | // æ´æ°ææç¼åé® |
| | | allkeys = allkeys.Where(u => !u.Contains(key)).ToList(); |
| | | await _cache.SetStringAsync(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); |
| | | } |
| | | |
| | | public void DelCacheKey(string cacheKey) |
| | | { |
| | | var res = _cache.GetString(CacheConst.KeyAll); |
| | | var allkeys = string.IsNullOrWhiteSpace(res) ? new List<string>() : JsonConvert.DeserializeObject<List<string>>(res); |
| | | if (allkeys.Any(m => m == cacheKey)) |
| | | { |
| | | allkeys.Remove(cacheKey); |
| | | _cache.SetString(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å é¤ç¼å |
| | | /// </summary> |
| | | /// <param name="cacheKey"></param> |
| | | /// <returns></returns> |
| | | public async Task DelCacheKeyAsync(string cacheKey) |
| | | { |
| | | var res = await _cache.GetStringAsync(CacheConst.KeyAll); |
| | | var allkeys = string.IsNullOrWhiteSpace(res) ? new List<string>() : JsonConvert.DeserializeObject<List<string>>(res); |
| | | if (allkeys.Any(m => m == cacheKey)) |
| | | { |
| | | allkeys.Remove(cacheKey); |
| | | await _cache.SetStringAsync(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); |
| | | } |
| | | } |
| | | |
| | | public bool Exists(string cacheKey) |
| | | { |
| | | var res = _cache.Get(cacheKey); |
| | | return res != null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ£æ¥ç»å® key æ¯å¦åå¨ |
| | | /// </summary> |
| | | /// <param name="cacheKey">é®</param> |
| | | /// <returns></returns> |
| | | public async Task<bool> ExistsAsync(string cacheKey) |
| | | { |
| | | var res = await _cache.GetAsync(cacheKey); |
| | | return res != null; |
| | | } |
| | | |
| | | public List<string> GetAllCacheKeys() |
| | | { |
| | | var res = _cache.GetString(CacheConst.KeyAll); |
| | | return string.IsNullOrWhiteSpace(res) ? null : JsonConvert.DeserializeObject<List<string>>(res); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åææç¼åå表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public async Task<List<string>> GetAllCacheKeysAsync() |
| | | { |
| | | var res = await _cache.GetStringAsync(CacheConst.KeyAll); |
| | | return string.IsNullOrWhiteSpace(res) ? null : JsonConvert.DeserializeObject<List<string>>(res); |
| | | } |
| | | |
| | | public T Get<T>(string cacheKey) |
| | | { |
| | | var res = _cache.Get(cacheKey); |
| | | return res == null ? default : JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(res)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åç¼å |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="cacheKey"></param> |
| | | /// <returns></returns> |
| | | public async Task<T> GetAsync<T>(string cacheKey) |
| | | { |
| | | var res = await _cache.GetAsync(cacheKey); |
| | | return res == null ? default : JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(res)); |
| | | } |
| | | |
| | | public object Get(Type type, string cacheKey) |
| | | { |
| | | var res = _cache.Get(cacheKey); |
| | | return res == null ? default : JsonConvert.DeserializeObject(Encoding.UTF8.GetString(res), type); |
| | | } |
| | | |
| | | public async Task<object> GetAsync(Type type, string cacheKey) |
| | | { |
| | | var res = await _cache.GetAsync(cacheKey); |
| | | return res == null ? default : JsonConvert.DeserializeObject(Encoding.UTF8.GetString(res), type); |
| | | } |
| | | |
| | | public string GetString(string cacheKey) |
| | | { |
| | | return _cache.GetString(cacheKey); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åç¼å |
| | | /// </summary> |
| | | /// <param name="cacheKey"></param> |
| | | /// <returns></returns> |
| | | public async Task<string> GetStringAsync(string cacheKey) |
| | | { |
| | | return await _cache.GetStringAsync(cacheKey); |
| | | } |
| | | |
| | | public void Remove(string key) |
| | | { |
| | | _cache.Remove(key); |
| | | DelCacheKey(key); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å é¤ç¼å |
| | | /// </summary> |
| | | /// <param name="key"></param> |
| | | /// <returns></returns> |
| | | public async Task RemoveAsync(string key) |
| | | { |
| | | await _cache.RemoveAsync(key); |
| | | await DelCacheKeyAsync(key); |
| | | } |
| | | |
| | | public void RemoveAll() |
| | | { |
| | | var catches = GetAllCacheKeys(); |
| | | foreach (var @catch in catches) Remove(@catch); |
| | | |
| | | catches.Clear(); |
| | | _cache.SetString(CacheConst.KeyAll, JsonConvert.SerializeObject(catches)); |
| | | } |
| | | |
| | | public async Task RemoveAllAsync() |
| | | { |
| | | var catches = await GetAllCacheKeysAsync(); |
| | | foreach (var @catch in catches) await RemoveAsync(@catch); |
| | | |
| | | catches.Clear(); |
| | | await _cache.SetStringAsync(CacheConst.KeyAll, JsonConvert.SerializeObject(catches)); |
| | | } |
| | | |
| | | |
| | | public void Set<T>(string cacheKey, T value, TimeSpan? expire = null) |
| | | { |
| | | _cache.Set(cacheKey, GetBytes(value), |
| | | expire == null |
| | | ? new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(6) } |
| | | : new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = expire }); |
| | | |
| | | AddCacheKey(cacheKey); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¢å 对象ç¼å |
| | | /// </summary> |
| | | /// <param name="cacheKey"></param> |
| | | /// <param name="value"></param> |
| | | /// <returns></returns> |
| | | public async Task SetAsync<T>(string cacheKey, T value) |
| | | { |
| | | await _cache.SetAsync(cacheKey, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value)), |
| | | new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(6) }); |
| | | |
| | | await AddCacheKeyAsync(cacheKey); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¢å 对象ç¼å,å¹¶è®¾ç½®è¿ææ¶é´ |
| | | /// </summary> |
| | | /// <param name="cacheKey"></param> |
| | | /// <param name="value"></param> |
| | | /// <param name="expire"></param> |
| | | /// <returns></returns> |
| | | public async Task SetAsync<T>(string cacheKey, T value, TimeSpan expire) |
| | | { |
| | | await _cache.SetAsync(cacheKey, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value)), |
| | | new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = expire }); |
| | | |
| | | await AddCacheKeyAsync(cacheKey); |
| | | } |
| | | |
| | | public void SetPermanent<T>(string cacheKey, T value) |
| | | { |
| | | _cache.Set(cacheKey, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value))); |
| | | AddCacheKey(cacheKey); |
| | | } |
| | | |
| | | public async Task SetPermanentAsync<T>(string cacheKey, T value) |
| | | { |
| | | await _cache.SetAsync(cacheKey, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value))); |
| | | await AddCacheKeyAsync(cacheKey); |
| | | } |
| | | |
| | | public void SetString(string cacheKey, string value, TimeSpan? expire = null) |
| | | { |
| | | if (expire == null) |
| | | _cache.SetString(cacheKey, value, new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(6) }); |
| | | else |
| | | _cache.SetString(cacheKey, value, new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = expire }); |
| | | |
| | | AddCacheKey(cacheKey); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¢å å符串ç¼å |
| | | /// </summary> |
| | | /// <param name="cacheKey"></param> |
| | | /// <param name="value"></param> |
| | | /// <returns></returns> |
| | | public async Task SetStringAsync(string cacheKey, string value) |
| | | { |
| | | await _cache.SetStringAsync(cacheKey, value, new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(6) }); |
| | | |
| | | await AddCacheKeyAsync(cacheKey); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¢å å符串ç¼å,å¹¶è®¾ç½®è¿ææ¶é´ |
| | | /// </summary> |
| | | /// <param name="cacheKey"></param> |
| | | /// <param name="value"></param> |
| | | /// <param name="expire"></param> |
| | | /// <returns></returns> |
| | | public async Task SetStringAsync(string cacheKey, string value, TimeSpan expire) |
| | | { |
| | | await _cache.SetStringAsync(cacheKey, value, new DistributedCacheEntryOptions() { AbsoluteExpirationRelativeToNow = expire }); |
| | | |
| | | await AddCacheKeyAsync(cacheKey); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// ç¼åæå¤§è§è²æ°æ®èå´ |
| | | /// </summary> |
| | | /// <param name="userId"></param> |
| | | /// <param name="dataScopeType"></param> |
| | | /// <returns></returns> |
| | | public async Task SetMaxDataScopeType(long userId, int dataScopeType) |
| | | { |
| | | var cacheKey = CacheConst.KeyMaxDataScopeType + userId; |
| | | await SetStringAsync(cacheKey, dataScopeType.ToString()); |
| | | |
| | | await AddCacheKeyAsync(cacheKey); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®ç¶é®æ¸
空 |
| | | /// </summary> |
| | | /// <param name="key"></param> |
| | | /// <returns></returns> |
| | | public async Task DelByParentKeyAsync(string key) |
| | | { |
| | | var allkeys = await GetAllCacheKeysAsync(); |
| | | if (allkeys == null) return; |
| | | |
| | | var delAllkeys = allkeys.Where(u => u.StartsWith(key)).ToList(); |
| | | delAllkeys.ForEach(Remove); |
| | | // æ´æ°ææç¼åé® |
| | | allkeys = allkeys.Where(u => !u.StartsWith(key)).ToList(); |
| | | await SetStringAsync(CacheConst.KeyAll, JsonConvert.SerializeObject(allkeys)); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Caches |
| | | { |
| | | public interface ICacheService : IDisposable |
| | | { |
| | | /// <summary> |
| | | /// éªè¯ç¼å项æ¯å¦åå¨ |
| | | /// </summary> |
| | | /// <param name="key">ç¼åKey</param> |
| | | /// <returns></returns> |
| | | bool Exists(string key); |
| | | |
| | | /// <summary> |
| | | /// æ·»å ç¼å |
| | | /// </summary> |
| | | /// <param name="key">ç¼åKey</param> |
| | | /// <param name="value">ç¼åValue</param> |
| | | /// <param name="expiresIn">ç¼åæ¶é¿</param> |
| | | /// <param name="isSliding">æ¯å¦æ»å¨è¿æï¼å¦æå¨è¿ææ¶é´å
ææä½ï¼å以å½åæ¶é´ç¹å»¶é¿è¿ææ¶é´ï¼ //new TimeSpan(0, 60, 0);</param> |
| | | /// <returns></returns> |
| | | bool AddObject(string key, object value, int expireSeconds = -1, bool isSliding = false); |
| | | |
| | | bool Add(string key, string value, int expireSeconds = -1, bool isSliding = false); |
| | | |
| | | void AddOrUpdate(string key, string value, int expireSeconds = -1, bool isSliding = false); |
| | | |
| | | /// <summary> |
| | | /// å é¤ç¼å |
| | | /// </summary> |
| | | /// <param name="key">ç¼åKey</param> |
| | | /// <returns></returns> |
| | | bool Remove(string key); |
| | | |
| | | /// <summary> |
| | | /// æ¹éå é¤ç¼å |
| | | /// </summary> |
| | | /// <param name="key">ç¼åKeyéå</param> |
| | | /// <returns></returns> |
| | | void Remove(IEnumerable<string> keys); |
| | | |
| | | /// <summary> |
| | | /// è·åç¼å |
| | | /// </summary> |
| | | /// <param name="key">ç¼åKey</param> |
| | | /// <returns></returns> |
| | | T Get<T>(string key) where T : class; |
| | | |
| | | /// <summary> |
| | | /// è·åç¼å |
| | | /// </summary> |
| | | /// <param name="key">ç¼åKey</param> |
| | | /// <returns></returns> |
| | | string Get(string key); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.Caching.Distributed; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Caches |
| | | { |
| | | /// <summary> |
| | | /// ç¼åæ½è±¡æ¥å£,åºäºIDistributedCacheå°è£
|
| | | /// </summary> |
| | | public interface ICaching |
| | | { |
| | | public IDistributedCache Cache { get; } |
| | | void AddCacheKey(string cacheKey); |
| | | Task AddCacheKeyAsync(string cacheKey); |
| | | |
| | | void DelByPattern(string key); |
| | | Task DelByPatternAsync(string key); |
| | | |
| | | void DelCacheKey(string cacheKey); |
| | | Task DelCacheKeyAsync(string cacheKey); |
| | | |
| | | bool Exists(string cacheKey); |
| | | Task<bool> ExistsAsync(string cacheKey); |
| | | |
| | | List<string> GetAllCacheKeys(); |
| | | Task<List<string>> GetAllCacheKeysAsync(); |
| | | |
| | | T Get<T>(string cacheKey); |
| | | Task<T> GetAsync<T>(string cacheKey); |
| | | |
| | | object Get(Type type, string cacheKey); |
| | | Task<object> GetAsync(Type type, string cacheKey); |
| | | |
| | | string GetString(string cacheKey); |
| | | Task<string> GetStringAsync(string cacheKey); |
| | | |
| | | void Remove(string key); |
| | | Task RemoveAsync(string key); |
| | | |
| | | void RemoveAll(); |
| | | Task RemoveAllAsync(); |
| | | |
| | | void Set<T>(string cacheKey, T value, TimeSpan? expire = null); |
| | | Task SetAsync<T>(string cacheKey, T value); |
| | | Task SetAsync<T>(string cacheKey, T value, TimeSpan expire); |
| | | |
| | | void SetPermanent<T>(string cacheKey, T value); |
| | | Task SetPermanentAsync<T>(string cacheKey, T value); |
| | | |
| | | void SetString(string cacheKey, string value, TimeSpan? expire = null); |
| | | Task SetStringAsync(string cacheKey, string value); |
| | | Task SetStringAsync(string cacheKey, string value, TimeSpan expire); |
| | | |
| | | Task DelByParentKeyAsync(string key); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.Caching.Memory; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Caches |
| | | { |
| | | public class MemoryCacheService : ICacheService |
| | | { |
| | | protected IMemoryCache _cache; |
| | | public MemoryCacheService(IMemoryCache cache) |
| | | { |
| | | _cache = cache; |
| | | |
| | | } |
| | | |
| | | public bool Add(string key, string value, int expireSeconds = -1, bool isSliding = false) |
| | | { |
| | | return AddObject(key, value, expireSeconds, isSliding); |
| | | } |
| | | |
| | | public bool AddObject(string key, object value, int expireSeconds = -1, bool isSliding = false) |
| | | { |
| | | if (expireSeconds != -1) |
| | | { |
| | | _cache.Set(key, |
| | | value, |
| | | new MemoryCacheEntryOptions() |
| | | .SetSlidingExpiration(new TimeSpan(0, 0, expireSeconds)) |
| | | ); |
| | | } |
| | | else |
| | | { |
| | | _cache.Set(key, value); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | public void AddOrUpdate(string key, string value, int expireSeconds = -1, bool isSliding = false) |
| | | { |
| | | if (!string.IsNullOrEmpty(Get(key))) |
| | | { |
| | | Remove(key); |
| | | Add(key, value, expireSeconds, isSliding); |
| | | } |
| | | else |
| | | { |
| | | Add(key, value, expireSeconds, isSliding); |
| | | } |
| | | } |
| | | |
| | | public void Dispose() |
| | | { |
| | | if (_cache != null) |
| | | _cache.Dispose(); |
| | | GC.SuppressFinalize(this); |
| | | } |
| | | |
| | | public bool Exists(string key) |
| | | { |
| | | if (key == null) |
| | | { |
| | | throw new ArgumentNullException(nameof(key)); |
| | | } |
| | | return _cache.Get(key) != null; |
| | | } |
| | | |
| | | public T Get<T>(string key) where T : class |
| | | { |
| | | if (key == null) |
| | | { |
| | | throw new ArgumentNullException(nameof(key)); |
| | | } |
| | | return _cache.Get(key) as T; |
| | | } |
| | | |
| | | public string Get(string key) |
| | | { |
| | | try |
| | | { |
| | | return _cache.Get(key)?.ToString(); |
| | | } |
| | | catch |
| | | { |
| | | return string.Empty; |
| | | } |
| | | } |
| | | |
| | | public bool Remove(string key) |
| | | { |
| | | if (key == null) |
| | | { |
| | | throw new ArgumentNullException(nameof(key)); |
| | | } |
| | | _cache.Remove(key); |
| | | |
| | | return !Exists(key); |
| | | } |
| | | |
| | | public void Remove(IEnumerable<string> keys) |
| | | { |
| | | if (keys == null) |
| | | { |
| | | throw new ArgumentNullException(nameof(keys)); |
| | | } |
| | | |
| | | keys.ToList().ForEach(item => _cache.Remove(item)); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Const |
| | | { |
| | | /// <summary> |
| | | /// ç§é¥é
ç½® |
| | | /// </summary> |
| | | public struct AppSecret |
| | | { |
| | | public const string JWT = "BB3647441FFA4B5DB4E64A29B53CE525"; |
| | | |
| | | public const string Audience = "WIDESEAWCS_WMS"; |
| | | |
| | | public const string Issuer = "WIDESEAWCS_WMS_Owner"; |
| | | |
| | | public const string TokenHeaderName = "Authorization"; |
| | | |
| | | public const string User = "C5ABA9E202D94C43A3CA66002BF77FAF"; |
| | | |
| | | public const string DB = "3F8B7B38AD3D484A89ACA513CBD79F36"; |
| | | |
| | | //è¿æ¥å符串 |
| | | //Data Source=.;Initial Catalog=WIDESEAWCS_DB_2;User ID=sa;Password=P@ssw0rd;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Const |
| | | { |
| | | /// <summary> |
| | | /// ç¼åç¸å
³å¸¸é |
| | | /// </summary> |
| | | public class CacheConst |
| | | { |
| | | /// <summary> |
| | | /// ç¨æ·ç¼å |
| | | /// </summary> |
| | | public const string KeyUser = "user:"; |
| | | |
| | | /// <summary> |
| | | /// ç¨æ·é¨é¨ç¼å |
| | | /// </summary> |
| | | public const string KeyUserDepart = "userDepart:"; |
| | | |
| | | /// <summary> |
| | | /// èåç¼å |
| | | /// </summary> |
| | | public const string KeyMenu = "menu:"; |
| | | |
| | | /// <summary> |
| | | /// èå |
| | | /// </summary> |
| | | public const string KeyPermissions = "permissions"; |
| | | |
| | | /// <summary> |
| | | /// æéç¼å |
| | | /// </summary> |
| | | public const string KeyPermission = "permission:"; |
| | | |
| | | /// <summary> |
| | | /// æ¥å£è·¯ç± |
| | | /// </summary> |
| | | public const string KeyModules = "modules"; |
| | | |
| | | /// <summary> |
| | | /// ç³»ç»é
ç½® |
| | | /// </summary> |
| | | public const string KeySystemConfig = "sysConfig"; |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢è¿æ»¤å¨ç¼å |
| | | /// </summary> |
| | | public const string KeyQueryFilter = "queryFilter:"; |
| | | |
| | | /// <summary> |
| | | /// æºæIdéåç¼å |
| | | /// </summary> |
| | | public const string KeyOrgIdList = "org:"; |
| | | |
| | | /// <summary> |
| | | /// æå¤§è§è²æ°æ®èå´ç¼å |
| | | /// </summary> |
| | | public const string KeyMaxDataScopeType = "maxDataScopeType:"; |
| | | |
| | | /// <summary> |
| | | /// éªè¯ç ç¼å |
| | | /// </summary> |
| | | public const string KeyVerCode = "verCode:"; |
| | | |
| | | /// <summary> |
| | | /// ææç¼åå
³é®åéå |
| | | /// </summary> |
| | | public const string KeyAll = "keys"; |
| | | |
| | | /// <summary> |
| | | /// 宿¶ä»»å¡ç¼å |
| | | /// </summary> |
| | | public const string KeyTimer = "timer:"; |
| | | |
| | | /// <summary> |
| | | /// å¨çº¿ç¨æ·ç¼å |
| | | /// </summary> |
| | | public const string KeyOnlineUser = "onlineuser:"; |
| | | |
| | | /// <summary> |
| | | /// 常éä¸ææ¡ |
| | | /// </summary> |
| | | public const string KeyConstSelector = "selector:"; |
| | | |
| | | /// <summary> |
| | | /// swaggerç»å½ç¼å |
| | | /// </summary> |
| | | public const string SwaggerLogin = "swaggerLogin:"; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Const |
| | | { |
| | | public class ErrorMsgConst |
| | | { |
| | | public const string ParamIsNull = "åæ°æ æ"; |
| | | public const string EntityValueIsNull = "为å¿
é¡»æäº¤é¡¹"; |
| | | public const string SugarColumnIsNull = "请é
ç½®SugarColumn屿§"; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Const |
| | | { |
| | | public struct HtmlElementType |
| | | { |
| | | public const string drop = "drop"; |
| | | public const string droplist = "droplist"; |
| | | public const string select = "select"; |
| | | public const string selectlist = "selectlist"; |
| | | public const string checkbox = "checkbox"; |
| | | public const string textarea = "textarea"; |
| | | public const string thanorequal = "thanorequal"; |
| | | public const string lessorequal = "lessorequal"; |
| | | |
| | | |
| | | public const string gt = "gt"; |
| | | public const string lt = "lt"; |
| | | public const string GT = ">"; |
| | | public const string LT = "<"; |
| | | public const string like = "like"; |
| | | |
| | | public const string ThanOrEqual = ">="; |
| | | public const string LessOrequal = "<="; |
| | | public const string Contains = "in"; |
| | | public const string Equal = "="; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Const |
| | | { |
| | | public struct SqlDbTypeName |
| | | { |
| | | public const string NVarChar = "nvarchar"; |
| | | public const string VarChar = "varchar"; |
| | | public const string NChar = "nchar"; |
| | | public const string Char = "char"; |
| | | public const string Text = "text"; |
| | | public const string Int = "int"; |
| | | public const string BigInt = "bigint"; |
| | | public const string DateTime = "datetime"; |
| | | public const string Date = "date"; |
| | | public const string SmallDateTime = "smalldatetime"; |
| | | public const string SmallDate = "smalldate"; |
| | | public const string Float = "float"; |
| | | public const string Decimal = "decimal"; |
| | | public const string Double = "double"; |
| | | public const string Bit = "bit"; |
| | | public const string Bool = "bool"; |
| | | public const string UniqueIdentifier = "uniqueidentifier"; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Const |
| | | { |
| | | public class TenantConst |
| | | { |
| | | public const string DBConStr = "Data Source={0};Initial Catalog={1};User ID={2};Password={3};Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Const |
| | | { |
| | | public struct TenantStatus |
| | | { |
| | | public const int Enable = 1; |
| | | public const int Disable = 2; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Microsoft.Extensions.Options; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Core |
| | | { |
| | | public static class ConfigurableOptions |
| | | { |
| | | /// <summary>æ·»å é项é
ç½®</summary> |
| | | /// <typeparam name="TOptions">é项类å</typeparam> |
| | | /// <param name="services">æå¡éå</param> |
| | | /// <returns>æå¡éå</returns> |
| | | public static IServiceCollection AddConfigurableOptions<TOptions>(this IServiceCollection services) |
| | | where TOptions : class, IConfigurableOptions |
| | | { |
| | | Type optionsType = typeof(TOptions); |
| | | string path = GetConfigurationPath(optionsType); |
| | | services.Configure<TOptions>(App.Configuration.GetSection(path)); |
| | | |
| | | return services; |
| | | } |
| | | |
| | | public static IServiceCollection AddConfigurableOptions(this IServiceCollection services, Type type) |
| | | { |
| | | string path = GetConfigurationPath(type); |
| | | var config = App.Configuration.GetSection(path); |
| | | |
| | | Type iOptionsChangeTokenSource = typeof(IOptionsChangeTokenSource<>); |
| | | Type iConfigureOptions = typeof(IConfigureOptions<>); |
| | | Type configurationChangeTokenSource = typeof(ConfigurationChangeTokenSource<>); |
| | | Type namedConfigureFromConfigurationOptions = typeof(NamedConfigureFromConfigurationOptions<>); |
| | | iOptionsChangeTokenSource = iOptionsChangeTokenSource.MakeGenericType(type); |
| | | iConfigureOptions = iConfigureOptions.MakeGenericType(type); |
| | | configurationChangeTokenSource = configurationChangeTokenSource.MakeGenericType(type); |
| | | namedConfigureFromConfigurationOptions = namedConfigureFromConfigurationOptions.MakeGenericType(type); |
| | | |
| | | services.AddOptions(); |
| | | services.AddSingleton(iOptionsChangeTokenSource, |
| | | Activator.CreateInstance(configurationChangeTokenSource, Options.DefaultName, config) ?? throw new InvalidOperationException()); |
| | | return services.AddSingleton(iConfigureOptions, |
| | | Activator.CreateInstance(namedConfigureFromConfigurationOptions, Options.DefaultName, config) ?? throw new InvalidOperationException()); |
| | | } |
| | | |
| | | /// <summary>è·åé
置路å¾</summary> |
| | | /// <param name="optionsType">é项类å</param> |
| | | /// <returns></returns> |
| | | public static string GetConfigurationPath(Type optionsType) |
| | | { |
| | | var endPath = new[] { "Option", "Options" }; |
| | | var configurationPath = optionsType.Name; |
| | | foreach (var s in endPath) |
| | | { |
| | | if (configurationPath.EndsWith(s)) |
| | | { |
| | | return configurationPath[..^s.Length]; |
| | | } |
| | | } |
| | | |
| | | return configurationPath; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Core |
| | | { |
| | | public interface IConfigurableOptions |
| | | { |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Builder; |
| | | using Microsoft.AspNetCore.Hosting; |
| | | using Microsoft.Extensions.Configuration; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Microsoft.Extensions.Hosting; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Core |
| | | { |
| | | public static class InternalApp |
| | | { |
| | | internal static IServiceCollection InternalServices; |
| | | |
| | | /// <summary>æ ¹æå¡</summary> |
| | | internal static IServiceProvider RootServices; |
| | | |
| | | /// <summary>è·åWeb主æºç¯å¢</summary> |
| | | internal static IWebHostEnvironment WebHostEnvironment; |
| | | |
| | | /// <summary>è·åæ³å主æºç¯å¢</summary> |
| | | internal static IHostEnvironment HostEnvironment; |
| | | |
| | | /// <summary>é
置对象</summary> |
| | | internal static IConfiguration Configuration; |
| | | |
| | | public static void ConfigureApplication(this WebApplicationBuilder wab) |
| | | { |
| | | HostEnvironment = wab.Environment; |
| | | WebHostEnvironment = wab.Environment; |
| | | InternalServices = wab.Services; |
| | | } |
| | | |
| | | public static void ConfigureApplication(this IConfiguration configuration) |
| | | { |
| | | Configuration = configuration; |
| | | } |
| | | |
| | | public static void ConfigureApplication(this IHost app) |
| | | { |
| | | RootServices = app.Services; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Dynamic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.Tenants; |
| | | |
| | | namespace WIDESEAWCS_Core.DB |
| | | { |
| | | public class BaseDBConfig |
| | | { |
| | | /* ä¹åçååºæä½å·²ç»å é¤ï¼å¦ææ³è¦ä¹åç代ç ï¼å¯ä»¥æ¥çæçGitHubçåå²è®°å½ |
| | | * ç®åæ¯å¤åºæä½ï¼é»è®¤å è½½çæ¯appsettings.json设置为trueç第ä¸ä¸ªdbè¿æ¥ã |
| | | */ |
| | | public static List<MutiDBOperate> MutiConnectionString => MutiInitConn(); |
| | | |
| | | private static string DifDBConnOfSecurity(params string[] conn) |
| | | { |
| | | foreach (var item in conn) |
| | | { |
| | | try |
| | | { |
| | | if (File.Exists(item)) |
| | | { |
| | | return File.ReadAllText(item).Trim(); |
| | | } |
| | | } |
| | | catch (System.Exception) |
| | | { |
| | | } |
| | | } |
| | | |
| | | return conn[conn.Length - 1]; |
| | | } |
| | | |
| | | public static List<MutiDBOperate> MutiInitConn() |
| | | { |
| | | SqlSugarScope sqlSugarClient = new SqlSugarScope(new ConnectionConfig |
| | | { |
| | | ConfigId = MainDb.CurrentDbConnId, |
| | | ConnectionString = AppSettings.app(MainDb.ConnectionString).DecryptDES(AppSecret.DB), |
| | | IsAutoCloseConnection = true, |
| | | DbType = MainDb.DbType, |
| | | AopEvents = new AopEvents |
| | | { |
| | | OnError = x => |
| | | { |
| | | Console.WriteLine(x.Sql); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | List<ExpandoObject> list = sqlSugarClient.Queryable(MainDb.TenantTableName, "x").Where(MainDb.TenantStatus, "=", TenantStatus.Enable).Select(TenantUtil.GetTenantSelectModels()).ToList(); |
| | | List<MutiDBOperate> listdatabaseSlaveDB = new List<MutiDBOperate>(); |
| | | MutiDBOperate mainDb = new MutiDBOperate() |
| | | { |
| | | Connection = AppSettings.app(MainDb.ConnectionString).DecryptDES(AppSecret.DB), |
| | | ConnId = MainDb.CurrentDbConnId, |
| | | DbType = DataBaseType.SqlServer |
| | | }; |
| | | listdatabaseSlaveDB.Add(mainDb); |
| | | for (int i = 0; i < list.Count; i++) |
| | | { |
| | | dynamic data = list[i]; |
| | | MutiDBOperate mutiDBOperate = new MutiDBOperate() |
| | | { |
| | | Connection = data.ConnectionString, |
| | | ConnId = data.TenantId + "", |
| | | DbType = (DataBaseType)data.DbType, |
| | | }; |
| | | mutiDBOperate.Connection = mutiDBOperate.Connection.DecryptDES(AppSecret.DB); |
| | | listdatabaseSlaveDB.Add(mutiDBOperate); |
| | | } |
| | | |
| | | return listdatabaseSlaveDB; |
| | | } |
| | | } |
| | | |
| | | public enum DataBaseType |
| | | { |
| | | MySql = 0, |
| | | SqlServer = 1, |
| | | Sqlite = 2, |
| | | Oracle = 3, |
| | | PostgreSQL = 4, |
| | | Dm = 5, |
| | | Kdbndp = 6, |
| | | } |
| | | |
| | | public class MutiDBOperate |
| | | { |
| | | /// <summary> |
| | | /// è¿æ¥å¯ç¨å¼å
³ |
| | | /// </summary> |
| | | public bool Enabled { get; set; } |
| | | |
| | | /// <summary> |
| | | /// è¿æ¥ID |
| | | /// </summary> |
| | | public string ConnId { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ä»åºæ§è¡çº§å«ï¼è¶å¤§è¶å
æ§è¡ |
| | | /// </summary> |
| | | public int HitRate { get; set; } |
| | | |
| | | /// <summary> |
| | | /// è¿æ¥å符串 |
| | | /// </summary> |
| | | public string Connection { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ°æ®åºç±»å |
| | | /// </summary> |
| | | public DataBaseType DbType { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.DB |
| | | { |
| | | public static class MainDb |
| | | { |
| | | public const string CurrentDbConnId = "WIDESEA"; |
| | | public const string ConnectionStringsEncryption = "ConnectionStringsEncryption"; |
| | | public const string ConnectionString = "ConnectionString"; |
| | | public const string TenantTableName = "Sys_Tenant"; |
| | | public const string TenantStatus = "Status"; |
| | | public const string TenantId = "TenantId"; |
| | | public const string TenantName = "TenantName"; |
| | | public const string EntityNameSpace = "WIDESEAWCS_Model.Models"; |
| | | public const string TenantDbType = "DbType"; |
| | | public const string AssemblyName = "WIDESEAWCS_Model.dll"; |
| | | public static DbType DbType = DbType.SqlServer; |
| | | public const string UserTableName = "Sys_User"; |
| | | public const string RoleId = "Role_Id"; |
| | | public const string UserName = "UserName"; |
| | | public const string UserId = "User_Id"; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.DB.Models |
| | | { |
| | | public class BaseEntity |
| | | { |
| | | #region æ°æ®ç¶æç®¡ç |
| | | |
| | | /// <summary> |
| | | /// ç¶æ <br/> |
| | | /// ä¸ç«åæ®µï¼æäºè¡¨å¯ä½¿ç¨æäºè¡¨ä¸ä½¿ç¨ |
| | | /// </summary> |
| | | //public bool Enabled { get; set; } = true; |
| | | |
| | | /// <summary> |
| | | /// ä¸ç«åæ®µï¼æäºè¡¨å¯ä½¿ç¨æäºè¡¨ä¸ä½¿ç¨ <br/> |
| | | /// é»è¾ä¸çå é¤ï¼éç©çå é¤ <br/> |
| | | /// ä¾å¦ï¼åæ®å é¤å¹¶éç´æ¥å é¤ |
| | | /// </summary> |
| | | //public bool IsDeleted { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ä¸ç«å段 <br/> |
| | | /// æ¯å¦å
ç½®æ°æ® |
| | | /// </summary> |
| | | //public bool IsInternal { get; set; } |
| | | |
| | | #endregion |
| | | |
| | | #region å建 |
| | | |
| | | /// <summary> |
| | | /// å建è
|
| | | /// </summary> |
| | | [ImporterHeader(IsIgnore = true)] |
| | | [ExporterHeader(DisplayName = "å建è
")] |
| | | [SugarColumn(IsNullable = false, IsOnlyIgnoreUpdate = true, ColumnDescription = "å建è
")] |
| | | public string Creater { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å建æ¶é´ |
| | | /// </summary> |
| | | [ImporterHeader(IsIgnore = true)] |
| | | [ExporterHeader(DisplayName = "å建æ¶é´")] |
| | | [SugarColumn(IsNullable = false, IsOnlyIgnoreUpdate = true, ColumnDescription = "å建æ¶é´")] |
| | | public DateTime CreateDate { get; set; } = DateTime.Now; |
| | | |
| | | #endregion |
| | | |
| | | #region ä¿®æ¹ |
| | | |
| | | /// <summary> |
| | | /// æ´æ°è
|
| | | /// </summary> |
| | | [ImporterHeader(IsIgnore = true)] |
| | | [ExporterHeader(DisplayName = "ä¿®æ¹äºº")] |
| | | [SugarColumn(IsNullable = true, IsOnlyIgnoreInsert = true, ColumnDescription = "ä¿®æ¹äºº")] |
| | | public string Modifier { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ä¿®æ¹æ¥æ |
| | | /// </summary> |
| | | [ImporterHeader(IsIgnore = true)] |
| | | [ExporterHeader(DisplayName = "ä¿®æ¹æ¥æ")] |
| | | [SugarColumn(IsNullable = true, IsOnlyIgnoreInsert = true, ColumnDescription = "ä¿®æ¹æ¥æ")] |
| | | public DateTime? ModifyDate { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ°æ®çæ¬ |
| | | /// </summary> |
| | | //[SugarColumn(DefaultValue = "0", IsEnableUpdateVersionValidation = true)] //æ è¯çæ¬å段 |
| | | //public long Version { get; set; } |
| | | |
| | | #endregion |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.DB.Models; |
| | | using WIDESEAWCS_Core.Tenants; |
| | | |
| | | namespace WIDESEAWCS_Core.DB |
| | | { |
| | | public class RepositorySetting |
| | | { |
| | | private static readonly Lazy<IEnumerable<Type>> AllEntitys = new(() => |
| | | { |
| | | var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; |
| | | var referencedAssemblies = System.IO.Directory.GetFiles(path, MainDb.AssemblyName).Select(Assembly.LoadFrom).FirstOrDefault(); |
| | | return referencedAssemblies |
| | | .GetTypes() |
| | | .Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(BaseEntity))) |
| | | .Where(it => it.FullName != null && it.FullName.StartsWith(MainDb.EntityNameSpace)); |
| | | }); |
| | | |
| | | public static IEnumerable<Type> Entitys => AllEntitys.Value; |
| | | |
| | | /// <summary> |
| | | /// é
ç½®å®ä½è½¯å é¤è¿æ»¤å¨<br/> |
| | | /// ç»ä¸è¿æ»¤ 软å é¤ æ éèªå·±åæ¡ä»¶ |
| | | /// </summary> |
| | | public static void SetDeletedEntityFilter(SqlSugarScopeProvider db) |
| | | { |
| | | //db.QueryFilter.AddTableFilter<IDeleteFilter>(it => it.IsDeleted == false); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// é
ç½®ç§æ· |
| | | /// </summary> |
| | | public static void SetTenantEntityFilter(SqlSugarScopeProvider db) |
| | | { |
| | | if (App.User is not { UserId: > 0, TenantId: > 0 }) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | //å¤ç§æ· å表 |
| | | //db.QueryFilter.AddTableFilter<ITenantEntity>(it => it.TenantId == App.User.TenantId || it.TenantId == 0); |
| | | |
| | | //å¤ç§æ· å¤è¡¨ |
| | | //db.SetTenantTable(App.User.TenantId.ToString()); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System.ComponentModel; |
| | | using System.Reflection; |
| | | |
| | | namespace WIDESEA_Core.Enums |
| | | { |
| | | public static class EnumHelper |
| | | { |
| | | /// <summary> |
| | | /// æä¸¾è½¬åå
¸éå |
| | | /// </summary> |
| | | /// <typeparam name="T">æä¸¾ç±»åç§°</typeparam> |
| | | /// <param name="keyDefault">é»è®¤keyå¼</param> |
| | | /// <param name="valueDefault">é»è®¤valueå¼</param> |
| | | /// <returns>è¿åçæçåå
¸éå</returns> |
| | | public static Dictionary<string, object> EnumListDic<T>(string keyDefault, string valueDefault = "") |
| | | { |
| | | Dictionary<string, object> dicEnum = new Dictionary<string, object>(); |
| | | Type enumType = typeof(T); |
| | | if (!enumType.IsEnum) |
| | | { |
| | | return dicEnum; |
| | | } |
| | | if (!string.IsNullOrEmpty(keyDefault)) //夿æ¯å¦æ·»å é»è®¤é项 |
| | | { |
| | | dicEnum.Add(keyDefault, valueDefault); |
| | | } |
| | | string[] fieldstrs = Enum.GetNames(enumType); //è·åæä¸¾å段æ°ç» |
| | | foreach (var item in fieldstrs) |
| | | { |
| | | string description = string.Empty; |
| | | var field = enumType.GetField(item); |
| | | object[] arr = field.GetCustomAttributes(typeof(DescriptionAttribute), true); //è·å屿§å段æ°ç» |
| | | if (arr != null && arr.Length > 0) |
| | | { |
| | | description = ((DescriptionAttribute)arr[0]).Description; //屿§æè¿° |
| | | } |
| | | else |
| | | { |
| | | description = item; //æè¿°ä¸åå¨ååæ®µåç§° |
| | | } |
| | | dicEnum.Add(description, (int)Enum.Parse(enumType, item)); //ä¸ç¨æä¸¾çvalueå¼ä½ä¸ºåå
¸keyå¼çåå 仿䏾ä¾åè½çåºæ¥ï¼å
¶å®è¿è¾¹åºè¯¥å¤æä»çå¼ä¸åå¨ï¼é»è®¤ååæ®µåç§° |
| | | } |
| | | return dicEnum; |
| | | } |
| | | /// <summary> |
| | | /// è·åæä¸¾é¡¹æè¿°ä¿¡æ¯ ä¾å¦GetEnumDesc(Days.Sunday) |
| | | /// </summary> |
| | | /// <param name="en">æä¸¾é¡¹ å¦Days.Sunday</param> |
| | | /// <returns></returns> |
| | | public static string GetIntegralRuleTypeEnumDesc(this Enum en) |
| | | { |
| | | Type type = en.GetType(); |
| | | MemberInfo[] memInfo = type.GetMember(en.ToString()); |
| | | if (memInfo != null && memInfo.Length > 0) |
| | | { |
| | | object[] attrs = memInfo[0].GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false); |
| | | if (attrs != null && attrs.Length > 0) |
| | | return ((DescriptionAttribute)attrs[0]).Description; |
| | | } |
| | | return en.ToString(); |
| | | } |
| | | /// <summary> |
| | | /// è·åæä¸¾éå |
| | | /// </summary> |
| | | /// <typeparam name="T">æä¸¾ç±»åç§°</typeparam> |
| | | /// <returns></returns> |
| | | public static IEnumerable<EnumModel> GetEnumList<T>() |
| | | { |
| | | var model = default(T); |
| | | FieldInfo[] fieldinfo = typeof(T).GetFields(); |
| | | List<EnumModel> result = new List<EnumModel>(); |
| | | foreach (FieldInfo field in fieldinfo) |
| | | { |
| | | EnumModel enumModel = new EnumModel(); |
| | | if (!(Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute attribute)) |
| | | { |
| | | enumModel.Desc = field.GetValue(model).ToString(); |
| | | } |
| | | else |
| | | { |
| | | enumModel.Desc = attribute.Description; |
| | | } |
| | | enumModel.Value = field.GetValue(model).GetHashCode(); |
| | | enumModel.Key = field.GetValue(model) as ValueType; |
| | | if (field.GetValue(model).ToString() != "0") |
| | | { |
| | | result.Add(enumModel); |
| | | } |
| | | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static int GetEnumMaxValue(this Enum @enum) |
| | | { |
| | | Type type = @enum.GetType(); |
| | | MemberInfo[] memInfo = type.GetMember(@enum.ToString()); |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | public class EnumModel |
| | | { |
| | | /// <summary> |
| | | /// Enumçå¼ |
| | | /// </summary> |
| | | public int Value { get; set; } |
| | | /// <summary> |
| | | /// Enumçkey |
| | | /// </summary> |
| | | public ValueType Key { get; set; } |
| | | /// <summary> |
| | | /// Enumæè¿° |
| | | /// </summary> |
| | | public string Desc { get; set; } |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Enums |
| | | { |
| | | public enum LinqExpressionType |
| | | { |
| | | Equal = 0,//= |
| | | NotEqual = 1,//!= |
| | | GreaterThan,//> |
| | | LessThan,//< |
| | | ThanOrEqual,//>= |
| | | LessThanOrEqual,//<= |
| | | In, |
| | | Contains,//Contains |
| | | NotContains//NotContains |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Enums |
| | | { |
| | | public enum RouterInOutType |
| | | { |
| | | /// <summary> |
| | | /// å
¥åºè·¯ç± |
| | | /// </summary> |
| | | [Description("å
¥åºè·¯ç±")] |
| | | In = 1, |
| | | |
| | | /// <summary> |
| | | /// åºåºè·¯ç± |
| | | /// </summary> |
| | | [Description("åºåºè·¯ç±")] |
| | | Out = 2, |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Core; |
| | | |
| | | namespace WIDESEAWCS_Core.Extensions |
| | | { |
| | | public static class AllOptionRegister |
| | | { |
| | | public static void AddAllOptionRegister(this IServiceCollection services) |
| | | { |
| | | if (services == null) throw new ArgumentNullException(nameof(services)); |
| | | |
| | | foreach (var optionType in App.EffectiveTypes.Where(s => |
| | | !s.IsInterface && typeof(IConfigurableOptions).IsAssignableFrom(s))) |
| | | { |
| | | services.AddConfigurableOptions(optionType); |
| | | } |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Builder; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Extensions |
| | | { |
| | | public static class ApplicationSetup |
| | | { |
| | | public static void UseApplicationSetup(this WebApplication app) |
| | | { |
| | | app.Lifetime.ApplicationStarted.Register(() => |
| | | { |
| | | App.IsRun = true; |
| | | }); |
| | | |
| | | app.Lifetime.ApplicationStopped.Register(() => |
| | | { |
| | | App.IsRun = false; |
| | | |
| | | //æ¸
餿¥å¿ |
| | | //Log.CloseAndFlush(); |
| | | }); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Autofac; |
| | | using Autofac.Extras.DynamicProxy; |
| | | using Microsoft.Extensions.DependencyModel; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Runtime.Loader; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.AOP; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | |
| | | namespace WIDESEAWCS_Core.Extensions |
| | | { |
| | | public class AutofacModuleRegister : Autofac.Module |
| | | { |
| | | protected override void Load(ContainerBuilder builder) |
| | | { |
| | | var basePath = AppContext.BaseDirectory; |
| | | var cacheType = new List<Type>(); |
| | | |
| | | //builder.RegisterType<LogAOP>(); |
| | | //cacheType.Add(typeof(LogAOP)); |
| | | |
| | | builder.RegisterGeneric(typeof(RepositoryBase<>)).As(typeof(IRepository<>)).InstancePerDependency();//注åä»å¨ |
| | | builder.RegisterGeneric(typeof(ServiceBase<,>)).As(typeof(IService<>)).InstancePerDependency();//注åæå¡ |
| | | |
| | | Type baseType = typeof(IDependency); |
| | | |
| | | List<RuntimeLibrary> compilationLibrary = DependencyContext.Default |
| | | .RuntimeLibraries |
| | | .Where(x => !x.Serviceable |
| | | && x.Type == "project") |
| | | .ToList(); |
| | | List<Assembly> assemblyList = new List<Assembly>(); |
| | | foreach (var library in compilationLibrary) |
| | | { |
| | | try |
| | | { |
| | | string path = Path.Combine(basePath, $"{library.Name}.dll"); |
| | | if (!File.Exists(path)) |
| | | { |
| | | var msg = $"{library.Name}.dll丢失ï¼å 为项ç®è§£è¦äºï¼æä»¥éè¦å
F6ç¼è¯ï¼åF5è¿è¡ï¼è¯·æ£æ¥ bin æä»¶å¤¹ï¼å¹¶æ·è´ã"; |
| | | //log.Error(msg); |
| | | throw new Exception(msg); |
| | | } |
| | | assemblyList.Add(Assembly.LoadFrom(path)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine(library.Name + ex.Message); |
| | | } |
| | | } |
| | | |
| | | builder.RegisterAssemblyTypes(assemblyList.ToArray()).Where(x => !x.IsInterface && !x.IsAbstract && baseType.IsAssignableFrom(x)) |
| | | .AsImplementedInterfaces() |
| | | .PropertiesAutowired() |
| | | .InstancePerDependency(). |
| | | EnableInterfaceInterceptors() |
| | | .InterceptedBy(cacheType.ToArray()); |
| | | |
| | | builder.RegisterType<UnitOfWorkManage>().As<IUnitOfWorkManage>() |
| | | .AsImplementedInterfaces() |
| | | .InstancePerLifetimeScope() |
| | | .PropertiesAutowired(); |
| | | |
| | | builder.RegisterType<RequestLogModel>().InstancePerLifetimeScope(); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | |
| | | namespace WIDESEAWCS_Core.Extensions |
| | | { |
| | | /// <summary> |
| | | /// Cors è·¨å |
| | | /// </summary> |
| | | public static class CorsSetup |
| | | { |
| | | /// <summary> |
| | | /// è·¨å |
| | | /// </summary> |
| | | /// <param name="services"></param> |
| | | /// <exception cref="ArgumentNullException"></exception> |
| | | public static void AddCorsSetup(this IServiceCollection services) |
| | | { |
| | | if (services == null) throw new ArgumentNullException(nameof(services)); |
| | | |
| | | services.AddCors(c => |
| | | { |
| | | if (!AppSettings.app(new string[] { "Cors", "EnableAllIPs" }).ObjToBool()) |
| | | { |
| | | c.AddPolicy(AppSettings.app(new string[] {"Cors", "PolicyName" }), |
| | | |
| | | policy => |
| | | { |
| | | policy |
| | | .WithOrigins(AppSettings.app(new string[] { "Cors", "IPs" }).Split(',')) |
| | | .AllowAnyHeader()//Ensures that the policy allows any header. |
| | | .AllowAnyMethod(); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | //å
许任æè·¨åè¯·æ± |
| | | c.AddPolicy(AppSettings.app(new string[] { "Cors", "PolicyName" }), |
| | | policy => |
| | | { |
| | | policy |
| | | .SetIsOriginAllowed((host) => true) |
| | | .AllowAnyMethod() |
| | | .AllowAnyHeader() |
| | | .AllowCredentials(); |
| | | }); |
| | | } |
| | | |
| | | }); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Seed; |
| | | |
| | | namespace WIDESEAWCS_Core |
| | | { |
| | | /// <summary> |
| | | /// Db å¯å¨æå¡ |
| | | /// </summary> |
| | | public static class DbSetup |
| | | { |
| | | public static void AddDbSetup(this IServiceCollection services) |
| | | { |
| | | if (services == null) throw new ArgumentNullException(nameof(services)); |
| | | |
| | | services.AddScoped<DBSeed>(); |
| | | services.AddScoped<DBContext>(); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.HttpContextUser; |
| | | |
| | | namespace WIDESEAWCS_Core.Extensions |
| | | { |
| | | /// <summary> |
| | | /// HttpContext ç¸å
³æå¡ |
| | | /// </summary> |
| | | public static class HttpContextSetup |
| | | { |
| | | /// <summary> |
| | | /// HttpContext ç¸å
³æå¡ |
| | | /// </summary> |
| | | /// <param name="services"></param> |
| | | /// <exception cref="ArgumentNullException"></exception> |
| | | public static void AddHttpContextSetup(this IServiceCollection services) |
| | | { |
| | | if (services == null) throw new ArgumentNullException(nameof(services)); |
| | | |
| | | services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); |
| | | services.AddScoped<IUser, AspNetUser>(); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Extensions |
| | | { |
| | | public static class InitializationHostServiceSetup |
| | | { |
| | | /// <summary> |
| | | /// åºç¨åå§åæå¡æ³¨å
¥ |
| | | /// </summary> |
| | | /// <param name="services"></param> |
| | | public static void AddInitializationHostServiceSetup(this IServiceCollection services) |
| | | { |
| | | if (services is null) |
| | | { |
| | | ArgumentNullException.ThrowIfNull(nameof(services)); |
| | | } |
| | | services.AddHostedService<SeedDataHostedService>(); |
| | | //services.AddHostedService<QuartzJobHostedService>(); |
| | | //services.AddHostedService<ConsulHostedService>(); |
| | | //services.AddHostedService<EventBusHostedService>(); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.Extensions.Configuration; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Extensions |
| | | { |
| | | /// <summary> |
| | | /// IPLimitéæµ å¯å¨æå¡ |
| | | /// </summary> |
| | | public static class IpPolicyRateLimitSetup |
| | | { |
| | | public static void AddIpPolicyRateLimitSetup(this IServiceCollection services, IConfiguration Configuration) |
| | | { |
| | | if (services == null) throw new ArgumentNullException(nameof(services)); |
| | | |
| | | // needed to store rate limit counters and ip rules |
| | | //services.AddMemoryCache(); |
| | | |
| | | //load general configuration from appsettings.json |
| | | //services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimiting")); |
| | | |
| | | // inject counter and rules stores |
| | | //services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>(); |
| | | //services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>(); |
| | | //services.AddSingleton<IProcessingStrategy, AsyncKeyLockProcessingStrategy>(); |
| | | |
| | | // inject counter and rules distributed cache stores |
| | | //services.AddSingleton<IIpPolicyStore, DistributedCacheIpPolicyStore>(); |
| | | //services.AddSingleton<IRateLimitCounterStore, DistributedCacheRateLimitCounterStore>(); |
| | | |
| | | // the clientId/clientIp resolvers use it. |
| | | //services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); |
| | | |
| | | // configuration (resolvers, counter key builders) |
| | | //services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>(); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.Caching.Memory; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Microsoft.Extensions.Options; |
| | | using System; |
| | | using WIDESEAWCS_Core.Caches; |
| | | |
| | | namespace WIDESEAWCS_Core.Extensions |
| | | { |
| | | /// <summary> |
| | | /// Memoryç¼å å¯å¨æå¡ |
| | | /// </summary> |
| | | public static class MemoryCacheSetup |
| | | { |
| | | public static void AddMemoryCacheSetup(this IServiceCollection services) |
| | | { |
| | | if (services == null) throw new ArgumentNullException(nameof(services)); |
| | | |
| | | |
| | | services.AddSingleton<ICacheService, MemoryCacheService>(); |
| | | services.AddMemoryCache(); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | |
| | | namespace WIDESEAWCS_Core.Extensions |
| | | { |
| | | /// <summary> |
| | | /// MiniProfiler æ§è½åæ |
| | | /// </summary> |
| | | public static class MiniProfilerSetup |
| | | { |
| | | /// <summary> |
| | | /// æ§è½åæ |
| | | /// </summary> |
| | | /// <param name="services"></param> |
| | | /// <exception cref="ArgumentNullException"></exception> |
| | | public static void AddMiniProfilerSetup(this IServiceCollection services) |
| | | { |
| | | if (services == null) throw new ArgumentNullException(nameof(services)); |
| | | //if (AppSettings.app(new string[] { "Startup", "MiniProfiler", "Enabled" }).ObjToBool()) |
| | | //{ |
| | | services.AddMiniProfiler(options => |
| | | { |
| | | options.RouteBasePath = "/profiler"; |
| | | }); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.Caching.Memory; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using SqlSugar; |
| | | using StackExchange.Profiling; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.AOP; |
| | | using WIDESEAWCS_Core.DB; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | using WIDESEAWCS_Core.Seed; |
| | | |
| | | namespace WIDESEAWCS_Core |
| | | { |
| | | /// <summary> |
| | | /// SqlSugar å¯å¨æå¡ |
| | | /// </summary> |
| | | public static class SqlsugarSetup |
| | | { |
| | | private static readonly MemoryCache Cache = new MemoryCache(new MemoryCacheOptions()); |
| | | |
| | | public static void AddSqlsugarSetup(this IServiceCollection services) |
| | | { |
| | | if (services == null) throw new ArgumentNullException(nameof(services)); |
| | | |
| | | // é»è®¤æ·»å ä¸»æ°æ®åºè¿æ¥ |
| | | //MainDb.CurrentDbConnId = AppSettings.app(new string[] { "MainDB" }); |
| | | services.AddHttpContextAccessor(); |
| | | // SqlSugarScopeæ¯çº¿ç¨å®å
¨ï¼å¯ä½¿ç¨å便³¨å
¥ |
| | | // åèï¼https://www.donet5.com/Home/Doc?typeId=1181 |
| | | services.AddSingleton<ISqlSugarClient>(o => |
| | | { |
| | | var memoryCache = o.GetRequiredService<IMemoryCache>(); |
| | | |
| | | // è¿æ¥å符串 |
| | | var listConfig = new List<ConnectionConfig> |
| | | { |
| | | new ConnectionConfig |
| | | { |
| | | ConfigId = MainDb.CurrentDbConnId, |
| | | ConnectionString = DBContext.GetMainConnectionDb().Connection, |
| | | IsAutoCloseConnection = true, |
| | | DbType = MainDb.DbType, |
| | | AopEvents = new AopEvents |
| | | { |
| | | OnLogExecuting = (sql, p) => |
| | | { |
| | | Parallel.For(0, 1, e => |
| | | { |
| | | MiniProfiler.Current.CustomTiming("SQLï¼", GetParas(p) + "ãSQLè¯å¥ãï¼" + sql); |
| | | }); |
| | | //Console.Out.WriteLine(GetParas(p)); |
| | | //Console.Out.WriteLine(sql); |
| | | //Console.Out.WriteLine(); |
| | | } |
| | | }, |
| | | } |
| | | }; |
| | | #region ä»åº |
| | | //var listConfig_Slave = new List<SlaveConnectionConfig>(); |
| | | //BaseDBConfig.MutiConnectionString.ForEach(s => |
| | | //{ |
| | | // if(s.ConnId != MainDb.CurrentDbConnId) |
| | | // { |
| | | // listConfig_Slave.Add(new SlaveConnectionConfig() |
| | | // { |
| | | // HitRate = s.HitRate, |
| | | // ConnectionString = s.Connection |
| | | // }); |
| | | // } |
| | | |
| | | //}); |
| | | |
| | | //BaseDBConfig.MutiConnectionString.ForEach(m => |
| | | //{ |
| | | // listConfig.Add(new ConnectionConfig() |
| | | // { |
| | | // ConfigId = m.ConnId.ObjToString().ToLower(), |
| | | // ConnectionString = m.Connection, |
| | | // DbType = (DbType)m.DbType, |
| | | // IsAutoCloseConnection = true, |
| | | // MoreSettings = new ConnMoreSettings() |
| | | // { |
| | | // //IsWithNoLockQuery = true, |
| | | // IsAutoRemoveDataCache = true |
| | | // }, |
| | | // // ä»åº |
| | | // //SlaveConnectionConfigs = listConfig_Slave, |
| | | // // èªå®ä¹ç¹æ§ |
| | | // ConfigureExternalServices = new ConfigureExternalServices() |
| | | // { |
| | | // DataInfoCacheService = new SqlSugarMemoryCacheService(memoryCache), |
| | | // EntityService = (property, column) => |
| | | // { |
| | | // if (column.IsPrimarykey && property.PropertyType == typeof(int)) |
| | | // { |
| | | // column.IsIdentity = true; |
| | | // } |
| | | // } |
| | | // }, |
| | | // InitKeyType = InitKeyType.Attribute, |
| | | // AopEvents = new AopEvents() |
| | | // { |
| | | // OnError = x => |
| | | // { |
| | | // Console.WriteLine(x.Sql); |
| | | // } |
| | | // } |
| | | // } |
| | | // ); |
| | | //}); |
| | | #endregion |
| | | |
| | | SqlSugarScope sqlSugarClient = new SqlSugarScope(listConfig, db => |
| | | { |
| | | db.Aop.DataExecuting = SqlSugarAop.DataExecuting; |
| | | }); |
| | | return sqlSugarClient; |
| | | }); |
| | | } |
| | | |
| | | private static string GetWholeSql(SugarParameter[] paramArr, string sql) |
| | | { |
| | | foreach (var param in paramArr) |
| | | { |
| | | sql.Replace(param.ParameterName, param.Value.ObjToString()); |
| | | } |
| | | |
| | | return sql; |
| | | } |
| | | |
| | | private static string GetParas(SugarParameter[] pars) |
| | | { |
| | | string key = "ãSQLåæ°ãï¼"; |
| | | foreach (var param in pars) |
| | | { |
| | | key += $"{param.ParameterName}:{param.Value}\n"; |
| | | } |
| | | |
| | | return key; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | |  |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Microsoft.OpenApi.Models; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Runtime.InteropServices; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using static WIDESEAWCS_Core.Extensions.CustomApiVersion; |
| | | using Swashbuckle.AspNetCore.Filters; |
| | | using Microsoft.Extensions.Logging; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; |
| | | |
| | | namespace WIDESEAWCS_Core.Extensions |
| | | { |
| | | /// <summary> |
| | | /// Swagger |
| | | /// </summary> |
| | | public static class SwaggerSetup |
| | | { |
| | | /// <summary> |
| | | /// Swagger |
| | | /// </summary> |
| | | /// <param name="services"></param> |
| | | /// <exception cref="ArgumentNullException"></exception> |
| | | public static void AddSwaggerSetup(this IServiceCollection services) |
| | | { |
| | | if (services == null) throw new ArgumentNullException(nameof(services)); |
| | | |
| | | var basePath = AppContext.BaseDirectory; |
| | | //var basePath2 = Microsoft.DotNet.PlatformAbstractions.ApplicationEnvironment.ApplicationBasePath; |
| | | var ApiName = AppSettings.app(new string[] { "ApiName" }); |
| | | |
| | | services.AddSwaggerGen(c => |
| | | { |
| | | //éååºå
¨é¨ççæ¬ï¼åææ¡£ä¿¡æ¯å±ç¤º |
| | | typeof(ApiVersions).GetEnumNames().ToList().ForEach(version => |
| | | { |
| | | c.SwaggerDoc(version, new OpenApiInfo |
| | | { |
| | | Version = version, |
| | | Title = $"{ApiName} æ¥å£ææ¡£ââ{RuntimeInformation.FrameworkDescription}", |
| | | Description = $"{ApiName} HTTP API " + version, |
| | | }); |
| | | c.OrderActionsBy(o => o.RelativePath); |
| | | }); |
| | | |
| | | c.UseInlineDefinitionsForEnums(); |
| | | try |
| | | { |
| | | //è¿ä¸ªå°±æ¯ååé
ç½®çxmlæä»¶å |
| | | //var xmlPath = Path.Combine(basePath, "WIDESEAWCS_Server.xml"); |
| | | //é»è®¤ç第äºä¸ªåæ°æ¯falseï¼è¿ä¸ªæ¯controllerçæ³¨éï¼è®°å¾ä¿®æ¹ |
| | | //c.IncludeXmlComments(xmlPath, true); |
| | | |
| | | //è¿ä¸ªå°±æ¯Modelå±çxmlæä»¶å |
| | | //var xmlModelPath = Path.Combine(basePath, "WIDESEAWCS_Server.Model.xml"); |
| | | //c.IncludeXmlComments(xmlModelPath); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //log.Error("Blog.Core.xmlåBlog.Core.Model.xml 丢失ï¼è¯·æ£æ¥å¹¶æ·è´ã\n" + ex.Message); |
| | | } |
| | | |
| | | // å¼å¯å æå°é |
| | | c.OperationFilter<AddResponseHeadersFilter>(); |
| | | c.OperationFilter<AppendAuthorizeToSummaryOperationFilter>(); |
| | | |
| | | // å¨header䏿·»å tokenï¼ä¼ éå°åå° |
| | | c.OperationFilter<SecurityRequirementsOperationFilter>(); |
| | | |
| | | c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme |
| | | { |
| | | Description = "JWTæætokenåé¢éè¦å ä¸å段Bearerä¸ä¸ä¸ªç©ºæ ¼,å¦Bearer token", |
| | | Name = "Authorization", |
| | | In = ParameterLocation.Header, |
| | | Type = SecuritySchemeType.ApiKey, |
| | | BearerFormat = "JWT", |
| | | Scheme = "Bearer" |
| | | }); |
| | | |
| | | c.AddSecurityRequirement(new OpenApiSecurityRequirement |
| | | { |
| | | { |
| | | new OpenApiSecurityScheme |
| | | { |
| | | Reference = new OpenApiReference { |
| | | Type = ReferenceType.SecurityScheme, |
| | | Id = "Bearer" |
| | | } |
| | | }, |
| | | new string[] { } |
| | | } |
| | | }); |
| | | }).AddControllers() |
| | | .ConfigureApiBehaviorOptions(options => |
| | | { |
| | | options.SuppressConsumesConstraintForFormFileParameters = true; |
| | | options.SuppressInferBindingSourcesForParameters = true; |
| | | options.SuppressModelStateInvalidFilter = true; |
| | | options.SuppressMapClientErrors = true; |
| | | options.ClientErrorMapping[404].Link = |
| | | "https://*/404"; |
| | | }); |
| | | //services.AddSwaggerGenNewtonsoftSupport(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// èªå®ä¹çæ¬ |
| | | /// </summary> |
| | | public class CustomApiVersion |
| | | { |
| | | /// <summary> |
| | | /// Apiæ¥å£çæ¬ èªå®ä¹ |
| | | /// </summary> |
| | | public enum ApiVersions |
| | | { |
| | | /// <summary> |
| | | /// V1 çæ¬ |
| | | /// </summary> |
| | | V1 = 1, |
| | | /// <summary> |
| | | /// V2 çæ¬ |
| | | /// </summary> |
| | | V2 = 2, |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Microsoft.AspNetCore.Mvc.Filters; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Filter |
| | | { |
| | | public class ActionExecuteFilter : IActionFilter |
| | | { |
| | | public void OnActionExecuted(ActionExecutedContext context) |
| | | { |
| | | //throw new NotImplementedException(); |
| | | } |
| | | |
| | | public void OnActionExecuting(ActionExecutingContext context) |
| | | { |
| | | //throw new NotImplementedException(); |
| | | //foreach (KeyValuePair<string, object?> item in context.ActionArguments) |
| | | //{ |
| | | // if (item.Value != null) |
| | | // { |
| | | // string name = item.Value.GetType().Name; |
| | | // Console.Out.WriteLine(name); |
| | | // } |
| | | // else |
| | | // { |
| | | // context.Result = new JsonResult(new { Status = false, Message = "åæ°ä¸è½ä¸ºç©º" }); |
| | | // return; |
| | | // } |
| | | //} |
| | | |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Authorization; |
| | | using Microsoft.AspNetCore.Mvc.Filters; |
| | | using Microsoft.Extensions.Hosting; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IdentityModel.Tokens.Jwt; |
| | | using System.Linq; |
| | | using System.Runtime; |
| | | using System.Security.Claims; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Authorization; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.Helper; |
| | | |
| | | namespace WIDESEAWCS_Core.Filter |
| | | { |
| | | /// <summary> |
| | | /// 夿tokenæ¯å¦æ£ç¡® |
| | | /// </summary> |
| | | public class ApiAuthorizeFilter : IAuthorizationFilter |
| | | { |
| | | private static readonly string replaceTokenPath = "/api/User/replaceToken"; |
| | | private static readonly string loginPath = "/api/User/login"; |
| | | private static readonly string vierificationCodePath = "/api/User/getVierificationCode"; |
| | | |
| | | public ApiAuthorizeFilter() |
| | | { |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åªå¤ætokenæ¯å¦æ£ç¡®ï¼ä¸å¤ææé |
| | | /// 妿éè¦å¤ææéçå¨Actionä¸å ä¸ApiActionPermission屿§æ è¯æéç±»å«ï¼ActionPermissionFilter使éå¤ç |
| | | ///(string,string,string)1ã请æ±åæ°,2ãè¿åæ¶æ¯ï¼3,å¼å¸¸æ¶æ¯,4ç¶æ |
| | | /// </summary> |
| | | /// <param name="context"></param> |
| | | public void OnAuthorization(AuthorizationFilterContext context) |
| | | { |
| | | //if (!App.HostEnvironment.IsProduction() || context.HttpContext.Request.Path.Value == loginPath || context.HttpContext.Request.Path.Value == vierificationCodePath) |
| | | { |
| | | if (context.ActionDescriptor.EndpointMetadata.Any(item => item is IAllowAnonymous)) |
| | | { |
| | | //å¦æä½¿ç¨äºåºå®Tokenä¸è¿æï¼ç´æ¥å¯¹tokençåæ³æ§åtokenæ¯å¦åå¨è¿è¡éªè¯ |
| | | //if (context.Filters |
| | | // .Where(item => item is IFixedTokenFilter) |
| | | // .FirstOrDefault() is IFixedTokenFilter tokenFilter) |
| | | //{ |
| | | // tokenFilter.OnAuthorization(context); |
| | | // return; |
| | | //} |
| | | //å¿åå¹¶ä¼ å
¥äºtokenï¼éè¦å°ç¨æ·çIDç¼åèµ·æ¥ï¼ä¿è¯UserHelperéè½æ£ç¡®è·åå°ç¨æ·ä¿¡æ¯ |
| | | if (!context.HttpContext.User.Identity?.IsAuthenticated ?? false |
| | | && !string.IsNullOrEmpty(context.HttpContext.Request.Headers[AppSecret.TokenHeaderName])) |
| | | { |
| | | context.AddIdentity(); |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | //else |
| | | //{ |
| | | // if (!context.HttpContext.User.Identity.IsAuthenticated |
| | | // || !context.HttpContext.Request.Headers.ContainsKey(AppSecret.TokenHeaderName)) |
| | | // { |
| | | // context.Unauthorized("æªææ"); |
| | | // return; |
| | | // } |
| | | //} |
| | | |
| | | #region åç¹ç»å½ |
| | | if (string.IsNullOrEmpty(App.User.Token)) |
| | | { |
| | | if (!string.IsNullOrEmpty(context.HttpContext.Request.Headers[AppSecret.TokenHeaderName].ObjToString().Replace("Bearer ", ""))) |
| | | { |
| | | DateTime? expDate = context.HttpContext.User.Claims.Where(x => x.Type == JwtRegisteredClaimNames.Exp).Select(x => x.Value).FirstOrDefault()?.GetTimeSpmpToDate(); |
| | | //卿æ è¯å·æ°token(2021.05.01) |
| | | int ExpMinutes = AppSettings.app("ExpMinutes").ObjToInt(); |
| | | if ((expDate.GetValueOrDefault() - DateTime.Now).TotalMinutes > ExpMinutes) |
| | | { |
| | | context.Unauthorized("ç»éå·²è¿æ"); |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | App.User.UpdateToke(context.HttpContext.Request.Headers[AppSecret.TokenHeaderName].ObjToString().Replace("Bearer ", "")); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | context.Unauthorized("ç»éå·²è¿æ"); |
| | | return; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (App.User.Token != ((ClaimsIdentity?)context.HttpContext.User.Identity)?.BootstrapContext?.ToString()) |
| | | { |
| | | context.Unauthorized("ç»éå·²è¿æ"); |
| | | return; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | { |
| | | DateTime? expDate = context.HttpContext.User.Claims.Where(x => x.Type == JwtRegisteredClaimNames.Exp) |
| | | .Select(x => x.Value).FirstOrDefault()?.GetTimeSpmpToDate(); |
| | | //卿æ è¯å·æ°token(2021.05.01) |
| | | int ExpMinutes = AppSettings.app("ExpMinutes").ObjToInt(); |
| | | if ((expDate.GetValueOrDefault() - DateTime.Now).TotalMinutes < ExpMinutes / 3 && context.HttpContext.Request.Path != replaceTokenPath) |
| | | { |
| | | context.HttpContext.Response.Headers.Add("wideseawcs_exp", "1"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Magicodes.ExporterAndImporter.Core.Filters; |
| | | using Magicodes.ExporterAndImporter.Core.Models; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Filter |
| | | { |
| | | public class ExporterHeaderFilter : IExporterHeaderFilter |
| | | { |
| | | /// <summary> |
| | | /// 表头çéå¨ï¼ä¿®æ¹åç§°ï¼ |
| | | /// </summary> |
| | | /// <param name="exporterHeaderInfo"></param> |
| | | /// <returns></returns> |
| | | public ExporterHeaderInfo Filter(ExporterHeaderInfo exporterHeaderInfo) |
| | | { |
| | | return exporterHeaderInfo; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Hosting; |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.AspNetCore.Mvc.Filters; |
| | | using Microsoft.AspNetCore.Mvc.Rendering; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Microsoft.AspNetCore.SignalR; |
| | | using Microsoft.Extensions.Logging; |
| | | using StackExchange.Profiling; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using System.Reflection.Metadata; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | |
| | | namespace WIDESEAWCS_Core.Filter |
| | | { |
| | | /// <summary> |
| | | /// å
¨å±å¼å¸¸é误æ¥å¿ |
| | | /// </summary> |
| | | public class GlobalExceptionsFilter : IExceptionFilter |
| | | { |
| | | private readonly IWebHostEnvironment _env; |
| | | private readonly ILogger<GlobalExceptionsFilter> _loggerHelper; |
| | | |
| | | public GlobalExceptionsFilter(IWebHostEnvironment env, ILogger<GlobalExceptionsFilter> loggerHelper) |
| | | { |
| | | _env = env; |
| | | _loggerHelper = loggerHelper; |
| | | } |
| | | |
| | | public void OnException(ExceptionContext context) |
| | | { |
| | | var json = new WebResponseContent(); |
| | | |
| | | json.Message = context.Exception.Message;//éè¯¯ä¿¡æ¯ |
| | | json.Code = 500;//500å¼å¸¸ |
| | | var errorAudit = "Unable to resolve service for"; |
| | | if (!string.IsNullOrEmpty(json.Message) && json.Message.Contains(errorAudit)) |
| | | { |
| | | json.Message = json.Message.Replace(errorAudit, $"ï¼è¥æ°æ·»å æå¡ï¼éè¦éæ°ç¼è¯é¡¹ç®ï¼{errorAudit}"); |
| | | } |
| | | |
| | | if (_env.EnvironmentName.ObjToString().Equals("Development")) |
| | | { |
| | | json.DevMessage = context.Exception.StackTrace;//å æ ä¿¡æ¯ |
| | | } |
| | | var res = new ContentResult(); |
| | | res.Content = json.Serialize(); |
| | | |
| | | context.Result = res; |
| | | MiniProfiler.Current.CustomTiming("Errorsï¼", json.Message); |
| | | |
| | | LogLock.OutLogAOP("å
¨å±å¼å¸¸é误æ¥å¿", new string[] { json.Message + WriteLog(json.Message, context.Exception) }); |
| | | //éç¨log4net è¿è¡é误æ¥å¿è®°å½ |
| | | //_loggerHelper.LogError(json.Message + WriteLog(json.Message, context.Exception)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// èªå®ä¹è¿åæ ¼å¼ |
| | | /// </summary> |
| | | /// <param name="throwMsg"></param> |
| | | /// <param name="ex"></param> |
| | | /// <returns></returns> |
| | | public string WriteLog(string throwMsg, Exception ex) |
| | | { |
| | | return string.Format("\r\nãèªå®ä¹é误ãï¼{0} \r\nãå¼å¸¸ç±»åãï¼{1} \r\nãå¼å¸¸ä¿¡æ¯ãï¼{2} \r\nãå æ è°ç¨ãï¼{3}", new object[] { throwMsg, |
| | | ex.GetType().Name, ex.Message, ex.StackTrace }); |
| | | } |
| | | |
| | | } |
| | | public class InternalServerErrorObjectResult : ObjectResult |
| | | { |
| | | public InternalServerErrorObjectResult(object value) : base(value) |
| | | { |
| | | StatusCode = StatusCodes.Status500InternalServerError; |
| | | } |
| | | } |
| | | //è¿åéè¯¯ä¿¡æ¯ |
| | | public class JsonErrorResponse |
| | | { |
| | | /// <summary> |
| | | /// ç产ç¯å¢çæ¶æ¯ |
| | | /// </summary> |
| | | public string Message { get; set; } |
| | | /// <summary> |
| | | /// å¼åç¯å¢çæ¶æ¯ |
| | | /// </summary> |
| | | public string DevelopmentMessage { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Mvc.Filters; |
| | | using Microsoft.Extensions.Logging; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Filter |
| | | { |
| | | public class UseServiceDIAttribute : ActionFilterAttribute |
| | | { |
| | | |
| | | protected readonly ILogger<UseServiceDIAttribute> _logger; |
| | | //private readonly IBlogArticleServices _blogArticleServices; |
| | | private readonly string _name; |
| | | |
| | | public UseServiceDIAttribute(ILogger<UseServiceDIAttribute> logger/*, IBlogArticleServices blogArticleServices*/, string Name = "") |
| | | { |
| | | _logger = logger; |
| | | /*_blogArticleServices = blogArticleServices;*/ |
| | | _name = Name; |
| | | } |
| | | |
| | | |
| | | public override void OnActionExecuted(ActionExecutedContext context) |
| | | { |
| | | //var dd =await _blogArticleServices.Query(); |
| | | base.OnActionExecuted(context); |
| | | DeleteSubscriptionFiles(); |
| | | } |
| | | |
| | | private void DeleteSubscriptionFiles() |
| | | { |
| | | |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.Extensions.Configuration.Json; |
| | | using Microsoft.Extensions.Configuration; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Helper |
| | | { |
| | | /// <summary> |
| | | /// appsettings.jsonæä½ç±» |
| | | /// </summary> |
| | | public class AppSettings |
| | | { |
| | | public static IConfiguration Configuration { get; set; } |
| | | static string contentPath { get; set; } |
| | | |
| | | public AppSettings(string contentPath) |
| | | { |
| | | string Path = "appsettings.json"; |
| | | |
| | | //å¦æä½ æé
ç½®æä»¶ æ¯ æ ¹æ®ç¯å¢å鿥åå¼äºï¼å¯ä»¥è¿æ ·å |
| | | //Path = $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json"; |
| | | |
| | | Configuration = new ConfigurationBuilder() |
| | | .SetBasePath(contentPath) |
| | | .Add(new JsonConfigurationSource { Path = Path, Optional = false, ReloadOnChange = true })//è¿æ ·çè¯ï¼å¯ä»¥ç´æ¥è¯»ç®å½éçjsonæä»¶ï¼è䏿¯ bin æä»¶å¤¹ä¸çï¼æä»¥ä¸ç¨ä¿®æ¹å¤å¶å±æ§ |
| | | .Build(); |
| | | } |
| | | |
| | | public AppSettings(IConfiguration configuration) |
| | | { |
| | | Configuration = configuration; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°è£
è¦æä½çå符 |
| | | /// </summary> |
| | | /// <param name="sections">èç¹é
ç½®</param> |
| | | /// <returns></returns> |
| | | public static string app(params string[] sections) |
| | | { |
| | | try |
| | | { |
| | | if (sections.Any()) |
| | | { |
| | | return Configuration[string.Join(":", sections)]; |
| | | } |
| | | } |
| | | catch (Exception) { } |
| | | |
| | | return ""; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éå½è·åé
ç½®ä¿¡æ¯æ°ç» |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="sections"></param> |
| | | /// <returns></returns> |
| | | public static List<T> app<T>(params string[] sections) |
| | | { |
| | | List<T> list = new List<T>(); |
| | | // å¼ç¨ Microsoft.Extensions.Configuration.Binder å
|
| | | Configuration.Bind(string.Join(":", sections), list); |
| | | return list; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è·¯å¾ configuration["App:Name"]; |
| | | /// </summary> |
| | | /// <param name="sectionsPath"></param> |
| | | /// <returns></returns> |
| | | public static string GetValue(string sectionsPath) |
| | | { |
| | | try |
| | | { |
| | | return Configuration[sectionsPath]; |
| | | } |
| | | catch (Exception) { } |
| | | |
| | | return ""; |
| | | |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Helper |
| | | { |
| | | public static class ConsoleHelper |
| | | { |
| | | private static readonly object _objLock = new(); |
| | | |
| | | /// <summary> |
| | | /// 卿§å¶å°è¾åº |
| | | /// </summary> |
| | | /// <param name="str">ææ¬</param> |
| | | /// <param name="color">åé¢è²</param> |
| | | public static void WriteColorLine(string str, ConsoleColor color) |
| | | { |
| | | lock (_objLock) |
| | | { |
| | | ConsoleColor currentForeColor = Console.ForegroundColor; |
| | | Console.ForegroundColor = color; |
| | | Console.WriteLine(str); |
| | | Console.ForegroundColor = currentForeColor; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 卿§å¶å°è¾åº |
| | | /// </summary> |
| | | /// <param name="str">ææ¬</param> |
| | | /// <param name="color">åé¢è²</param> |
| | | public static void WriteColorLine(object str, ConsoleColor color) |
| | | { |
| | | lock (_objLock) |
| | | { |
| | | ConsoleColor currentForeColor = Console.ForegroundColor; |
| | | Console.ForegroundColor = color; |
| | | Console.WriteLine(str); |
| | | Console.ForegroundColor = currentForeColor; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå°éè¯¯ä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="str">å¾
æå°çå符串</param> |
| | | /// <param name="color">æ³è¦æå°çé¢è²</param> |
| | | public static void WriteErrorLine(this string str, ConsoleColor color = ConsoleColor.Red) => WriteColorLine(str, color); |
| | | |
| | | /// <summary> |
| | | /// æå°è¦åä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="str">å¾
æå°çå符串</param> |
| | | /// <param name="color">æ³è¦æå°çé¢è²</param> |
| | | public static void WriteWarningLine(this string str, ConsoleColor color = ConsoleColor.Yellow) => WriteColorLine(str, color); |
| | | |
| | | /// <summary> |
| | | /// æå°æ£å¸¸ä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="str">å¾
æå°çå符串</param> |
| | | /// <param name="color">æ³è¦æå°çé¢è²</param> |
| | | public static void WriteInfoLine(this string str, ConsoleColor color = ConsoleColor.White) => WriteColorLine(str, color); |
| | | |
| | | /// <summary> |
| | | /// æå°æåçä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="str">å¾
æå°çå符串</param> |
| | | /// <param name="color">æ³è¦æå°çé¢è²</param> |
| | | public static void WriteSuccessLine(this string str, ConsoleColor color = ConsoleColor.Green) => WriteColorLine(str, color); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using Magicodes.ExporterAndImporter.Excel; |
| | | using Magicodes.IE.Core; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Reflection.Emit; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Helper |
| | | { |
| | | public static class ExportHelper |
| | | { |
| | | public static Type CreateDynamicClass(this PropertyInfo[] propertyInfos) |
| | | { |
| | | string className = "DynamicClass"; |
| | | AssemblyName assemblyName = new AssemblyName("WIDESEAWCS_Model.Models"); |
| | | AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);//å®ä¹å
·ææå®åç§°åè®¿é®æéç卿ç¨åºé |
| | | ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MainModule");//卿¤ç¨åºéä¸å®ä¹å½åçææ¶å¨ææ¨¡å |
| | | TypeBuilder typeBuilder = moduleBuilder.DefineType(className, TypeAttributes.Public);//TypeBuilder:å¨è¿è¡æ¶å®ä¹å¹¶åå»ºç±»çæ°å®ä¾ |
| | | |
| | | Type attributeType1 = typeof(ExcelExporterAttribute); |
| | | MethodInfo [] methodInfos = attributeType1.GetMethods(BindingFlags.Public); |
| | | ConstructorInfo[] constructorInfos2 = attributeType1.GetConstructors(); |
| | | ConstructorInfo constructorInfo2 = constructorInfos2[0]; |
| | | CustomAttributeBuilder customAttributeBuilder2 = new CustomAttributeBuilder(constructorInfo2, new object[] { }); |
| | | |
| | | typeBuilder.SetCustomAttribute(customAttributeBuilder2); |
| | | |
| | | foreach (var property in propertyInfos) |
| | | { |
| | | string propertyName = property.Name; |
| | | Type propertyType = property.PropertyType; |
| | | |
| | | FieldBuilder fieldBuilder = typeBuilder.DefineField("_" + propertyName, propertyType, FieldAttributes.Private); |
| | | PropertyBuilder propertyBuilder = typeBuilder.DefineProperty(propertyName, PropertyAttributes.HasDefault, propertyType, null); |
| | | |
| | | SugarColumn sugarColumn = property.GetCustomAttribute<SugarColumn>(); |
| | | if (sugarColumn != null) |
| | | { |
| | | Type attributeType = typeof(ExporterHeaderAttribute); |
| | | ConstructorInfo[] constructorInfos = attributeType.GetConstructors(); |
| | | ConstructorInfo constructorInfo = constructorInfos[0]; |
| | | CustomAttributeBuilder customAttributeBuilder = new CustomAttributeBuilder(constructorInfo, new object[] { sugarColumn.ColumnDescription, 11f, null, false, true, true, 0, KnownColor.Empty }); |
| | | propertyBuilder.SetCustomAttribute(customAttributeBuilder); |
| | | } |
| | | |
| | | MethodAttributes getSetAttributes = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig; |
| | | |
| | | MethodBuilder getMethodBuilder = typeBuilder.DefineMethod("get_" + propertyName, getSetAttributes, propertyType, Type.EmptyTypes); |
| | | ILGenerator getIL = getMethodBuilder.GetILGenerator(); |
| | | getIL.Emit(OpCodes.Ldarg_0); |
| | | getIL.Emit(OpCodes.Ldfld, fieldBuilder); |
| | | getIL.Emit(OpCodes.Ret); |
| | | |
| | | MethodBuilder setMethodBuilder = typeBuilder.DefineMethod("set_" + propertyName, getSetAttributes, null, new Type[] { propertyType }); |
| | | ILGenerator setIL = setMethodBuilder.GetILGenerator(); |
| | | setIL.Emit(OpCodes.Ldarg_0); |
| | | setIL.Emit(OpCodes.Ldarg_1); |
| | | setIL.Emit(OpCodes.Stfld, fieldBuilder); |
| | | setIL.Emit(OpCodes.Ret); |
| | | |
| | | propertyBuilder.SetGetMethod(getMethodBuilder); |
| | | propertyBuilder.SetSetMethod(setMethodBuilder); |
| | | |
| | | |
| | | } |
| | | |
| | | Type generatedType = typeBuilder.CreateType(); |
| | | return generatedType; |
| | | } |
| | | |
| | | public static void SetProperty(object instance, string propertyName, object value) |
| | | { |
| | | Type type = instance.GetType(); |
| | | PropertyInfo propertyInfo = type.GetProperty(propertyName); |
| | | propertyInfo.SetValue(instance, value); |
| | | } |
| | | |
| | | public static object GetProperty(object instance, string propertyName) |
| | | { |
| | | Type type = instance.GetType(); |
| | | PropertyInfo propertyInfo = type.GetProperty(propertyName); |
| | | return propertyInfo.GetValue(instance); |
| | | } |
| | | |
| | | public static void SetValue<T>(object instance, T value) |
| | | { |
| | | Type type = instance.GetType(); |
| | | |
| | | PropertyInfo[] propertyInfos = typeof(T).GetProperties(); |
| | | for (int j = 0; j < propertyInfos.Length; j++) |
| | | { |
| | | PropertyInfo propertyInfo = type.GetProperty(propertyInfos[j].Name); |
| | | object obj = propertyInfos[j].GetValue(value); |
| | | propertyInfo.SetValue(instance, obj); |
| | | ExporterHeaderAttribute exporterHeaderAttribute = propertyInfo.GetCustomAttribute<ExporterHeaderAttribute>(); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Helper |
| | | { |
| | | public class FileHelper : IDisposable |
| | | { |
| | | |
| | | private bool _alreadyDispose = false; |
| | | |
| | | #region æé 彿° |
| | | public FileHelper() |
| | | { |
| | | |
| | | } |
| | | ~FileHelper() |
| | | { |
| | | Dispose(); ; |
| | | } |
| | | |
| | | protected virtual void Dispose(bool isDisposing) |
| | | { |
| | | if (_alreadyDispose) return; |
| | | _alreadyDispose = true; |
| | | } |
| | | #endregion |
| | | |
| | | #region IDisposable æå |
| | | |
| | | public void Dispose() |
| | | { |
| | | Dispose(true); |
| | | GC.SuppressFinalize(this); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region å徿件åç¼å |
| | | /**************************************** |
| | | * 彿°åç§°ï¼GetPostfixStr |
| | | * åè½è¯´æï¼å徿件åç¼å |
| | | * å æ°ï¼filename:æä»¶åç§° |
| | | * è°ç¨ç¤ºåï¼ |
| | | * string filename = "aaa.aspx"; |
| | | * string s = EC.FileObj.GetPostfixStr(filename); |
| | | *****************************************/ |
| | | /// <summary> |
| | | /// ååç¼å |
| | | /// </summary> |
| | | /// <param name="filename">æä»¶å</param> |
| | | /// <returns>.gif|.htmlæ ¼å¼</returns> |
| | | public static string GetPostfixStr(string filename) |
| | | { |
| | | int start = filename.LastIndexOf("."); |
| | | int length = filename.Length; |
| | | string postfix = filename.Substring(start, length - start); |
| | | return postfix; |
| | | } |
| | | #endregion |
| | | |
| | | #region æ ¹æ®æä»¶å¤§å°è·åæå®åç¼çå¯ç¨æä»¶å |
| | | /// <summary> |
| | | /// æ ¹æ®æä»¶å¤§å°è·åæå®åç¼çå¯ç¨æä»¶å |
| | | /// </summary> |
| | | /// <param name="folderPath">æä»¶å¤¹</param> |
| | | /// <param name="prefix">æä»¶åç¼</param> |
| | | /// <param name="size">æä»¶å¤§å°(1m)</param> |
| | | /// <param name="ext">æä»¶åç¼(.log)</param> |
| | | /// <returns>å¯ç¨æä»¶å</returns> |
| | | public static string GetAvailableFileWithPrefixOrderSize(string folderPath, string prefix, int size = 1 * 1024 * 1024, string ext = ".log") |
| | | { |
| | | var allFiles = new DirectoryInfo(folderPath); |
| | | var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(prefix.ToLower()) && fi.Extension.ToLower() == ext.ToLower() && fi.Length < size).OrderByDescending(d => d.Name).ToList(); |
| | | |
| | | if (selectFiles.Count > 0) |
| | | { |
| | | return selectFiles.FirstOrDefault().FullName; |
| | | } |
| | | |
| | | return Path.Combine(folderPath, $@"{prefix}_{DateTime.Now.DateToTimeStamp()}.log"); |
| | | } |
| | | public static string GetAvailableFileNameWithPrefixOrderSize(string _contentRoot, string prefix, int size = 1 * 1024 * 1024, string ext = ".log") |
| | | { |
| | | var folderPath = Path.Combine(_contentRoot, "Log"); |
| | | if (!Directory.Exists(folderPath)) |
| | | { |
| | | Directory.CreateDirectory(folderPath); |
| | | } |
| | | |
| | | var allFiles = new DirectoryInfo(folderPath); |
| | | var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(prefix.ToLower()) && fi.Extension.ToLower() == ext.ToLower() && fi.Length < size).OrderByDescending(d => d.Name).ToList(); |
| | | |
| | | if (selectFiles.Count > 0) |
| | | { |
| | | return selectFiles.FirstOrDefault().Name.Replace(".log", ""); |
| | | } |
| | | |
| | | return $@"{prefix}_{DateTime.Now.DateToTimeStamp()}"; |
| | | } |
| | | #endregion |
| | | |
| | | #region åæä»¶ |
| | | /**************************************** |
| | | * 彿°åç§°ï¼WriteFile |
| | | * åè½è¯´æï¼åæä»¶,ä¼è¦çæä»¥åçå
容 |
| | | * å æ°ï¼Path:æä»¶è·¯å¾,Strings:ææ¬å
容 |
| | | * è°ç¨ç¤ºåï¼ |
| | | * string Path = Server.MapPath("Default2.aspx"); |
| | | * string Strings = "è¿æ¯æåçå
容å"; |
| | | * EC.FileObj.WriteFile(Path,Strings); |
| | | *****************************************/ |
| | | /// <summary> |
| | | /// åæä»¶ |
| | | /// </summary> |
| | | /// <param name="Path">æä»¶è·¯å¾</param> |
| | | /// <param name="Strings">æä»¶å
容</param> |
| | | public static void WriteFile(string Path, string Strings) |
| | | { |
| | | if (!File.Exists(Path)) |
| | | { |
| | | FileStream f = File.Create(Path); |
| | | f.Close(); |
| | | } |
| | | StreamWriter f2 = new StreamWriter(Path, false, System.Text.Encoding.UTF8); |
| | | f2.Write(Strings); |
| | | f2.Close(); |
| | | f2.Dispose(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åæä»¶ |
| | | /// </summary> |
| | | /// <param name="Path">æä»¶è·¯å¾</param> |
| | | /// <param name="Strings">æä»¶å
容</param> |
| | | public static void WriteFileAndDelOldFile(string Path, string Strings) |
| | | { |
| | | if (!File.Exists(Path)) |
| | | { |
| | | FileStream f = File.Create(Path); |
| | | f.Close(); |
| | | } |
| | | else |
| | | { |
| | | File.Delete(Path); |
| | | } |
| | | StreamWriter f2 = new StreamWriter(Path, false, System.Text.Encoding.UTF8); |
| | | f2.Write(Strings); |
| | | f2.Close(); |
| | | f2.Dispose(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åæä»¶ |
| | | /// </summary> |
| | | /// <param name="Path">æä»¶è·¯å¾</param> |
| | | /// <param name="Strings">æä»¶å
容</param> |
| | | public static void WriteFile(string Path, byte[] buf) |
| | | { |
| | | if (!File.Exists(Path)) |
| | | { |
| | | FileStream f = File.Create(Path); |
| | | f.Close(); |
| | | } |
| | | FileStream f2 = new FileStream(Path, FileMode.Create, FileAccess.Write); |
| | | f2.Write(buf, 0, buf.Length); |
| | | f2.Close(); |
| | | f2.Dispose(); |
| | | } |
| | | |
| | | public static void WriteFile(string Path, string fileName, byte[] buf) |
| | | { |
| | | if (!Directory.Exists(Path)) |
| | | { |
| | | Directory.CreateDirectory(Path); |
| | | } |
| | | if (!File.Exists(Path + "\\" + fileName)) |
| | | { |
| | | FileStream f = File.Create(Path + "\\" + fileName); |
| | | f.Close(); |
| | | } |
| | | FileStream f2 = new FileStream(Path + "\\" + fileName, FileMode.Create, FileAccess.Write); |
| | | f2.Write(buf, 0, buf.Length); |
| | | f2.Close(); |
| | | f2.Dispose(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åæä»¶ |
| | | /// </summary> |
| | | /// <param name="Path">æä»¶è·¯å¾</param> |
| | | /// <param name="Strings">æä»¶å
容</param> |
| | | /// <param name="encode">ç¼ç æ ¼å¼</param> |
| | | public static void WriteFile(string Path, string Strings, Encoding encode) |
| | | { |
| | | if (!File.Exists(Path)) |
| | | { |
| | | FileStream f = File.Create(Path); |
| | | f.Close(); |
| | | } |
| | | StreamWriter f2 = new StreamWriter(Path, false, encode); |
| | | f2.Write(Strings); |
| | | f2.Close(); |
| | | f2.Dispose(); |
| | | } |
| | | #endregion |
| | | |
| | | #region 读æä»¶ |
| | | /**************************************** |
| | | * 彿°åç§°ï¼ReadFile |
| | | * åè½è¯´æï¼è¯»åææ¬å
容 |
| | | * å æ°ï¼Path:æä»¶è·¯å¾ |
| | | * è°ç¨ç¤ºåï¼ |
| | | * string Path = Server.MapPath("Default2.aspx"); |
| | | * string s = EC.FileObj.ReadFile(Path); |
| | | *****************************************/ |
| | | /// <summary> |
| | | /// 读æä»¶ |
| | | /// </summary> |
| | | /// <param name="Path">æä»¶è·¯å¾</param> |
| | | /// <returns></returns> |
| | | public static string ReadFile(string Path) |
| | | { |
| | | string s = ""; |
| | | if (!File.Exists(Path)) |
| | | s = "ä¸åå¨ç¸åºçç®å½"; |
| | | else |
| | | { |
| | | StreamReader f2 = new StreamReader(Path, System.Text.Encoding.GetEncoding("gb2312")); |
| | | s = f2.ReadToEnd(); |
| | | f2.Close(); |
| | | f2.Dispose(); |
| | | } |
| | | |
| | | return s; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读æä»¶ |
| | | /// </summary> |
| | | /// <param name="Path">æä»¶è·¯å¾</param> |
| | | /// <param name="encode">ç¼ç æ ¼å¼</param> |
| | | /// <returns></returns> |
| | | public static string ReadFile(string Path, Encoding encode) |
| | | { |
| | | string s = ""; |
| | | if (!File.Exists(Path)) |
| | | s = "ä¸åå¨ç¸åºçç®å½"; |
| | | else |
| | | { |
| | | StreamReader f2 = new StreamReader(Path, encode); |
| | | s = f2.ReadToEnd(); |
| | | f2.Close(); |
| | | f2.Dispose(); |
| | | } |
| | | |
| | | return s; |
| | | } |
| | | #endregion |
| | | |
| | | #region è¿½å æä»¶ |
| | | /**************************************** |
| | | * 彿°åç§°ï¼FileAdd |
| | | * åè½è¯´æï¼è¿½å æä»¶å
容 |
| | | * å æ°ï¼Path:æä»¶è·¯å¾,strings:å
容 |
| | | * è°ç¨ç¤ºåï¼ |
| | | * string Path = Server.MapPath("Default2.aspx"); |
| | | * string Strings = "æ°è¿½å å
容"; |
| | | * EC.FileObj.FileAdd(Path, Strings); |
| | | *****************************************/ |
| | | /// <summary> |
| | | /// è¿½å æä»¶ |
| | | /// </summary> |
| | | /// <param name="Path">æä»¶è·¯å¾</param> |
| | | /// <param name="strings">å
容</param> |
| | | public static void FileAdd(string Path, string strings) |
| | | { |
| | | StreamWriter sw = File.AppendText(Path); |
| | | sw.Write(strings); |
| | | sw.Flush(); |
| | | sw.Close(); |
| | | } |
| | | #endregion |
| | | |
| | | #region æ·è´æä»¶ |
| | | /**************************************** |
| | | * 彿°åç§°ï¼FileCoppy |
| | | * åè½è¯´æï¼æ·è´æä»¶ |
| | | * å æ°ï¼OrignFile:åå§æä»¶,NewFile:æ°æä»¶è·¯å¾ |
| | | * è°ç¨ç¤ºåï¼ |
| | | * string orignFile = Server.MapPath("Default2.aspx"); |
| | | * string NewFile = Server.MapPath("Default3.aspx"); |
| | | * EC.FileObj.FileCoppy(OrignFile, NewFile); |
| | | *****************************************/ |
| | | /// <summary> |
| | | /// æ·è´æä»¶ |
| | | /// </summary> |
| | | /// <param name="OrignFile">åå§æä»¶</param> |
| | | /// <param name="NewFile">æ°æä»¶è·¯å¾</param> |
| | | public static void FileCoppy(string orignFile, string NewFile) |
| | | { |
| | | File.Copy(orignFile, NewFile, true); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region å 餿件 |
| | | /**************************************** |
| | | * 彿°åç§°ï¼FileDel |
| | | * åè½è¯´æï¼å 餿件 |
| | | * å æ°ï¼Path:æä»¶è·¯å¾ |
| | | * è°ç¨ç¤ºåï¼ |
| | | * string Path = Server.MapPath("Default3.aspx"); |
| | | * EC.FileObj.FileDel(Path); |
| | | *****************************************/ |
| | | /// <summary> |
| | | /// å 餿件 |
| | | /// </summary> |
| | | /// <param name="Path">è·¯å¾</param> |
| | | public static void FileDel(string Path) |
| | | { |
| | | File.Delete(Path); |
| | | } |
| | | #endregion |
| | | |
| | | #region ç§»å¨æä»¶ |
| | | /**************************************** |
| | | * 彿°åç§°ï¼FileMove |
| | | * åè½è¯´æï¼ç§»å¨æä»¶ |
| | | * å æ°ï¼OrignFile:åå§è·¯å¾,NewFile:æ°æä»¶è·¯å¾ |
| | | * è°ç¨ç¤ºåï¼ |
| | | * string orignFile = Server.MapPath("../说æ.txt"); |
| | | * string NewFile = Server.MapPath("http://www.cnblogs.com/说æ.txt"); |
| | | * EC.FileObj.FileMove(OrignFile, NewFile); |
| | | *****************************************/ |
| | | /// <summary> |
| | | /// ç§»å¨æä»¶ |
| | | /// </summary> |
| | | /// <param name="OrignFile">åå§è·¯å¾</param> |
| | | /// <param name="NewFile">æ°è·¯å¾</param> |
| | | public static void FileMove(string orignFile, string NewFile) |
| | | { |
| | | File.Move(orignFile, NewFile); |
| | | } |
| | | #endregion |
| | | |
| | | #region å¨å½åç®å½ä¸å建ç®å½ |
| | | /**************************************** |
| | | * 彿°åç§°ï¼FolderCreate |
| | | * åè½è¯´æï¼å¨å½åç®å½ä¸å建ç®å½ |
| | | * å æ°ï¼OrignFolder:å½åç®å½,NewFloder:æ°ç®å½ |
| | | * è°ç¨ç¤ºåï¼ |
| | | * string orignFolder = Server.MapPath("test/"); |
| | | * string NewFloder = "new"; |
| | | * EC.FileObj.FolderCreate(OrignFolder, NewFloder); |
| | | *****************************************/ |
| | | /// <summary> |
| | | /// å¨å½åç®å½ä¸å建ç®å½ |
| | | /// </summary> |
| | | /// <param name="OrignFolder">å½åç®å½</param> |
| | | /// <param name="NewFloder">æ°ç®å½</param> |
| | | public static void FolderCreate(string orignFolder, string NewFloder) |
| | | { |
| | | Directory.SetCurrentDirectory(orignFolder); |
| | | Directory.CreateDirectory(NewFloder); |
| | | } |
| | | #endregion |
| | | |
| | | #region éå½å 餿件夹ç®å½åæä»¶ |
| | | /**************************************** |
| | | * 彿°åç§°ï¼DeleteFolder |
| | | * åè½è¯´æï¼éå½å 餿件夹ç®å½åæä»¶ |
| | | * å æ°ï¼dir:æä»¶å¤¹è·¯å¾ |
| | | * è°ç¨ç¤ºåï¼ |
| | | * string dir = Server.MapPath("test/"); |
| | | * EC.FileObj.DeleteFolder(dir); |
| | | *****************************************/ |
| | | /// <summary> |
| | | /// éå½å 餿件夹ç®å½åæä»¶ |
| | | /// </summary> |
| | | /// <param name="dir"></param> |
| | | /// <returns></returns> |
| | | public static void DeleteFolder(string dir) |
| | | { |
| | | if (Directory.Exists(dir)) //妿åå¨è¿ä¸ªæä»¶å¤¹å é¤ä¹ |
| | | { |
| | | foreach (string d in Directory.GetFileSystemEntries(dir)) |
| | | { |
| | | if (File.Exists(d)) |
| | | File.Delete(d); //ç´æ¥å é¤å
¶ä¸çæä»¶ |
| | | else |
| | | DeleteFolder(d); //éå½å é¤åæä»¶å¤¹ |
| | | } |
| | | Directory.Delete(dir); //å é¤å·²ç©ºæä»¶å¤¹ |
| | | } |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | #region 尿宿件夹ä¸é¢çææå
容copyå°ç®æ æä»¶å¤¹ä¸é¢ æç®æ æä»¶å¤¹ä¸ºåªè¯»å±æ§å°±ä¼æ¥éã |
| | | /**************************************** |
| | | * 彿°åç§°ï¼CopyDir |
| | | * åè½è¯´æï¼å°æå®æä»¶å¤¹ä¸é¢çææå
容copyå°ç®æ æä»¶å¤¹ä¸é¢ æç®æ æä»¶å¤¹ä¸ºåªè¯»å±æ§å°±ä¼æ¥éã |
| | | * å æ°ï¼srcPath:åå§è·¯å¾,aimPath:ç®æ æä»¶å¤¹ |
| | | * è°ç¨ç¤ºåï¼ |
| | | * string srcPath = Server.MapPath("test/"); |
| | | * string aimPath = Server.MapPath("test1/"); |
| | | * EC.FileObj.CopyDir(srcPath,aimPath); |
| | | *****************************************/ |
| | | /// <summary> |
| | | /// æå®æä»¶å¤¹ä¸é¢çææå
容copyå°ç®æ æä»¶å¤¹ä¸é¢ |
| | | /// </summary> |
| | | /// <param name="srcPath">åå§è·¯å¾</param> |
| | | /// <param name="aimPath">ç®æ æä»¶å¤¹</param> |
| | | public static void CopyDir(string srcPath, string aimPath) |
| | | { |
| | | try |
| | | { |
| | | // æ£æ¥ç®æ ç®å½æ¯å¦ä»¥ç®å½åå²åç¬¦ç»æå¦æä¸æ¯åæ·»å ä¹ |
| | | if (aimPath[aimPath.Length - 1] != Path.DirectorySeparatorChar) |
| | | aimPath += Path.DirectorySeparatorChar; |
| | | // å¤æç®æ ç®å½æ¯å¦åå¨å¦æä¸åå¨åæ°å»ºä¹ |
| | | if (!Directory.Exists(aimPath)) |
| | | Directory.CreateDirectory(aimPath); |
| | | // å¾å°æºç®å½çæä»¶å表ï¼è¯¥é颿¯å
嫿件以åç®å½è·¯å¾çä¸ä¸ªæ°ç» |
| | | //å¦æä½ æåcopyç®æ æä»¶ä¸é¢çæä»¶èä¸å
å«ç®å½è¯·ä½¿ç¨ä¸é¢çæ¹æ³ |
| | | //string[] fileList = Directory.GetFiles(srcPath); |
| | | string[] fileList = Directory.GetFileSystemEntries(srcPath); |
| | | //éåææçæä»¶åç®å½ |
| | | foreach (string file in fileList) |
| | | { |
| | | //å
å½ä½ç®å½å¤ç妿åå¨è¿ä¸ªç®å½å°±éå½Copy该ç®å½ä¸é¢çæä»¶ |
| | | |
| | | if (Directory.Exists(file)) |
| | | CopyDir(file, aimPath + Path.GetFileName(file)); |
| | | //å¦åç´æ¥Copyæä»¶ |
| | | else |
| | | File.Copy(file, aimPath + Path.GetFileName(file), true); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ee) |
| | | { |
| | | throw new Exception(ee.ToString()); |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Helper |
| | | { |
| | | public static class HttpContextHelper |
| | | { |
| | | public static string GetUserIp(this HttpContext context) |
| | | { |
| | | string realIP = null; |
| | | string forwarded = null; |
| | | string remoteIpAddress = context.Connection.RemoteIpAddress.ToString(); |
| | | if (context.Request.Headers.ContainsKey("X-Real-IP")) |
| | | { |
| | | realIP = context.Request.Headers["X-Real-IP"].ToString(); |
| | | if (realIP != remoteIpAddress) |
| | | { |
| | | remoteIpAddress = realIP; |
| | | } |
| | | } |
| | | if (context.Request.Headers.ContainsKey("X-Forwarded-For")) |
| | | { |
| | | forwarded = context.Request.Headers["X-Forwarded-For"].ToString(); |
| | | if (forwarded != remoteIpAddress) |
| | | { |
| | | remoteIpAddress = forwarded; |
| | | } |
| | | } |
| | | return remoteIpAddress; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using AngleSharp.Dom; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Net.Http.Headers; |
| | | using System.Security.Policy; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Helper |
| | | { |
| | | public class HttpHelper |
| | | { |
| | | public static async Task<string> GetAsync(string serviceAddress, Dictionary<string, object> parameters, string contentType = "application/json", Dictionary<string, string>? headers = null) |
| | | { |
| | | try |
| | | { |
| | | string result = string.Empty; |
| | | using HttpClient httpClient = new HttpClient(); |
| | | httpClient.Timeout = new TimeSpan(0, 0, 60); |
| | | // å°åæ°æ¼æ¥å°URLä¸ |
| | | string queryString = string.Join("&", parameters.Select(x => $"{x.Key}={x.Value}")); |
| | | serviceAddress += "?" + queryString; |
| | | |
| | | if (headers != null) |
| | | { |
| | | foreach (var header in headers) |
| | | httpClient.DefaultRequestHeaders.Add(header.Key, header.Value); |
| | | } |
| | | |
| | | result = await httpClient.GetAsync(serviceAddress).Result.Content.ReadAsStringAsync(); |
| | | return result; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Console.WriteLine(e.Message); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | // ç¨äºè¿½è¸ªæ¯ä¸ªè¯·æ±çè°ç¨æ¬¡æ°åæåè¯·æ±æ¶é´ã |
| | | private static readonly Dictionary<string, (int Count, DateTime LastRequestTime)> requestTracker = new(); |
| | | |
| | | public static async Task<string> PostAsync(string serviceAddress, string requestJson = null, string contentType = "application/json", Dictionary<string, string>? headers = null) |
| | | { |
| | | try |
| | | { |
| | | if (serviceAddress.Contains("http://c24-cellmi3:12020")) |
| | | { |
| | | // å° JSON å符串转æ¢ä¸ºåå
¸ |
| | | var parameters = JsonConvert.DeserializeObject<Dictionary<string, object>>(requestJson); |
| | | |
| | | // å建ä¸ä¸ªæ°çåå
¸ï¼æé¤ RequestTime å SessionId |
| | | var filteredParameters = parameters.Where(p => p.Key != "RequestTime" && p.Key != "SessionId").ToDictionary(p => p.Key, p => p.Value); |
| | | |
| | | string requestKey = $"{serviceAddress}:{JsonConvert.SerializeObject(filteredParameters)}"; |
| | | |
| | | // æ£æ¥è¯·æ±æ¬¡æ°åæ¶é´éå¶ |
| | | if (requestTracker.TryGetValue(requestKey, out var requestInfo)) |
| | | { |
| | | if (requestInfo.Count >= 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(3)) |
| | | { |
| | | // å¦æè¯·æ±æ¬¡æ°è¶
è¿éå¶ä¸æªè¶
è¿10åéï¼æåºå¼å¸¸ |
| | | throw new InvalidOperationException("è¯·æ±æ¬¡æ°å·²è¾¾å°éå¶ï¼è¯·ç¨ååè¯ã"); |
| | | } |
| | | } |
| | | |
| | | // æ´æ°è¯·æ±è·è¸ªä¿¡æ¯ |
| | | if (requestTracker.ContainsKey(requestKey)) |
| | | { |
| | | requestTracker[requestKey] = (requestInfo.Count + 1, DateTime.Now); |
| | | } |
| | | else |
| | | { |
| | | requestTracker[requestKey] = (1, DateTime.Now); |
| | | } |
| | | } |
| | | string result = string.Empty; |
| | | using (HttpContent httpContent = new StringContent(requestJson)) |
| | | { |
| | | httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); |
| | | using HttpClient httpClient = new HttpClient(); |
| | | httpClient.Timeout = new TimeSpan(0, 0, 60); |
| | | |
| | | if (headers != null) |
| | | { |
| | | foreach (var header in headers) |
| | | httpClient.DefaultRequestHeaders.Add(header.Key, header.Value); |
| | | } |
| | | result = await httpClient.PostAsync(serviceAddress, httpContent).Result.Content.ReadAsStringAsync(); |
| | | } |
| | | return result; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Console.WriteLine(e.Message); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static string Get(string serviceAddress, string contentType = "application/json", Dictionary<string, string>? headers = null) |
| | | { |
| | | try |
| | | { |
| | | string result = string.Empty; |
| | | using HttpClient httpClient = new HttpClient(); |
| | | httpClient.Timeout = new TimeSpan(0, 0, 60); |
| | | |
| | | foreach (var header in headers) |
| | | httpClient.DefaultRequestHeaders.Add(header.Key, header.Value); |
| | | |
| | | result = httpClient.GetStringAsync(serviceAddress).Result; |
| | | return result; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Console.WriteLine(e.Message); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static string Post(string serviceAddress, string requestJson = null, string contentType = "application/json", Dictionary<string, string>? headers = null) |
| | | { |
| | | try |
| | | { |
| | | string result = string.Empty; |
| | | using (HttpContent httpContent = new StringContent(requestJson)) |
| | | { |
| | | httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); |
| | | using HttpClient httpClient = new HttpClient(); |
| | | httpClient.Timeout = new TimeSpan(0, 0, 60); |
| | | |
| | | foreach (var header in headers) |
| | | httpClient.DefaultRequestHeaders.Add(header.Key, header.Value); |
| | | |
| | | result = httpClient.PostAsync(serviceAddress, httpContent).Result.Content.ReadAsStringAsync().Result; |
| | | } |
| | | return result; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Console.WriteLine(e.Message); |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Helper |
| | | { |
| | | public static class MethodInfoExtensions |
| | | { |
| | | public static string GetFullName(this MethodInfo method) |
| | | { |
| | | if (method.DeclaringType == null) |
| | | { |
| | | return $@"{method.Name}"; |
| | | } |
| | | |
| | | return $"{method.DeclaringType.FullName}.{method.Name}"; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Helper |
| | | { |
| | | public static class ObjectExtension |
| | | { |
| | | public static List<T> DicToIEnumerable<T>(this List<Dictionary<string, object>> dicList) |
| | | { |
| | | List<T> list = new List<T>(); |
| | | foreach (Dictionary<string, object> dic in dicList) |
| | | { |
| | | list.Add(dic.DicToModel<T>()); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | public static T DicToModel<T>(this Dictionary<string, object> dic) |
| | | { |
| | | //T model = Activator.CreateInstance<T>(); |
| | | //PropertyInfo[] propertyInfos = typeof(T).GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance); |
| | | |
| | | //Dictionary<string, object> upperDic = dic.ToDictionary(k => k.Key.ToUpper(), v => v.Value); |
| | | |
| | | //foreach (var property in propertyInfos) |
| | | //{ |
| | | // object value = null; |
| | | // if (!upperDic.TryGetValue(property.Name.ToUpper(), out value)) |
| | | // { |
| | | // continue; |
| | | // } |
| | | // property.SetValue(model, value?.ToString().ChangeType(property.PropertyType)); |
| | | //} |
| | | //return model; |
| | | |
| | | T model = Activator.CreateInstance<T>(); |
| | | PropertyInfo[] propertyInfos = typeof(T).GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance); |
| | | foreach (var property in propertyInfos) |
| | | { |
| | | object value = null; |
| | | if (!dic.TryGetValue(property.Name, out value)) |
| | | { |
| | | if (!dic.TryGetValue(property.Name.FirstLetterToUpper(), out value)) |
| | | { |
| | | if (!dic.TryGetValue(property.Name.FirstLetterToLower(), out value)) |
| | | { |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | ; |
| | | property.SetValue(model, value?.ToString().ChangeType(property.PropertyType)); |
| | | } |
| | | return model; |
| | | |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | |  |
| | | using Microsoft.Extensions.DependencyModel; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Runtime.Loader; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Helper |
| | | { |
| | | public static class RuntimeExtension |
| | | { |
| | | /// <summary> |
| | | /// è·å项ç®ç¨åºéï¼æé¤ææçç³»ç»ç¨åºé(Microsoft.***ãSystem.***ç)ãNugetä¸è½½å
|
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static IList<Assembly> GetAllAssemblies() |
| | | { |
| | | var list = new List<Assembly>(); |
| | | var deps = DependencyContext.Default; |
| | | //åªå 载项ç®ä¸çç¨åºé |
| | | var libs = deps.CompileLibraries.Where(lib => !lib.Serviceable && lib.Type == "project"); //æé¤ææçç³»ç»ç¨åºéãNugetä¸è½½å
|
| | | foreach (var lib in libs) |
| | | { |
| | | try |
| | | { |
| | | var assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(lib.Name)); |
| | | list.Add(assembly); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | //Log.Debug(e, "GetAllAssemblies Exception:{ex}", e.Message); |
| | | } |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | public static Assembly GetAssembly(string assemblyName) |
| | | { |
| | | return GetAllAssemblies().FirstOrDefault(assembly => assembly.FullName.Contains(assemblyName)); |
| | | } |
| | | |
| | | public static IList<Type> GetAllTypes() |
| | | { |
| | | var list = new List<Type>(); |
| | | foreach (var assembly in GetAllAssemblies()) |
| | | { |
| | | var typeInfos = assembly.DefinedTypes; |
| | | foreach (var typeInfo in typeInfos) |
| | | { |
| | | list.Add(typeInfo.AsType()); |
| | | } |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | public static IList<Type> GetTypesByAssembly(string assemblyName) |
| | | { |
| | | var list = new List<Type>(); |
| | | var assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(assemblyName)); |
| | | var typeInfos = assembly.DefinedTypes; |
| | | foreach (var typeInfo in typeInfos) |
| | | { |
| | | list.Add(typeInfo.AsType()); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | public static Type GetImplementType(string typeName, Type baseInterfaceType) |
| | | { |
| | | return GetAllTypes().FirstOrDefault(t => |
| | | { |
| | | if (t.Name == typeName && |
| | | t.GetTypeInfo().GetInterfaces().Any(b => b.Name == baseInterfaceType.Name)) |
| | | { |
| | | var typeInfo = t.GetTypeInfo(); |
| | | return typeInfo.IsClass && !typeInfo.IsAbstract && !typeInfo.IsGenericType; |
| | | } |
| | | |
| | | return false; |
| | | }); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Security.Cryptography; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.DB; |
| | | |
| | | namespace WIDESEAWCS_Core.Helper |
| | | { |
| | | public static class SecurityEncDecryptHelper |
| | | { |
| | | private static byte[] Keys = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; |
| | | /// <summary> |
| | | /// DESå å¯å符串 |
| | | /// </summary> |
| | | /// <param name="encryptString">å¾
å å¯çå符串</param> |
| | | /// <param name="encryptKey">å å¯å¯é¥,è¦æ±ä¸º16ä½</param> |
| | | /// <returns>å 坿åè¿åå å¯åçå符串ï¼å¤±è´¥è¿åæºä¸²</returns> |
| | | |
| | | public static string EncryptDES(this string encryptString, string encryptKey) |
| | | { |
| | | try |
| | | { |
| | | byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 16)); |
| | | byte[] rgbIV = Keys; |
| | | byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString); |
| | | |
| | | using (var DCSP = Aes.Create()) |
| | | { |
| | | using (MemoryStream mStream = new MemoryStream()) |
| | | { |
| | | using (CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write)) |
| | | { |
| | | cStream.Write(inputByteArray, 0, inputByteArray.Length); |
| | | cStream.FlushFinalBlock(); |
| | | return Convert.ToBase64String(mStream.ToArray()).Replace('+', '_').Replace('/', '~'); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception("å¯ç å å¯å¼å¸¸" + ex.Message); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// DESè§£å¯å符串 |
| | | /// </summary> |
| | | /// <param name="decryptString">å¾
è§£å¯çå符串</param> |
| | | /// <param name="decryptKey">è§£å¯å¯é¥,è¦æ±ä¸º16ä½,åå å¯å¯é¥ç¸å</param> |
| | | /// <returns>è§£å¯æåè¿åè§£å¯åçå符串ï¼å¤±è´¥è¿æºä¸²</returns> |
| | | |
| | | public static string DecryptDES(this string decryptString, string decryptKey) |
| | | { |
| | | if (decryptKey == AppSecret.DB && !AppSettings.app(MainDb.ConnectionStringsEncryption).ObjToBool()) |
| | | return decryptString; |
| | | |
| | | byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey.Substring(0, 16)); |
| | | byte[] rgbIV = Keys; |
| | | byte[] inputByteArray = Convert.FromBase64String(decryptString.Replace('_', '+').Replace('~', '/')); |
| | | using (var DCSP = Aes.Create()) |
| | | { |
| | | using (MemoryStream mStream = new MemoryStream()) |
| | | { |
| | | using (CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write)) |
| | | { |
| | | byte[] inputByteArrays = new byte[inputByteArray.Length]; |
| | | cStream.Write(inputByteArray, 0, inputByteArray.Length); |
| | | cStream.FlushFinalBlock(); |
| | | return Encoding.UTF8.GetString(mStream.ToArray()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | public static bool TryDecryptDES(this string decryptString, string decryptKey, out string result) |
| | | { |
| | | result = ""; |
| | | try |
| | | { |
| | | result = DecryptDES(decryptString, decryptKey); |
| | | return true; |
| | | } |
| | | catch |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.Enums; |
| | | |
| | | namespace WIDESEAWCS_Core.Helper |
| | | { |
| | | public static class UtilConvert |
| | | { |
| | | private static DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0); |
| | | |
| | | private static long longTime = 621355968000000000; |
| | | |
| | | private static int samllTime = 10000000; |
| | | /// <summary> |
| | | /// æ¶é´æ³è½¬æ¢ææ¥æ |
| | | /// </summary> |
| | | /// <param name="timeStamp"></param> |
| | | /// <returns></returns> |
| | | public static DateTime GetTimeSpmpToDate(this object timeStamp) |
| | | { |
| | | if (timeStamp == null) return dateStart; |
| | | DateTime dateTime = new DateTime(longTime + Convert.ToInt64(timeStamp) * samllTime, DateTimeKind.Utc).ToLocalTime(); |
| | | return dateTime; |
| | | } |
| | | |
| | | public static string Serialize(this object obj, JsonSerializerSettings formatDate = null) |
| | | { |
| | | if (obj == null) return null; |
| | | formatDate = formatDate ?? new JsonSerializerSettings |
| | | { |
| | | DateFormatString = "yyyy-MM-dd HH:mm:ss" |
| | | }; |
| | | return JsonConvert.SerializeObject(obj, formatDate); |
| | | } |
| | | |
| | | public static T DeserializeObject<T>(this string json) |
| | | { |
| | | if (string.IsNullOrEmpty(json)) |
| | | { |
| | | return default(T); |
| | | } |
| | | if (json == "{}") |
| | | { |
| | | json = "[]"; |
| | | } |
| | | return JsonConvert.DeserializeObject<T>(json); |
| | | } |
| | | |
| | | public static string FirstLetterToLower(this string thisValue) |
| | | { |
| | | if (string.IsNullOrEmpty(thisValue)) return string.Empty; |
| | | string result = thisValue.Substring(0, 1).ToLower() + thisValue.Substring(1, thisValue.Length - 1); |
| | | return result; |
| | | } |
| | | |
| | | public static string FirstLetterToUpper(this string thisValue) |
| | | { |
| | | if (string.IsNullOrEmpty(thisValue)) return string.Empty; |
| | | string result = thisValue.Substring(0, 1).ToUpper() + thisValue.Substring(1, thisValue.Length - 1); |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <returns></returns> |
| | | public static int ObjToInt(this object thisValue) |
| | | { |
| | | int reval = 0; |
| | | if (thisValue == null) return 0; |
| | | if (thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval)) |
| | | { |
| | | return reval; |
| | | } |
| | | |
| | | return reval; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <returns></returns> |
| | | public static int DoubleToInt(this double thisValue) |
| | | { |
| | | int reval = 0; |
| | | |
| | | return Convert.ToInt32(thisValue); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <param name="errorValue"></param> |
| | | /// <returns></returns> |
| | | public static int ObjToInt(this object thisValue, int errorValue) |
| | | { |
| | | int reval = 0; |
| | | if (thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval)) |
| | | { |
| | | return reval; |
| | | } |
| | | |
| | | return errorValue; |
| | | } |
| | | |
| | | public static long ObjToLong(this object thisValue) |
| | | { |
| | | long reval = 0; |
| | | if (thisValue == null) return 0; |
| | | if (thisValue != DBNull.Value && long.TryParse(thisValue.ToString(), out reval)) |
| | | { |
| | | return reval; |
| | | } |
| | | |
| | | return reval; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <returns></returns> |
| | | public static double ObjToMoney(this object thisValue) |
| | | { |
| | | double reval = 0; |
| | | if (thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out reval)) |
| | | { |
| | | return reval; |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <param name="errorValue"></param> |
| | | /// <returns></returns> |
| | | public static double ObjToMoney(this object thisValue, double errorValue) |
| | | { |
| | | double reval = 0; |
| | | if (thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out reval)) |
| | | { |
| | | return reval; |
| | | } |
| | | |
| | | return errorValue; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <returns></returns> |
| | | public static string ObjToString(this object thisValue) |
| | | { |
| | | if (thisValue != null) return thisValue.ToString().Trim(); |
| | | return ""; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <returns></returns> |
| | | public static bool IsNotEmptyOrNull(this object thisValue) |
| | | { |
| | | return ObjToString(thisValue) != "" && ObjToString(thisValue) != "undefined" && ObjToString(thisValue) != "null"; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <param name="errorValue"></param> |
| | | /// <returns></returns> |
| | | public static string ObjToString(this object thisValue, string errorValue) |
| | | { |
| | | if (thisValue != null) return thisValue.ToString().Trim(); |
| | | return errorValue; |
| | | } |
| | | |
| | | public static bool IsNullOrEmpty(this object thisValue) => thisValue == null || thisValue == DBNull.Value || string.IsNullOrWhiteSpace(thisValue.ToString()); |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <returns></returns> |
| | | public static Decimal ObjToDecimal(this object thisValue) |
| | | { |
| | | Decimal reval = 0; |
| | | if (thisValue != null && thisValue != DBNull.Value && decimal.TryParse(thisValue.ToString(), out reval)) |
| | | { |
| | | return reval; |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <param name="errorValue"></param> |
| | | /// <returns></returns> |
| | | public static Decimal ObjToDecimal(this object thisValue, decimal errorValue) |
| | | { |
| | | Decimal reval = 0; |
| | | if (thisValue != null && thisValue != DBNull.Value && decimal.TryParse(thisValue.ToString(), out reval)) |
| | | { |
| | | return reval; |
| | | } |
| | | |
| | | return errorValue; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <returns></returns> |
| | | public static DateTime ObjToDate(this object thisValue) |
| | | { |
| | | DateTime reval = DateTime.MinValue; |
| | | if (thisValue != null && thisValue != DBNull.Value && DateTime.TryParse(thisValue.ToString(), out reval)) |
| | | { |
| | | reval = Convert.ToDateTime(thisValue); |
| | | } |
| | | |
| | | return reval; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <param name="errorValue"></param> |
| | | /// <returns></returns> |
| | | public static DateTime ObjToDate(this object thisValue, DateTime errorValue) |
| | | { |
| | | DateTime reval = DateTime.MinValue; |
| | | if (thisValue != null && thisValue != DBNull.Value && DateTime.TryParse(thisValue.ToString(), out reval)) |
| | | { |
| | | return reval; |
| | | } |
| | | |
| | | return errorValue; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <returns></returns> |
| | | public static bool ObjToBool(this object thisValue) |
| | | { |
| | | bool reval = false; |
| | | if (thisValue != null && thisValue != DBNull.Value && bool.TryParse(thisValue.ToString(), out reval)) |
| | | { |
| | | return reval; |
| | | } |
| | | |
| | | return reval; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// è·åå½åæ¶é´çæ¶é´æ³ |
| | | /// </summary> |
| | | /// <param name="thisValue"></param> |
| | | /// <returns></returns> |
| | | public static string DateToTimeStamp(this DateTime thisValue) |
| | | { |
| | | TimeSpan ts = thisValue - new DateTime(1970, 1, 1, 0, 0, 0, 0); |
| | | return Convert.ToInt64(ts.TotalSeconds).ToString(); |
| | | } |
| | | |
| | | public static object ChangeType(this object value, Type type) |
| | | { |
| | | if (value == null && type.IsGenericType) return Activator.CreateInstance(type); |
| | | if (value == null) return null; |
| | | if (type == value.GetType()) return value; |
| | | if (type.IsEnum) |
| | | { |
| | | if (value is string) |
| | | return Enum.Parse(type, value as string); |
| | | else |
| | | return Enum.ToObject(type, value); |
| | | } |
| | | |
| | | if (!type.IsInterface && type.IsGenericType) |
| | | { |
| | | Type innerType = type.GetGenericArguments()[0]; |
| | | object innerValue = ChangeType(value, innerType); |
| | | return Activator.CreateInstance(type, new object[] { innerValue }); |
| | | } |
| | | |
| | | if (value is string && type == typeof(Guid)) return new Guid(value as string); |
| | | if (value is string && type == typeof(Version)) return new Version(value as string); |
| | | if (!(value is IConvertible)) return value; |
| | | return Convert.ChangeType(value, type); |
| | | } |
| | | |
| | | public static object ChangeTypeList(this object value, Type type) |
| | | { |
| | | if (value == null) return default; |
| | | |
| | | var gt = typeof(List<>).MakeGenericType(type); |
| | | dynamic lis = Activator.CreateInstance(gt); |
| | | |
| | | var addMethod = gt.GetMethod("Add"); |
| | | string values = value.ToString(); |
| | | if (values != null && values.StartsWith("(") && values.EndsWith(")")) |
| | | { |
| | | string[] splits; |
| | | if (values.Contains("\",\"")) |
| | | { |
| | | splits = values.Remove(values.Length - 2, 2) |
| | | .Remove(0, 2) |
| | | .Split("\",\""); |
| | | } |
| | | else |
| | | { |
| | | splits = values.Remove(0, 1) |
| | | .Remove(values.Length - 2, 1) |
| | | .Split(","); |
| | | } |
| | | |
| | | foreach (var split in splits) |
| | | { |
| | | var str = split; |
| | | if (split.StartsWith("\"") && split.EndsWith("\"")) |
| | | { |
| | | str = split.Remove(0, 1) |
| | | .Remove(split.Length - 2, 1); |
| | | } |
| | | |
| | | addMethod.Invoke(lis, new object[] { ChangeType(str, type) }); |
| | | } |
| | | } |
| | | |
| | | return lis; |
| | | } |
| | | |
| | | public static string ToJson(this object value) |
| | | { |
| | | return JsonConvert.SerializeObject(value); |
| | | } |
| | | |
| | | public static bool IsInt(this object obj) |
| | | { |
| | | if (obj == null) |
| | | return false; |
| | | bool reslut = Int32.TryParse(obj.ToString(), out int _number); |
| | | return reslut; |
| | | |
| | | } |
| | | public static bool IsDate(this object str) |
| | | { |
| | | return str.IsDate(out _); |
| | | } |
| | | public static bool IsDate(this object str, out DateTime dateTime) |
| | | { |
| | | dateTime = DateTime.Now; |
| | | if (str == null || str.ToString() == "") |
| | | { |
| | | return false; |
| | | } |
| | | return DateTime.TryParse(str.ToString(), out dateTime); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®ä¼ å
¥æ ¼å¼å¤ææ¯å¦ä¸ºå°æ° |
| | | /// </summary> |
| | | /// <param name="str"></param> |
| | | /// <param name="formatString">18,5</param> |
| | | /// <returns></returns> |
| | | public static bool IsNumber(this string str, string formatString) |
| | | { |
| | | if (string.IsNullOrEmpty(str)) return false; |
| | | |
| | | return Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$"); |
| | | } |
| | | |
| | | public static bool IsGuid(this string guid) |
| | | { |
| | | Guid newId; |
| | | return guid.GetGuid(out newId); |
| | | } |
| | | |
| | | public static bool GetGuid(this string guid, out Guid outId) |
| | | { |
| | | Guid emptyId = Guid.Empty; |
| | | return Guid.TryParse(guid, out outId); |
| | | } |
| | | |
| | | public static LinqExpressionType GetLinqCondition(this string stringType) |
| | | { |
| | | LinqExpressionType linqExpression; |
| | | switch (stringType) |
| | | { |
| | | case HtmlElementType.Contains: |
| | | linqExpression = LinqExpressionType.In; |
| | | break; |
| | | case HtmlElementType.ThanOrEqual: |
| | | linqExpression = LinqExpressionType.ThanOrEqual; |
| | | break; |
| | | case HtmlElementType.LessOrequal: |
| | | linqExpression = LinqExpressionType.LessThanOrEqual; |
| | | break; |
| | | case HtmlElementType.GT: |
| | | linqExpression = LinqExpressionType.GreaterThan; |
| | | break; |
| | | case HtmlElementType.lt: |
| | | linqExpression = LinqExpressionType.LessThan; |
| | | break; |
| | | case HtmlElementType.like: |
| | | linqExpression = LinqExpressionType.Contains; |
| | | break; |
| | | default: |
| | | linqExpression = LinqExpressionType.Equal; |
| | | break; |
| | | } |
| | | return linqExpression; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Hosting; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Microsoft.Extensions.Hosting; |
| | | using Microsoft.Extensions.Logging; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.Seed; |
| | | |
| | | namespace WIDESEAWCS_Core |
| | | { |
| | | public sealed class SeedDataHostedService : IHostedService |
| | | { |
| | | private readonly DBContext _dbContext; |
| | | private readonly ILogger<SeedDataHostedService> _logger; |
| | | private readonly string _webRootPath; |
| | | private readonly IServiceProvider _serviceProvider; |
| | | |
| | | public SeedDataHostedService( |
| | | IServiceProvider serviceProvider, |
| | | IWebHostEnvironment webHostEnvironment, |
| | | ILogger<SeedDataHostedService> logger) |
| | | { |
| | | _serviceProvider = serviceProvider; |
| | | _logger = logger; |
| | | _webRootPath = webHostEnvironment.WebRootPath; |
| | | |
| | | using var scope = _serviceProvider.CreateScope(); |
| | | |
| | | var dbContext = scope.ServiceProvider.GetService<DBContext>(); |
| | | //dbContext.Db.Aop.DataExecuting = SqlSugarAop.DataExecuting; |
| | | _dbContext = dbContext; |
| | | } |
| | | |
| | | public async Task StartAsync(CancellationToken cancellationToken) |
| | | { |
| | | _logger.LogInformation("Start Initialization Db Seed Service!"); |
| | | await DoWork(); |
| | | } |
| | | |
| | | private async Task DoWork() |
| | | { |
| | | try |
| | | { |
| | | //if (AppSettings.app("AppSettings", "SeedDBEnabled").ObjToBool() || AppSettings.app("AppSettings", "SeedDBDataEnabled").ObjToBool()) |
| | | { |
| | | // ä½¿ç¨ myScopedService æ§è¡ä»»å¡ |
| | | |
| | | await DBSeed.SeedAsync(_dbContext, _webRootPath); |
| | | |
| | | //å¤ç§æ· 忥 |
| | | //await DBSeed.TenantSeedAsync(_dbContext); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogError(ex, "Error occured seeding the Database."); |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | public Task StopAsync(CancellationToken cancellationToken) |
| | | { |
| | | _logger.LogInformation("Stop Initialization Db Seed Service!"); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Microsoft.Extensions.Logging; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IdentityModel.Tokens.Jwt; |
| | | using System.Linq; |
| | | using System.Security.Claims; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.DB; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.Seed; |
| | | using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; |
| | | |
| | | namespace WIDESEAWCS_Core.HttpContextUser |
| | | { |
| | | public class AspNetUser : IUser |
| | | { |
| | | private readonly IHttpContextAccessor _accessor; |
| | | private readonly ICacheService _cacheService; |
| | | //private readonly ILogger<AspNetUser> _logger; |
| | | |
| | | public AspNetUser(IHttpContextAccessor accessor, ICacheService cacheService) |
| | | { |
| | | _accessor = accessor; |
| | | _cacheService = cacheService; |
| | | /*_logger = logger;*/ |
| | | } |
| | | |
| | | public string UserName => GetUserInfoFromToken(ClaimTypes.Name).FirstOrDefault() ?? ""; |
| | | |
| | | public int UserId => GetClaimValueByType(JwtRegisteredClaimNames.Jti) == null ? 0 : GetClaimValueByType(JwtRegisteredClaimNames.Jti).FirstOrDefault()?.ObjToInt() ?? 0; |
| | | |
| | | public long TenantId => GetUserInfoFromToken(nameof(TenantId)).FirstOrDefault()?.ObjToLong() ?? -1; |
| | | |
| | | public int RoleId => GetUserInfoFromToken(ClaimTypes.Role).FirstOrDefault()?.ObjToInt() ?? 0; |
| | | |
| | | public string Token => GetToken(); |
| | | |
| | | public int MenuType => (_accessor.HttpContext?.Request.Headers.ContainsKey("uniapp") ?? false) ? 1 : 0; |
| | | |
| | | public bool IsAuthenticated() |
| | | { |
| | | return _accessor.HttpContext?.User?.Identity?.IsAuthenticated ?? false; |
| | | } |
| | | |
| | | public string GetToken() |
| | | { |
| | | string token = _cacheService.Get(UserId.ToString()); |
| | | if (!string.IsNullOrEmpty(token)) { return token; } |
| | | return string.Empty; |
| | | //return _accessor.HttpContext?.Request?.Headers["Authorization"].ObjToString().Replace("Bearer ", "") ?? ""; |
| | | } |
| | | |
| | | public void UpdateToke(string token) |
| | | { |
| | | _cacheService.AddOrUpdate(UserId.ToString(), token); |
| | | } |
| | | |
| | | public bool IsSuperAdmin => IsRoleIdSuperAdmin(RoleId); |
| | | |
| | | public List<string> GetUserInfoFromToken(string ClaimType) |
| | | { |
| | | var jwtHandler = new JwtSecurityTokenHandler(); |
| | | var token = ""; |
| | | |
| | | token = GetToken(); |
| | | // tokenæ ¡éª |
| | | if (token.IsNotEmptyOrNull() && jwtHandler.CanReadToken(token)) |
| | | { |
| | | JwtSecurityToken jwtToken = jwtHandler.ReadJwtToken(token); |
| | | |
| | | return (from item in jwtToken.Claims |
| | | where item.Type == ClaimType |
| | | select item.Value).ToList(); |
| | | } |
| | | |
| | | return new List<string>() { }; |
| | | } |
| | | |
| | | public IEnumerable<Claim> GetClaimsIdentity() |
| | | { |
| | | if (_accessor.HttpContext != null) |
| | | { |
| | | var claims = _accessor.HttpContext.User.Claims.ToList(); |
| | | var headers = _accessor.HttpContext.Request.Headers; |
| | | foreach (var header in headers) |
| | | { |
| | | claims.Add(new Claim(header.Key, header.Value)); |
| | | } |
| | | |
| | | return claims; |
| | | } |
| | | return ArraySegment<Claim>.Empty; |
| | | } |
| | | |
| | | public List<string> GetClaimValueByType(string ClaimType) |
| | | { |
| | | return (from item in GetClaimsIdentity() |
| | | where item.Type == ClaimType |
| | | select item.Value).ToList(); |
| | | } |
| | | |
| | | public bool IsRoleIdSuperAdmin(int roleId) |
| | | { |
| | | return roleId == 1; |
| | | } |
| | | } |
| | | |
| | | public class UserInfo |
| | | { |
| | | public long TenantId { get; set; } |
| | | |
| | | public int RoleId { get; set; } |
| | | |
| | | public string UserName { get; set; } |
| | | |
| | | public int UserId { get; set; } |
| | | |
| | | public string UserTrueName { get; set; } |
| | | |
| | | public string HeadImageUrl { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 使ç¨ä¸é¢çDeptIdsåæ®µ |
| | | /// </summary> |
| | | |
| | | [Obsolete] |
| | | |
| | | public int DeptId { get; set; } |
| | | |
| | | |
| | | public List<Guid> DeptIds { get; set; } |
| | | |
| | | public string Token { get; set; } |
| | | |
| | | public string Token_ID { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Security.Claims; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.HttpContextUser |
| | | { |
| | | public interface IUser |
| | | { |
| | | /// <summary> |
| | | /// åç§° |
| | | /// </summary> |
| | | string UserName { get; } |
| | | |
| | | /// <summary> |
| | | /// UserId |
| | | /// </summary> |
| | | int UserId { get; } |
| | | |
| | | /// <summary> |
| | | /// ç§æ·ID |
| | | /// </summary> |
| | | long TenantId { get; } |
| | | |
| | | int RoleId { get; } |
| | | |
| | | string Token { get; } |
| | | |
| | | int MenuType { get; } |
| | | |
| | | void UpdateToke(string token); |
| | | |
| | | /// <summary> |
| | | /// æ¯å¦è®¤è¯ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | bool IsAuthenticated(); |
| | | |
| | | IEnumerable<Claim> GetClaimsIdentity(); |
| | | |
| | | List<string> GetClaimValueByType(string ClaimType); |
| | | |
| | | string GetToken(); |
| | | |
| | | List<string> GetUserInfoFromToken(string ClaimType); |
| | | |
| | | bool IsSuperAdmin { get; } |
| | | |
| | | bool IsRoleIdSuperAdmin(int roleId); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core |
| | | { |
| | | public interface IDependency |
| | | { |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | |  |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | |
| | | namespace WIDESEAWCS_Core.LogHelper |
| | | { |
| | | public class LogLock |
| | | { |
| | | static ReaderWriterLockSlim LogWriteLock = new ReaderWriterLockSlim(); |
| | | static int WritedCount = 0; |
| | | static int FailedCount = 0; |
| | | static string _contentRoot = string.Empty; |
| | | |
| | | public LogLock(string contentPath) |
| | | { |
| | | _contentRoot = contentPath; |
| | | } |
| | | |
| | | public static void OutLogAOP(string prefix, string[] dataParas, bool IsHeader = true) |
| | | { |
| | | OutSql2LogToFile(prefix, dataParas, IsHeader); |
| | | } |
| | | |
| | | public static void OutSql2LogToFile(string prefix, string[] dataParas, bool IsHeader = true, bool isWrt = false) |
| | | { |
| | | try |
| | | { |
| | | //设置读åé为åå
¥æ¨¡å¼ç¬å èµæºï¼å
¶ä»åå
¥è¯·æ±éè¦çå¾
æ¬æ¬¡åå
¥ç»æä¹åæè½ç»§ç»åå
¥ |
| | | //注æï¼é¿æ¶é´ææè¯»çº¿ç¨éæå线ç¨éä¼ä½¿å
¶ä»çº¿ç¨åç饥饿 (starve)ã 为äºå¾å°æå¥½çæ§è½ï¼éè¦èèéæ°æé åºç¨ç¨åºä»¥å°å访é®çæç»æ¶é´åå°å°æå°ã |
| | | // 仿§è½æ¹é¢èèï¼è¯·æ±è¿å
¥åå
¥æ¨¡å¼åºè¯¥ç´§è·æä»¶æä½ä¹åï¼å¨æ¤å¤è¿å
¥åå
¥æ¨¡å¼ä»
æ¯ä¸ºäºéä½ä»£ç å¤æåº¦ |
| | | // å è¿å
¥ä¸éåºåå
¥æ¨¡å¼åºå¨åä¸ä¸ªtry finallyè¯å¥åå
ï¼æä»¥å¨è¯·æ±è¿å
¥åå
¥æ¨¡å¼ä¹åä¸è½è§¦åå¼å¸¸ï¼å¦åéæ¾æ¬¡æ°å¤§äºè¯·æ±æ¬¡æ°å°ä¼è§¦åå¼å¸¸ |
| | | LogWriteLock.EnterWriteLock(); |
| | | |
| | | var folderPath = Path.Combine(_contentRoot, "Log"); |
| | | if (!Directory.Exists(folderPath)) |
| | | { |
| | | Directory.CreateDirectory(folderPath); |
| | | } |
| | | //string logFilePath = Path.Combine(path, $@"{filename}.log"); |
| | | var logFilePath = FileHelper.GetAvailableFileWithPrefixOrderSize(folderPath, prefix); |
| | | |
| | | var now = DateTime.Now; |
| | | string logContent = String.Join("\r\n", dataParas); |
| | | if (IsHeader) |
| | | { |
| | | logContent = ( |
| | | "--------------------------------\r\n" + |
| | | DateTime.Now + "|\r\n" + |
| | | String.Join("\r\n", dataParas) + "\r\n" |
| | | ); |
| | | } |
| | | else |
| | | { |
| | | logContent = ( |
| | | dataParas[1] + ",\r\n" |
| | | ); |
| | | } |
| | | |
| | | //if (logContent.IsNotEmptyOrNull() && logContent.Length > 500) |
| | | //{ |
| | | // logContent = logContent.Substring(0, 500) + "\r\n"; |
| | | //} |
| | | if (isWrt) |
| | | { |
| | | System.IO.File.WriteAllText(logFilePath, logContent); |
| | | } |
| | | else |
| | | { |
| | | System.IO.File.AppendAllText(logFilePath, logContent); |
| | | } |
| | | WritedCount++; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | //Console.Write(e.Message); |
| | | FailedCount++; |
| | | } |
| | | finally |
| | | { |
| | | //éåºåå
¥æ¨¡å¼ï¼éæ¾èµæºå ç¨ |
| | | //注æï¼ä¸æ¬¡è¯·æ±å¯¹åºä¸æ¬¡éæ¾ |
| | | // è¥éæ¾æ¬¡æ°å¤§äºè¯·æ±æ¬¡æ°å°ä¼è§¦åå¼å¸¸[åå
¥é宿ªç»ä¿æå³è¢«éæ¾] |
| | | // è¥è¯·æ±å¤çå®æåæªéæ¾å°ä¼è§¦åå¼å¸¸[æ¤æ¨¡å¼ä¸ä¸å
许以é彿¹å¼è·ååå
¥éå®] |
| | | LogWriteLock.ExitWriteLock(); |
| | | } |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Concurrent; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.DB; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.HttpContextUser; |
| | | using WIDESEAWCS_Core.Seed; |
| | | |
| | | namespace WIDESEAWCS_Core.LogHelper |
| | | { |
| | | public static class Logger |
| | | { |
| | | public static ConcurrentQueue<dynamic> loggerQueueData = new ConcurrentQueue<dynamic>(); |
| | | static Logger() |
| | | { |
| | | Task.Run(() => |
| | | { |
| | | StartWriteLog(); |
| | | }); |
| | | |
| | | } |
| | | |
| | | static void StartWriteLog() |
| | | { |
| | | DataTable queueTable = CreateEmptyTable(); |
| | | while (true) |
| | | { |
| | | try |
| | | { |
| | | if (loggerQueueData.Count() > 0 && queueTable.Rows.Count < 500) |
| | | { |
| | | DequeueToTable(queueTable); continue; |
| | | } |
| | | //æ¯5ç§å䏿¬¡æ°æ® |
| | | Thread.Sleep(5000); |
| | | |
| | | if (queueTable.Rows.Count == 0) { continue; } |
| | | |
| | | SqlSugarScope sugarClient = new SqlSugarScope(new ConnectionConfig() |
| | | { |
| | | ConnectionString = DBContext.GetMainConnectionDb().Connection, |
| | | IsAutoCloseConnection = true, |
| | | DbType = MainDb.DbType, |
| | | }); |
| | | |
| | | int rows = sugarClient.Fastest<DataTable>().AS("Sys_Log").BulkCopy(queueTable); |
| | | |
| | | queueTable.Clear(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine(ex.ToString()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private static void DequeueToTable(DataTable queueTable) |
| | | { |
| | | loggerQueueData.TryDequeue(out dynamic log); |
| | | if (log != null) |
| | | { |
| | | DataRow row = queueTable.NewRow(); |
| | | if (log.BeginDate == null || log.BeginDate?.Year < 2010) |
| | | { |
| | | log.BeginDate = DateTime.Now; |
| | | } |
| | | if (log.EndDate == null) |
| | | { |
| | | log.EndDate = DateTime.Now; |
| | | } |
| | | // row["Id"] = log.Id; |
| | | row["RequestParam"] = log.RequestParam?.Replace("\r\n", ""); |
| | | row["ResponseParam"] = log.ResponseParam?.Replace("\r\n", ""); |
| | | //row["Success"] = log.Success ?? -1; |
| | | row["BeginDate"] = log.BeginDate; |
| | | row["EndDate"] = log.EndDate; |
| | | row["ElapsedTime"] = ((DateTime)log.EndDate - (DateTime)log.BeginDate).TotalMilliseconds; |
| | | row["UserIP"] = log.UserIP; |
| | | row["Url"] = log.Url; |
| | | row["UserId"] = log.UserId ?? -1; |
| | | row["UserName"] = log.UserName; |
| | | queueTable.Rows.Add(row); |
| | | } |
| | | } |
| | | |
| | | private static DataTable CreateEmptyTable() |
| | | { |
| | | DataTable queueTable = new DataTable(); |
| | | queueTable.Columns.Add("BeginDate", Type.GetType("System.DateTime")); |
| | | queueTable.Columns.Add("ElapsedTime", Type.GetType("System.Int32")); |
| | | queueTable.Columns.Add("EndDate", Type.GetType("System.DateTime")); |
| | | queueTable.Columns.Add("RequestParam", typeof(string)); |
| | | queueTable.Columns.Add("ResponseParam", typeof(string)); |
| | | //queueTable.Columns.Add("Success", Type.GetType("System.Int32")); |
| | | queueTable.Columns.Add("Url", typeof(string)); |
| | | queueTable.Columns.Add("UserIP", typeof(string)); |
| | | queueTable.Columns.Add("UserName", typeof(string)); |
| | | queueTable.Columns.Add("UserId", Type.GetType("System.Int32")); |
| | | //queueTable.Columns.Add("LogType", typeof(string)); |
| | | //queueTable.Columns.Add("ExceptionInfo", typeof(string)); |
| | | //queueTable.Columns.Add("ServiceIP", typeof(string)); |
| | | //queueTable.Columns.Add("BrowserType", typeof(string)); |
| | | //queueTable.Columns.Add("Role_Id", Type.GetType("System.Int32")); |
| | | return queueTable; |
| | | } |
| | | |
| | | public static void Add(string requestParameter, string responseParameter) |
| | | { |
| | | dynamic log = null; |
| | | try |
| | | { |
| | | HttpContext context = App.HttpContext; |
| | | if (context == null) |
| | | { |
| | | return; |
| | | } |
| | | if (context.Request.Method == "OPTIONS") return; |
| | | RequestLogModel logModel = (context.RequestServices.GetService(typeof(RequestLogModel)) as RequestLogModel) ?? new RequestLogModel { RequestDate = DateTime.Now }; |
| | | |
| | | IUser user = App.User; |
| | | log = new |
| | | { |
| | | BeginDate = logModel.RequestDate, |
| | | EndDate = DateTime.Now, |
| | | RequestParam = requestParameter, |
| | | ResponseParam = responseParameter, |
| | | Url = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase + context.Request.Path, |
| | | UserIP = GetClientIP(context) ?.Replace("::ffff:", ""), |
| | | UserId = user.UserId, |
| | | UserName = user.UserName |
| | | }; |
| | | } |
| | | catch (Exception exception) |
| | | { |
| | | log = log ?? new |
| | | { |
| | | BeginDate = DateTime.Now, |
| | | EndDate = DateTime.Now, |
| | | RequestParam = requestParameter, |
| | | ResponseParam = responseParameter, |
| | | }; |
| | | } |
| | | //æ·»å ç³»ç»æ¥å¿ |
| | | loggerQueueData.Enqueue(log); |
| | | } |
| | | |
| | | public static string GetClientIP(HttpContext context) |
| | | { |
| | | var ip = context.Request.Headers["X-Forwarded-For"].ObjToString(); |
| | | if (string.IsNullOrEmpty(ip)) |
| | | { |
| | | ip = context.Connection.RemoteIpAddress.ObjToString(); |
| | | } |
| | | |
| | | return ip; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | |
| | | namespace WIDESEAWCS_Core.LogHelper |
| | | { |
| | | public class QuartzLogger |
| | | { |
| | | static ReaderWriterLockSlim LogWriteLock = new ReaderWriterLockSlim(); |
| | | static string folderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Log\\{DateTime.Now.ToString("yyyy-MM-dd")}"); |
| | | |
| | | public static void WriteLogToFile(string fileName, string log) |
| | | { |
| | | try |
| | | { |
| | | LogWriteLock.EnterWriteLock(); |
| | | |
| | | |
| | | if (!Directory.Exists(folderPath)) |
| | | { |
| | | Directory.CreateDirectory(folderPath); |
| | | } |
| | | string logFilePath = Path.Combine(folderPath, GetLastAccessFileName(fileName)); |
| | | DateTime now = DateTime.Now; |
| | | string logContent = $"ã{now}ã{Environment.NewLine}{log}"; |
| | | |
| | | File.AppendAllText(logFilePath, logContent); |
| | | } |
| | | catch { } |
| | | finally |
| | | { |
| | | LogWriteLock.ExitWriteLock(); |
| | | } |
| | | } |
| | | static int size = 10 * 1024 * 1024; |
| | | static string ext = ".log"; |
| | | private static string GetLogFilePath(string folderPath, string fileName) |
| | | { |
| | | var allFiles = new DirectoryInfo(folderPath); |
| | | var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(fileName.ToLower()) && fi.Extension.ToLower() == ext.ToLower() && fi.Length < size).OrderByDescending(d => d.Name).ToList(); |
| | | |
| | | if (selectFiles.Count > 0) |
| | | { |
| | | return selectFiles.FirstOrDefault().FullName; |
| | | } |
| | | |
| | | return Path.Combine(folderPath, $@"{fileName}_{DateTime.Now.ToString("HH-mm-ss")}.log"); |
| | | } |
| | | |
| | | private static string GetLastAccessFileName(string fileName) |
| | | { |
| | | foreach (var m in GetExistLogFileNames(fileName)) |
| | | { |
| | | FileInfo fileInfo = new FileInfo(m); |
| | | if (fileInfo.Length < size) |
| | | { |
| | | return m; |
| | | } |
| | | } |
| | | |
| | | // è¿åä¸ä¸ªæ°çé»è®¤å½åæ¶é´çæ¥å¿åç§° |
| | | return $@"{fileName}_{DateTime.Now.ToString("HH-mm-ss")}.log"; |
| | | } |
| | | |
| | | public static string[] GetExistLogFileNames(string fileName) |
| | | { |
| | | string[] fileNames = Directory.GetFiles(folderPath, fileName + "*.log"); |
| | | return fileNames; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.LogHelper |
| | | { |
| | | public class RequestLogModel |
| | | { |
| | | public DateTime RequestDate { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.Extensions.Logging; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | |
| | | namespace WIDESEAWCS_Core.Middlewares |
| | | { |
| | | /// <summary> |
| | | /// è®°å½è¯·æ±åååºæ°æ® |
| | | /// </summary> |
| | | public class ApiLogMiddleware |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | private readonly RequestDelegate _next; |
| | | private readonly ILogger<ApiLogMiddleware> _logger; |
| | | |
| | | public ApiLogMiddleware(RequestDelegate next, ILogger<ApiLogMiddleware> logger) |
| | | { |
| | | _next = next; |
| | | _logger = logger; |
| | | } |
| | | |
| | | //todo |
| | | public async Task InvokeAsync(HttpContext context) |
| | | { |
| | | // è¿æ»¤ï¼åªææ¥å£ |
| | | if (context.Request.Path.Value?.Contains("api") ?? false) |
| | | { |
| | | context.Request.EnableBuffering(); |
| | | Stream originalBody = context.Response.Body; |
| | | string requestParam = string.Empty; |
| | | string responseParam = string.Empty; |
| | | try |
| | | { |
| | | (context.RequestServices.GetService(typeof(RequestLogModel)) as RequestLogModel).RequestDate = DateTime.Now; |
| | | try |
| | | { |
| | | // åå¨è¯·æ±æ°æ® |
| | | requestParam = RequestDataLog(context); |
| | | context.Request.Body.Position = 0; |
| | | } |
| | | catch { } |
| | | using MemoryStream ms = new(); |
| | | context.Response.Body = ms; |
| | | |
| | | await _next(context); |
| | | |
| | | try |
| | | { |
| | | // åå¨ååºæ°æ® |
| | | responseParam = ResponseDataLog(context.Response); |
| | | } |
| | | catch { } |
| | | |
| | | ms.Position = 0; |
| | | await ms.CopyToAsync(originalBody); |
| | | if (!(context.Request.Path.Value?.Contains("Get") ?? false)) |
| | | Logger.Add(requestParam, responseParam); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // è®°å½å¼å¸¸ |
| | | |
| | | } |
| | | finally |
| | | { |
| | | context.Response.Body = originalBody; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | await _next(context); |
| | | } |
| | | } |
| | | |
| | | private string RequestDataLog(HttpContext context) |
| | | { |
| | | var request = context.Request; |
| | | var sr = new StreamReader(request.Body); |
| | | |
| | | object obj = new |
| | | { |
| | | QueryString = request.QueryString.ToString(), |
| | | BodyData = sr.ReadToEndAsync().Result |
| | | }; |
| | | |
| | | string data = JsonConvert.SerializeObject(obj); |
| | | |
| | | request.Body.Position = 0; |
| | | |
| | | return data; |
| | | } |
| | | |
| | | private string ResponseDataLog(HttpResponse response) |
| | | { |
| | | response.Body.Position = 0; |
| | | using StreamReader stream = new StreamReader(response.Body, leaveOpen: true); |
| | | string body = stream.ReadToEnd(); |
| | | response.Body.Position = 0; |
| | | return body; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.DirectoryServices.Protocols; |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Middlewares |
| | | { |
| | | public class ExceptionHandlerMiddleware |
| | | { |
| | | private readonly RequestDelegate _next; |
| | | |
| | | public ExceptionHandlerMiddleware(RequestDelegate next) |
| | | { |
| | | _next = next; |
| | | } |
| | | |
| | | public async Task Invoke(HttpContext context) |
| | | { |
| | | try |
| | | { |
| | | await _next(context); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | await HandleExceptionAsync(context, ex); |
| | | } |
| | | } |
| | | |
| | | private async Task HandleExceptionAsync(HttpContext context, Exception e) |
| | | { |
| | | if (e == null) return; |
| | | |
| | | await WriteExceptionAsync(context, e).ConfigureAwait(false); |
| | | } |
| | | |
| | | private static async Task WriteExceptionAsync(HttpContext context, Exception e) |
| | | { |
| | | var message = e.Message; |
| | | switch (e) |
| | | { |
| | | case UnauthorizedAccessException: |
| | | context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; |
| | | break; |
| | | default: |
| | | context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; |
| | | break; |
| | | } |
| | | context.Response.ContentType = "application/json"; |
| | | await context.Response |
| | | .WriteAsync(JsonConvert.SerializeObject(WebResponseContent.Instance.Error(message))) |
| | | .ConfigureAwait(false); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Middlewares |
| | | { |
| | | public class HttpRequestMiddleware |
| | | { |
| | | private readonly RequestDelegate _next; |
| | | |
| | | public HttpRequestMiddleware(RequestDelegate next) |
| | | { |
| | | _next = next; |
| | | } |
| | | |
| | | public async Task InvokeAsync(HttpContext context) |
| | | { |
| | | context.Response.Headers.Add("Access-Control-Expose-Headers", "wideseawcs_exp"); |
| | | await _next(context); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | |  |
| | | using Microsoft.AspNetCore.Builder; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | |
| | | namespace WIDESEAWCS_Core.Middlewares |
| | | { |
| | | /// <summary> |
| | | /// ip éæµ |
| | | /// </summary> |
| | | public static class IpLimitMiddleware |
| | | { |
| | | /// <summary> |
| | | /// ipéæµ |
| | | /// </summary> |
| | | /// <param name="app"></param> |
| | | /// <exception cref="ArgumentNullException"></exception> |
| | | public static void UseIpLimitMiddle(this IApplicationBuilder app) |
| | | { |
| | | if (app == null) throw new ArgumentNullException(nameof(app)); |
| | | |
| | | //try |
| | | //{ |
| | | // if (AppSettings.app("Middleware", "IpRateLimit", "Enabled").ObjToBool()) |
| | | // { |
| | | // app.UseIpRateLimiting(); |
| | | // } |
| | | //} |
| | | //catch (Exception e) |
| | | //{ |
| | | // Log.Error($"Error occured limiting ip rate.\n{e.Message}"); |
| | | // throw; |
| | | //} |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Authorization; |
| | | using WIDESEAWCS_Core.HttpContextUser; |
| | | |
| | | namespace WIDESEAWCS_Core.Middlewares |
| | | { |
| | | /// <summary> |
| | | /// ä¸é´ä»¶ |
| | | /// åå为èªå®ä¹ææä¸é´ä»¶ |
| | | /// å
åæ£æ¥ header tokençä½¿ç¨ |
| | | /// </summary> |
| | | public class JwtTokenAuthMiddleware |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | private readonly RequestDelegate _next; |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="next"></param> |
| | | public JwtTokenAuthMiddleware(RequestDelegate next) |
| | | { |
| | | _next = next; |
| | | } |
| | | |
| | | |
| | | private void PreProceed(HttpContext next) |
| | | { |
| | | //Console.WriteLine($"{DateTime.Now} middleware invoke preproceed"); |
| | | //... |
| | | } |
| | | private void PostProceed(HttpContext next) |
| | | { |
| | | //Console.WriteLine($"{DateTime.Now} middleware invoke postproceed"); |
| | | //.... |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="httpContext"></param> |
| | | /// <returns></returns> |
| | | public Task Invoke(HttpContext httpContext) |
| | | { |
| | | PreProceed(httpContext); |
| | | |
| | | |
| | | //æ£æµæ¯å¦å
å«'Authorization'请æ±å¤´ |
| | | if (!httpContext.Request.Headers.ContainsKey("Authorization")) |
| | | { |
| | | PostProceed(httpContext); |
| | | |
| | | return _next(httpContext); |
| | | } |
| | | //var tokenHeader = httpContext.Request.Headers["Authorization"].ToString(); |
| | | var tokenHeader = httpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); |
| | | |
| | | try |
| | | { |
| | | if (tokenHeader.Length >= 128) |
| | | { |
| | | //Console.WriteLine($"{DateTime.Now} token :{tokenHeader}"); |
| | | UserInfo tm = JwtHelper.SerializeJwt(tokenHeader); |
| | | |
| | | //ææ |
| | | //var claimList = new List<Claim>(); |
| | | //var claim = new Claim(ClaimTypes.Role, tm.Role); |
| | | //claimList.Add(claim); |
| | | //var identity = new ClaimsIdentity(claimList); |
| | | //var principal = new ClaimsPrincipal(identity); |
| | | //httpContext.User = principal; |
| | | } |
| | | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | Console.WriteLine($"{DateTime.Now} middleware wrong:{e.Message}"); |
| | | } |
| | | |
| | | |
| | | PostProceed(httpContext); |
| | | |
| | | |
| | | return _next(httpContext); |
| | | } |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Builder; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Middlewares |
| | | { |
| | | public static class MiddlewareHelpers |
| | | { |
| | | /// <summary> |
| | | /// 请æ±ååºä¸é´ä»¶ |
| | | /// </summary> |
| | | /// <param name="app"></param> |
| | | /// <returns></returns> |
| | | public static IApplicationBuilder UseApiLogMiddleware(this IApplicationBuilder app) |
| | | { |
| | | return app.UseMiddleware<ApiLogMiddleware>(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// èªå®ä¹ææä¸é´ä»¶ |
| | | /// </summary> |
| | | /// <param name="app"></param> |
| | | /// <returns></returns> |
| | | public static IApplicationBuilder UseJwtTokenAuth(this IApplicationBuilder app) |
| | | { |
| | | return app.UseMiddleware<JwtTokenAuthMiddleware>(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¼å¸¸å¤çä¸é´ä»¶ |
| | | /// </summary> |
| | | /// <param name="app"></param> |
| | | /// <returns></returns> |
| | | public static IApplicationBuilder UseExceptionHandlerMiddle(this IApplicationBuilder app) |
| | | { |
| | | return app.UseMiddleware<ExceptionHandlerMiddleware>(); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Builder; |
| | | using Microsoft.AspNetCore.Http; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Middlewares |
| | | { |
| | | public class SwaggerAuthMiddleware |
| | | { |
| | | |
| | | private readonly RequestDelegate next; |
| | | |
| | | public SwaggerAuthMiddleware(RequestDelegate next) |
| | | { |
| | | this.next = next; |
| | | } |
| | | |
| | | public async Task InvokeAsync(HttpContext context) |
| | | { |
| | | // ä¹å¯ä»¥æ ¹æ®æ¯å¦æ¯æ¬å°å夿 IsLocalRequest |
| | | if (context.Request.Path.Value.ToLower().Contains("index.html")) |
| | | { |
| | | // 夿æéæ¯å¦æ£ç¡® |
| | | if (IsAuthorized(context)) |
| | | { |
| | | await next.Invoke(context); |
| | | return; |
| | | } |
| | | |
| | | // æ æéï¼è·³è½¬swaggerç»å½é¡µ |
| | | context.Response.Redirect("/swg-login.html"); |
| | | } |
| | | else |
| | | { |
| | | await next.Invoke(context); |
| | | } |
| | | } |
| | | |
| | | public bool IsAuthorized(HttpContext context) |
| | | { |
| | | // 使ç¨sessionæ¨¡å¼ |
| | | // å¯ä»¥ä½¿ç¨å
¶ä»ç |
| | | return context.Session.GetString("swagger-code") == "success"; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 夿æ¯ä¸æ¯æ¬å°è®¿é® |
| | | /// æ¬å°ä¸ç¨swaggeræ¦æª |
| | | /// </summary> |
| | | /// <param name="context"></param> |
| | | /// <returns></returns> |
| | | public bool IsLocalRequest(HttpContext context) |
| | | { |
| | | if (context.Connection.RemoteIpAddress == null && context.Connection.LocalIpAddress == null) |
| | | { |
| | | return true; |
| | | } |
| | | if (context.Connection.RemoteIpAddress.Equals(context.Connection.LocalIpAddress)) |
| | | { |
| | | return true; |
| | | } |
| | | if (IPAddress.IsLoopback(context.Connection.RemoteIpAddress)) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | public static class SwaggerAuthorizeExtensions |
| | | { |
| | | public static IApplicationBuilder UseSwaggerAuthorized(this IApplicationBuilder builder) |
| | | { |
| | | return builder.UseMiddleware<SwaggerAuthMiddleware>(); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | |  |
| | | using Microsoft.AspNetCore.Builder; |
| | | using Swashbuckle.AspNetCore.SwaggerUI; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using static WIDESEAWCS_Core.Extensions.CustomApiVersion; |
| | | |
| | | namespace WIDESEAWCS_Core.Middlewares |
| | | { |
| | | /// <summary> |
| | | /// Swaggerä¸é´ä»¶ |
| | | /// </summary> |
| | | public static class SwaggerMiddleware |
| | | { |
| | | public static void UseSwaggerMiddle(this IApplicationBuilder app, Func<Stream> streamHtml) |
| | | { |
| | | if (app == null) throw new ArgumentNullException(nameof(app)); |
| | | |
| | | app.UseSwagger(); |
| | | app.UseSwaggerUI(c => |
| | | { |
| | | //æ ¹æ®çæ¬åç§°ååº éåå±ç¤º |
| | | var apiName = AppSettings.app(new string[] { "ApiName" }); |
| | | typeof(ApiVersions).GetEnumNames().OrderByDescending(e => e).ToList().ForEach(version => |
| | | { |
| | | c.SwaggerEndpoint($"/swagger/{version}/swagger.json", $"{apiName} {version}"); |
| | | }); |
| | | |
| | | //c.SwaggerEndpoint("/swagger/v1/swagger.json", "WIDESEA.Coreåå°Api"); |
| | | |
| | | //c.SwaggerEndpoint($"https://petstore.swagger.io/v2/swagger.json", $"{apiName} pet"); |
| | | |
| | | // å°swaggeré¦é¡µï¼è®¾ç½®ææä»¬èªå®ä¹ç页é¢ï¼è®°å¾è¿ä¸ªå符串çåæ³ï¼{项ç®å.index.html} |
| | | if (streamHtml.Invoke() == null) |
| | | { |
| | | var msg = "index.htmlç屿§ï¼å¿
须设置为åµå
¥çèµæº"; |
| | | //Log.Error(msg); |
| | | throw new Exception(msg); |
| | | } |
| | | c.IndexStream = streamHtml; |
| | | c.DocExpansion(DocExpansion.None); //->ä¿®æ¹ç颿弿¶èªå¨æå |
| | | |
| | | //if (Permissions.IsUseIds4) |
| | | //{ |
| | | // c.OAuthClientId("blogadminjs"); |
| | | //} |
| | | |
| | | |
| | | // è·¯å¾é
ç½®ï¼è®¾ç½®ä¸ºç©ºï¼è¡¨ç¤ºç´æ¥å¨æ ¹ååï¼localhost:8001ï¼è®¿é®è¯¥æä»¶,注ælocalhost:8001/swaggeræ¯è®¿é®ä¸å°çï¼å»launchSettings.jsonælaunchUrl廿ï¼å¦æä½ æ³æ¢ä¸ä¸ªè·¯å¾ï¼ç´æ¥åååå³å¯ï¼æ¯å¦ç´æ¥åc.RoutePrefix = "doc"; |
| | | c.RoutePrefix = ""; |
| | | }); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.DB; |
| | | using WIDESEAWCS_Core.Helper; |
| | | |
| | | namespace WIDESEAWCS_Core.Seed |
| | | { |
| | | public class DBContext |
| | | { |
| | | private static MutiDBOperate connectObject => GetMainConnectionDb(); |
| | | private static string _connectionString = connectObject.Connection; |
| | | private static DbType _dbType = (DbType)connectObject.DbType; |
| | | public static string ConnId = connectObject.ConnId; |
| | | private SqlSugarScope _db; |
| | | |
| | | /// <summary> |
| | | /// è¿æ¥å符串 |
| | | /// </summary> |
| | | public static MutiDBOperate GetMainConnectionDb() |
| | | { |
| | | MutiDBOperate mainDb = new MutiDBOperate() |
| | | { |
| | | Connection = AppSettings.app(MainDb.ConnectionString).DecryptDES(AppSecret.DB), |
| | | ConnId = MainDb.CurrentDbConnId, |
| | | DbType = DataBaseType.SqlServer |
| | | }; |
| | | |
| | | return mainDb; |
| | | } |
| | | /// <summary> |
| | | /// è¿æ¥å符串 |
| | | /// </summary> |
| | | public static string ConnectionString |
| | | { |
| | | get { return _connectionString; } |
| | | set { _connectionString = value; } |
| | | } |
| | | /// <summary> |
| | | /// æ°æ®åºç±»å |
| | | /// </summary> |
| | | public static DbType DbType |
| | | { |
| | | get { return _dbType; } |
| | | set { _dbType = value; } |
| | | } |
| | | /// <summary> |
| | | /// æ°æ®è¿æ¥å¯¹è±¡ |
| | | /// </summary> |
| | | public SqlSugarScope Db |
| | | { |
| | | get { return _db; } |
| | | private set { _db = value; } |
| | | } |
| | | |
| | | //public SqlSugarScope DbClient |
| | | //{ |
| | | // get { return _dbClient; } |
| | | // private set { _dbClient = value; } |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// åè½æè¿°:æé 彿° |
| | | /// </summary> |
| | | public DBContext(ISqlSugarClient sqlSugarClient) |
| | | { |
| | | if (string.IsNullOrEmpty(_connectionString)) |
| | | throw new ArgumentNullException("æ°æ®åºè¿æ¥å符串为空"); |
| | | |
| | | _db = sqlSugarClient as SqlSugarScope; |
| | | //_db.Aop.DataExecuting = SqlSugarAop.DataExecuting; |
| | | } |
| | | |
| | | #region å®ä¾æ¹æ³ |
| | | /// <summary> |
| | | /// åè½æè¿°:è·åæ°æ®åºå¤ç对象 |
| | | /// </summary> |
| | | /// <returns>è¿åå¼</returns> |
| | | public SimpleClient<T> GetEntityDB<T>() where T : class, new() |
| | | { |
| | | return new SimpleClient<T>(_db); |
| | | } |
| | | /// <summary> |
| | | /// åè½æè¿°:è·åæ°æ®åºå¤ç对象 |
| | | /// </summary> |
| | | /// <param name="db">db</param> |
| | | /// <returns>è¿åå¼</returns> |
| | | //public SimpleClient<T> GetEntityDB<T>(SqlSugarClient db) where T : class, new() |
| | | //{ |
| | | // return new SimpleClient<T>(db); |
| | | //} |
| | | |
| | | |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #region æ ¹æ®å®ä½ç±»çææ°æ®åºè¡¨ |
| | | /// <summary> |
| | | /// åè½æè¿°:æ ¹æ®å®ä½ç±»çææ°æ®åºè¡¨ |
| | | /// </summary> |
| | | /// <param name="blnBackupTable">æ¯å¦å¤ä»½è¡¨</param> |
| | | /// <param name="lstEntitys">æå®çå®ä½</param> |
| | | public void CreateTableByEntity<T>(bool blnBackupTable, params T[] lstEntitys) where T : class, new() |
| | | { |
| | | Type[] lstTypes = null; |
| | | if (lstEntitys != null) |
| | | { |
| | | lstTypes = new Type[lstEntitys.Length]; |
| | | for (int i = 0; i < lstEntitys.Length; i++) |
| | | { |
| | | T t = lstEntitys[i]; |
| | | lstTypes[i] = typeof(T); |
| | | } |
| | | } |
| | | CreateTableByEntity(blnBackupTable, lstTypes); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åè½æè¿°:æ ¹æ®å®ä½ç±»çææ°æ®åºè¡¨ |
| | | /// </summary> |
| | | /// <param name="blnBackupTable">æ¯å¦å¤ä»½è¡¨</param> |
| | | /// <param name="lstEntitys">æå®çå®ä½</param> |
| | | public void CreateTableByEntity(bool blnBackupTable, params Type[] lstEntitys) |
| | | { |
| | | if (blnBackupTable) |
| | | { |
| | | _db.CodeFirst.BackupTable().InitTables(lstEntitys); //change entity backupTable |
| | | } |
| | | else |
| | | { |
| | | _db.CodeFirst.InitTables(lstEntitys); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region éææ¹æ³ |
| | | |
| | | ///// <summary> |
| | | ///// åè½æè¿°:è·å¾ä¸ä¸ªDbContext |
| | | ///// </summary> |
| | | ///// <returns></returns> |
| | | //public static MyContext GetDbContext() |
| | | //{ |
| | | // return new MyContext(); |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// åè½æè¿°:设置åå§ååæ° |
| | | /// </summary> |
| | | /// <param name="strConnectionString">è¿æ¥å符串</param> |
| | | /// <param name="enmDbType">æ°æ®åºç±»å</param> |
| | | public static void Init(string strConnectionString, DbType enmDbType = SqlSugar.DbType.SqlServer) |
| | | { |
| | | _connectionString = strConnectionString; |
| | | _dbType = enmDbType; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åè½æè¿°:å建ä¸ä¸ªé¾æ¥é
ç½® |
| | | /// </summary> |
| | | /// <param name="blnIsAutoCloseConnection">æ¯å¦èªå¨å
³éè¿æ¥</param> |
| | | /// <param name="blnIsShardSameThread">æ¯å¦å¤¸ç±»äºå¡</param> |
| | | /// <returns>ConnectionConfig</returns> |
| | | public static ConnectionConfig GetConnectionConfig(bool blnIsAutoCloseConnection = true, bool blnIsShardSameThread = false) |
| | | { |
| | | ConnectionConfig config = new ConnectionConfig() |
| | | { |
| | | ConnectionString = _connectionString, |
| | | DbType = _dbType, |
| | | IsAutoCloseConnection = blnIsAutoCloseConnection, |
| | | ConfigureExternalServices = new ConfigureExternalServices() |
| | | { |
| | | //DataInfoCacheService = new HttpRuntimeCache() |
| | | }, |
| | | //IsShardSameThread = blnIsShardSameThread |
| | | }; |
| | | return config; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åè½æè¿°:è·åä¸ä¸ªèªå®ä¹çDB |
| | | /// </summary> |
| | | /// <param name="config">config</param> |
| | | /// <returns>è¿åå¼</returns> |
| | | public static SqlSugarScope GetCustomDB(ConnectionConfig config) |
| | | { |
| | | return new SqlSugarScope(config); |
| | | } |
| | | /// <summary> |
| | | /// åè½æè¿°:è·åä¸ä¸ªèªå®ä¹çæ°æ®åºå¤ç对象 |
| | | /// </summary> |
| | | /// <param name="sugarClient">sugarClient</param> |
| | | /// <returns>è¿åå¼</returns> |
| | | //public static SqlSugarScope<T> GetCustomEntityDB<T>(SqlSugarScope sugarClient) where T : class, new() |
| | | //{ |
| | | // return new SqlSugarScope<T>(sugarClient); |
| | | //} |
| | | /// <summary> |
| | | /// åè½æè¿°:è·åä¸ä¸ªèªå®ä¹çæ°æ®åºå¤ç对象 |
| | | /// </summary> |
| | | /// <param name="config">config</param> |
| | | /// <returns>è¿åå¼</returns> |
| | | //public static SimpleClient<T> GetCustomEntityDB<T>(ConnectionConfig config) where T : class, new() |
| | | //{ |
| | | // SqlSugarScope sugarClient = GetCustomDB(config); |
| | | // return GetCustomEntityDB<T>(sugarClient); |
| | | //} |
| | | #endregion |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Castle.Components.DictionaryAdapter.Xml; |
| | | using Microsoft.AspNetCore.Mvc.Rendering; |
| | | using Newtonsoft.Json; |
| | | using SkiaSharp; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Dynamic; |
| | | using System.Linq; |
| | | using System.Net.Sockets; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.DB; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.Tenants; |
| | | |
| | | namespace WIDESEAWCS_Core.Seed |
| | | { |
| | | public class DBSeed |
| | | { |
| | | private static string SeedDataFolder = "WIDESEAWCS_DB.DBSeed.Json/{0}.tsv"; |
| | | |
| | | /// <summary> |
| | | /// 弿¥æ·»å ç§åæ°æ® |
| | | /// </summary> |
| | | /// <param name="myContext"></param> |
| | | /// <param name="WebRootPath"></param> |
| | | /// <returns></returns> |
| | | public static async Task SeedAsync(DBContext dbContext, string WebRootPath) |
| | | { |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(WebRootPath)) |
| | | { |
| | | throw new Exception("è·åwwwrootè·¯å¾æ¶ï¼å¼å¸¸ï¼"); |
| | | } |
| | | |
| | | SeedDataFolder = Path.Combine(WebRootPath, SeedDataFolder); |
| | | |
| | | Console.WriteLine("************ WIDESEA DataBase Set *****************"); |
| | | |
| | | //Console.WriteLine($"Master DB ConId: {DBContext.ConnId}"); |
| | | Console.WriteLine($"Master DB Type: {DBContext.DbType}"); |
| | | //Console.WriteLine($"Master DB ConnectString: {DBContext.ConnectionString}"); |
| | | |
| | | Console.WriteLine(); |
| | | |
| | | // åå»ºæ°æ®åº |
| | | Console.WriteLine($"Create Database(The Db Id:{DBContext.ConnId})..."); |
| | | |
| | | if (DBContext.DbType != SqlSugar.DbType.Oracle) |
| | | { |
| | | dbContext.Db.DbMaintenance.CreateDatabase(); |
| | | ConsoleHelper.WriteSuccessLine($"Database Created Successfully!"); |
| | | } |
| | | else |
| | | { |
| | | //Oracle æ°æ®åºä¸æ¯æè¯¥æä½ |
| | | ConsoleHelper.WriteSuccessLine($"Oracle æ°æ®åºä¸æ¯æè¯¥æä½ï¼å¯æå¨å建Oracleæ°æ®åº!"); |
| | | } |
| | | |
| | | // åå»ºæ°æ®åºè¡¨ï¼éåæå®å½å空é´ä¸çclassï¼ |
| | | // 注æä¸è¦æå
¶ä»å½å空é´ä¸ç乿·»å è¿æ¥ã |
| | | Console.WriteLine("Create Tables..."); |
| | | |
| | | var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; |
| | | var referencedAssemblies = System.IO.Directory.GetFiles(path, MainDb.AssemblyName).Select(Assembly.LoadFrom).ToArray(); |
| | | |
| | | var modelTypes = referencedAssemblies |
| | | .SelectMany(a => a.DefinedTypes) |
| | | .Select(type => type.AsType()) |
| | | .Where(x => x.IsClass && x.Namespace is MainDb.EntityNameSpace && x.GetCustomAttribute<SugarTable>() != null) |
| | | .ToList(); |
| | | |
| | | modelTypes.ForEach(t => |
| | | { |
| | | //var diffString = dbContext.Db.CodeFirst.GetDifferenceTables(t).ToDiffString(); |
| | | // è¿éåªæ¯ææ·»å 表ï¼ä¸æ¯æå é¤ |
| | | // 妿æ³è¦å é¤ï¼æ°æ®åºç´æ¥å³é®å é¤ï¼æè
èç³»SqlSugarä½è
ï¼ |
| | | IDbMaintenance dbMaintenance = dbContext.Db.DbMaintenance; |
| | | if (!dbMaintenance.IsAnyTable(t.Name, false)) |
| | | { |
| | | ConsoleHelper.WriteSuccessLine($"Table [{t.Name}] Created Successfully"); |
| | | dbContext.Db.CodeFirst.InitTables(t); |
| | | |
| | | string seedData = FileHelper.ReadFile(string.Format(SeedDataFolder, t.Name), Encoding.UTF8); |
| | | |
| | | #region AddSeedData |
| | | if (seedData != "ä¸åå¨ç¸åºçç®å½") |
| | | { |
| | | List<Dictionary<string, object>> dicFile = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(seedData); |
| | | |
| | | if (dicFile.Count > 0) |
| | | { |
| | | List<Dictionary<string, object>> dic = new List<Dictionary<string, object>>(); |
| | | |
| | | List<string> columnNames = dbContext.Db.DbMaintenance.GetColumnInfosByTableName(t.Name, false).Select(x => x.DbColumnName).ToList(); |
| | | var a = t.GetProperties().FirstOrDefault(x => !columnNames.Contains(x.Name)); |
| | | |
| | | List<PropertyInfo> propertyInfos = t.GetProperties().Where(x => columnNames.Contains(x.Name)).ToList(); |
| | | for (int j = 0; j < dicFile.Count; j++) |
| | | { |
| | | Dictionary<string, object> keyValuePairs = new Dictionary<string, object>(); |
| | | for (int i = 0; i < propertyInfos.Count; i++) |
| | | { |
| | | PropertyInfo propertyInfo = propertyInfos[i]; |
| | | SugarColumn sugarColumn = propertyInfo.GetCustomAttribute<SugarColumn>(); |
| | | if (sugarColumn != null) |
| | | { |
| | | if (!sugarColumn.IsIgnore) |
| | | { |
| | | keyValuePairs.Add(propertyInfo.Name, dicFile[j][propertyInfo.Name]); |
| | | } |
| | | } |
| | | } |
| | | dic.Add(keyValuePairs); |
| | | } |
| | | |
| | | if (dic.Count > 0) |
| | | { |
| | | for (int i = 0; i < dic.Count; i++) |
| | | { |
| | | if (dic[i].ContainsKey("CreateDate")) |
| | | dic[i]["CreateDate"] = DateTime.Now; |
| | | else |
| | | dic[i].Add("CreateDate", DateTime.Now); |
| | | } |
| | | string str = $"SET IDENTITY_INSERT {t.Name} ON;"; |
| | | |
| | | str += dbContext.Db.Insertable(dic).AS(t.Name).ToSqlString(); |
| | | |
| | | str += ($"SET IDENTITY_INSERT {t.Name} OFF;"); |
| | | |
| | | dbContext.Db.Ado.ExecuteCommand(str); |
| | | |
| | | ConsoleHelper.WriteSuccessLine($"Table [{t.Name}] SeedData Added Successfully"); |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | else |
| | | { |
| | | List<string> columnNames = dbContext.Db.DbMaintenance.GetColumnInfosByTableName(t.Name, false).Select(x => x.DbColumnName).ToList(); |
| | | if (t.GetProperties().FirstOrDefault(x => !columnNames.Contains(x.Name)) != null) |
| | | { |
| | | bool isChange = true; |
| | | List<PropertyInfo> propertyInfos = t.GetProperties().Where(x => !columnNames.Contains(x.Name)).ToList(); |
| | | for (int i = 0; i < propertyInfos.Count; i++) |
| | | { |
| | | PropertyInfo propertyInfo = propertyInfos[i]; |
| | | SugarColumn sugarColumn = propertyInfo.GetCustomAttribute<SugarColumn>(); |
| | | if (sugarColumn != null) |
| | | { |
| | | if (!sugarColumn.IsIgnore) |
| | | { |
| | | if (!sugarColumn.IsNullable) |
| | | { |
| | | isChange = false; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (isChange) |
| | | dbContext.Db.CodeFirst.InitTables(t); |
| | | } |
| | | } |
| | | }); |
| | | ConsoleHelper.WriteSuccessLine($"Tables Created Successfully!"); |
| | | Console.WriteLine(); |
| | | |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 1ãè¥æ¯Mysql,æ¥ç常è§é®é¢:https://github.com/anjoy8/Blog.Core/issues/148#issue-776281770 |
| | | //2ãè¥æ¯Oracle,æ¥ç常è§é®é¢:https://github.com/anjoy8/Blog.Core/issues/148#issuecomment-752340231 |
| | | throw new Exception("é误ï¼" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åå§å å¤ç§æ· |
| | | /// </summary> |
| | | /// <param name="dbContext"></param> |
| | | /// <returns></returns> |
| | | public static async Task TenantSeedAsync(DBContext dbContext) |
| | | { |
| | | |
| | | if (BaseDBConfig.MutiConnectionString.Where(x => x.ConnId != MainDb.CurrentDbConnId).Any()) |
| | | { |
| | | Console.WriteLine($@"Init Multi Tenant Db"); |
| | | foreach (MutiDBOperate tenant in BaseDBConfig.MutiConnectionString.Where(x => x.ConnId != MainDb.CurrentDbConnId)) |
| | | { |
| | | |
| | | Console.WriteLine($@"Init Multi Tenant Db : {tenant.ConnId}"); |
| | | ConnectionConfig connectionConfig = new ConnectionConfig() |
| | | { |
| | | ConfigId = tenant.ConnId, |
| | | ConnectionString = tenant.Connection, |
| | | IsAutoCloseConnection = true, |
| | | MoreSettings = new ConnMoreSettings() |
| | | { |
| | | IsAutoRemoveDataCache = true |
| | | }, |
| | | DbType = (DbType)tenant.DbType, |
| | | }; |
| | | await InitTenantSeedAsync(dbContext.Db.AsTenant(), connectionConfig); |
| | | } |
| | | |
| | | Console.WriteLine(DateTime.Now + $@"Init Multi Tenant Db Finish"); |
| | | } |
| | | |
| | | //tenants = await myContext.Db.Queryable<SysTenant>().Where(s => s.TenantType == TenantTypeEnum.Tables).ToListAsync(); |
| | | //if (tenants.Any()) |
| | | //{ |
| | | // await InitTenantSeedAsync(myContext, tenants); |
| | | //} |
| | | } |
| | | |
| | | #region å¤ç§æ· å¤åº åå§å |
| | | |
| | | /// <summary> |
| | | /// åå§åå¤åº |
| | | /// </summary> |
| | | /// <param name="itenant"></param> |
| | | /// <param name="config"></param> |
| | | /// <returns></returns> |
| | | public static async Task InitTenantSeedAsync(ITenant itenant, ConnectionConfig config) |
| | | { |
| | | Console.WriteLine(DateTime.Now + $@"Init Multi Tenant Db"); |
| | | //itenant.RemoveConnection(config.ConfigId); |
| | | itenant.AddConnection(config); |
| | | |
| | | var db = itenant.GetConnectionScope(config.ConfigId); |
| | | |
| | | db.DbMaintenance.CreateDatabase(); |
| | | ConsoleHelper.WriteSuccessLine($"Init Multi Tenant Db : {config.ConfigId} Database created successfully!"); |
| | | |
| | | Console.WriteLine($@"Init Multi Tenant Db : {config.ConfigId} Create Tables"); |
| | | |
| | | // è·åææå®ä½è¡¨-åå§åç§æ·ä¸å¡è¡¨ |
| | | var entityTypes = TenantUtil.GetTenantEntityTypes(TenantTypeEnum.Db); |
| | | if (!entityTypes.Any()) return; |
| | | foreach (var entityType in entityTypes) |
| | | { |
| | | //var splitTable = entityType.GetCustomAttribute<SplitTableAttribute>(); |
| | | //if (splitTable == null) |
| | | db.CodeFirst.InitTables(entityType); |
| | | //else |
| | | // db.CodeFirst.SplitTables().InitTables(entityType); |
| | | |
| | | Console.WriteLine(entityType.Name); |
| | | } |
| | | Console.WriteLine(DateTime.Now + $@"Init Multi Tenant Db Finish"); |
| | | //å¤ç§æ·åå§åç§åæ°æ® |
| | | //await TenantSeedDataAsync(db, TenantTypeEnum.Db); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | //private static async Task TenantSeedDataAsync(ISqlSugarClient db, TenantTypeEnum tenantType) |
| | | //{ |
| | | // // è·åææç§åé
ç½®-åå§åæ°æ® |
| | | // var seedDataTypes = AssemblysExtensions.GetAllAssemblies().SelectMany(s => s.DefinedTypes) |
| | | // .Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass) |
| | | // .Where(u => |
| | | // { |
| | | // var esd = u.GetInterfaces().FirstOrDefault(i => i.HasImplementedRawGeneric(typeof(IEntitySeedData<>))); |
| | | // if (esd is null) |
| | | // { |
| | | // return false; |
| | | // } |
| | | |
| | | // var eType = esd.GenericTypeArguments[0]; |
| | | // return eType.IsTenantEntity(tenantType); |
| | | // }); |
| | | // if (!seedDataTypes.Any()) return; |
| | | // foreach (var seedType in seedDataTypes) |
| | | // { |
| | | // dynamic instance = Activator.CreateInstance(seedType); |
| | | // //åå§åæ°æ® |
| | | // { |
| | | // var seedData = instance.InitSeedData(); |
| | | // if (seedData != null && Enumerable.Any(seedData)) |
| | | // { |
| | | // var entityType = seedType.GetInterfaces().First().GetGenericArguments().First(); |
| | | // var entity = db.EntityMaintenance.GetEntityInfo(entityType); |
| | | |
| | | // if (!await db.Queryable(entity.DbTableName, "").AnyAsync()) |
| | | // { |
| | | // await db.Insertable(Enumerable.ToList(seedData)).ExecuteCommandAsync(); |
| | | // Console.WriteLine($"Table:{entity.DbTableName} init success!"); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | // //ç§åæ°æ® |
| | | // { |
| | | // var seedData = instance.SeedData(); |
| | | // if (seedData != null && Enumerable.Any(seedData)) |
| | | // { |
| | | // var entityType = seedType.GetInterfaces().First().GetGenericArguments().First(); |
| | | // var entity = db.EntityMaintenance.GetEntityInfo(entityType); |
| | | |
| | | // await db.Storageable(Enumerable.ToList(seedData)).ExecuteCommandAsync(); |
| | | // Console.WriteLine($"Table:{entity.DbTableName} seedData success!"); |
| | | // } |
| | | // } |
| | | |
| | | // //èªå®ä¹å¤ç |
| | | // { |
| | | // await instance.CustomizeSeedData(db); |
| | | // } |
| | | // } |
| | | //} |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Seed |
| | | { |
| | | public class FrameSeed |
| | | { |
| | | |
| | | /// <summary> |
| | | /// çæControllerå± |
| | | /// </summary> |
| | | /// <param name="sqlSugarClient">sqlsugarå®ä¾</param> |
| | | /// <param name="ConnId">æ°æ®åºé¾æ¥ID</param> |
| | | /// <param name="tableNames">æ°æ®åºè¡¨åæ°ç»ï¼é»è®¤ç©ºï¼çæææè¡¨</param> |
| | | /// <param name="isMuti"></param> |
| | | /// <returns></returns> |
| | | public static bool CreateControllers(SqlSugarScope sqlSugarClient, string ConnId = null, bool isMuti = false, string[] tableNames = null) |
| | | { |
| | | Create_Controller_ClassFileByDBTalbe(sqlSugarClient, ConnId, $@"C:\my-file\Blog.Core.Api.Controllers", "Blog.Core.Api.Controllers", tableNames, "", isMuti); |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// çæModelå± |
| | | /// </summary> |
| | | /// <param name="sqlSugarClient">sqlsugarå®ä¾</param> |
| | | /// <param name="ConnId">æ°æ®åºé¾æ¥ID</param> |
| | | /// <param name="tableNames">æ°æ®åºè¡¨åæ°ç»ï¼é»è®¤ç©ºï¼çæææè¡¨</param> |
| | | /// <param name="isMuti"></param> |
| | | /// <returns></returns> |
| | | public static bool CreateModels(SqlSugarScope sqlSugarClient, string ConnId, bool isMuti = false, string[] tableNames = null) |
| | | { |
| | | Create_Model_ClassFileByDBTalbe(sqlSugarClient, ConnId, $@"C:\my-file\Blog.Core.Model", "Blog.Core.Model.Models", tableNames, "", isMuti); |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// çæIRepositoryå± |
| | | /// </summary> |
| | | /// <param name="sqlSugarClient">sqlsugarå®ä¾</param> |
| | | /// <param name="ConnId">æ°æ®åºé¾æ¥ID</param> |
| | | /// <param name="isMuti"></param> |
| | | /// <param name="tableNames">æ°æ®åºè¡¨åæ°ç»ï¼é»è®¤ç©ºï¼çæææè¡¨</param> |
| | | /// <returns></returns> |
| | | public static bool CreateIRepositorys(SqlSugarScope sqlSugarClient, string ConnId, bool isMuti = false, string[] tableNames = null) |
| | | { |
| | | Create_IRepository_ClassFileByDBTalbe(sqlSugarClient, ConnId, $@"C:\my-file\Blog.Core.IRepository", "Blog.Core.IRepository", tableNames, "", isMuti); |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// çæ IService å± |
| | | /// </summary> |
| | | /// <param name="sqlSugarClient">sqlsugarå®ä¾</param> |
| | | /// <param name="ConnId">æ°æ®åºé¾æ¥ID</param> |
| | | /// <param name="isMuti"></param> |
| | | /// <param name="tableNames">æ°æ®åºè¡¨åæ°ç»ï¼é»è®¤ç©ºï¼çæææè¡¨</param> |
| | | /// <returns></returns> |
| | | public static bool CreateIServices(SqlSugarScope sqlSugarClient, string ConnId, bool isMuti = false, string[] tableNames = null) |
| | | { |
| | | Create_IServices_ClassFileByDBTalbe(sqlSugarClient, ConnId, $@"C:\my-file\Blog.Core.IServices", "Blog.Core.IServices", tableNames, "", isMuti); |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// çæ Repository å± |
| | | /// </summary> |
| | | /// <param name="sqlSugarClient">sqlsugarå®ä¾</param> |
| | | /// <param name="ConnId">æ°æ®åºé¾æ¥ID</param> |
| | | /// <param name="isMuti"></param> |
| | | /// <param name="tableNames">æ°æ®åºè¡¨åæ°ç»ï¼é»è®¤ç©ºï¼çæææè¡¨</param> |
| | | /// <returns></returns> |
| | | public static bool CreateRepository(SqlSugarScope sqlSugarClient, string ConnId, bool isMuti = false, string[] tableNames = null) |
| | | { |
| | | Create_Repository_ClassFileByDBTalbe(sqlSugarClient, ConnId, $@"C:\my-file\Blog.Core.Repository", "Blog.Core.Repository", tableNames, "", isMuti); |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// çæ Service å± |
| | | /// </summary> |
| | | /// <param name="sqlSugarClient">sqlsugarå®ä¾</param> |
| | | /// <param name="ConnId">æ°æ®åºé¾æ¥ID</param> |
| | | /// <param name="isMuti"></param> |
| | | /// <param name="tableNames">æ°æ®åºè¡¨åæ°ç»ï¼é»è®¤ç©ºï¼çæææè¡¨</param> |
| | | /// <returns></returns> |
| | | public static bool CreateServices(SqlSugarScope sqlSugarClient, string ConnId, bool isMuti = false, string[] tableNames = null) |
| | | { |
| | | Create_Services_ClassFileByDBTalbe(sqlSugarClient, ConnId, $@"C:\my-file\Blog.Core.Services", "Blog.Core.Services", tableNames, "", isMuti); |
| | | return true; |
| | | } |
| | | |
| | | |
| | | #region æ ¹æ®æ°æ®åºè¡¨ç产Controllerå± |
| | | |
| | | /// <summary> |
| | | /// åè½æè¿°:æ ¹æ®æ°æ®åºè¡¨ç产Controllerå± |
| | | /// ä½ããè
:Blog.Core |
| | | /// </summary> |
| | | /// <param name="sqlSugarClient"></param> |
| | | /// <param name="ConnId">æ°æ®åºé¾æ¥ID</param> |
| | | /// <param name="strPath">å®ä½ç±»åæ¾è·¯å¾</param> |
| | | /// <param name="strNameSpace">å½å空é´</param> |
| | | /// <param name="lstTableNames">ç产æå®ç表</param> |
| | | /// <param name="strInterface">å®ç°æ¥å£</param> |
| | | /// <param name="isMuti"></param> |
| | | /// <param name="blnSerializable">æ¯å¦åºåå</param> |
| | | private static void Create_Controller_ClassFileByDBTalbe( |
| | | SqlSugarScope sqlSugarClient, |
| | | string ConnId, |
| | | string strPath, |
| | | string strNameSpace, |
| | | string[] lstTableNames, |
| | | string strInterface, |
| | | bool isMuti = false, |
| | | bool blnSerializable = false) |
| | | { |
| | | var IDbFirst = sqlSugarClient.DbFirst; |
| | | if (lstTableNames != null && lstTableNames.Length > 0) |
| | | { |
| | | IDbFirst = IDbFirst.Where(lstTableNames); |
| | | } |
| | | var ls = IDbFirst.IsCreateDefaultValue().IsCreateAttribute() |
| | | |
| | | .SettingClassTemplate(p => p = |
| | | @"using Blog.Core.IServices; |
| | | using Blog.Core.Model; |
| | | using Blog.Core.Model.Models; |
| | | using Microsoft.AspNetCore.Authorization; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using System; |
| | | using System.Linq.Expressions; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace " + strNameSpace + @" |
| | | { |
| | | [Route(""api/[controller]/[action]"")] |
| | | [ApiController] |
| | | [Authorize(Permissions.Name)] |
| | | public class {ClassName}Controller : ControllerBase |
| | | { |
| | | /// <summary> |
| | | /// æå¡å¨æ¥å£ï¼å ä¸ºæ¯æ¨¡æ¿çæï¼æä»¥é¦åæ¯æ¯å¤§åçï¼èªå·±å¯ä»¥éæä¸ |
| | | /// </summary> |
| | | private readonly I{ClassName}Services _{ClassName}Services; |
| | | |
| | | public {ClassName}Controller(I{ClassName}Services {ClassName}Services) |
| | | { |
| | | _{ClassName}Services = {ClassName}Services; |
| | | } |
| | | |
| | | [HttpGet] |
| | | public async Task<MessageModel<PageModel<{ClassName}>>> Get(int page = 1, string key = """",int intPageSize = 50) |
| | | { |
| | | if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key)) |
| | | { |
| | | key = """"; |
| | | } |
| | | |
| | | Expression<Func<{ClassName}, bool>> whereExpression = a => true; |
| | | |
| | | return new MessageModel<PageModel<{ClassName}>>() |
| | | { |
| | | msg = ""è·åæå"", |
| | | success = true, |
| | | response = await _{ClassName}Services.QueryPage(whereExpression, page, intPageSize) |
| | | }; |
| | | |
| | | } |
| | | |
| | | [HttpGet(""{id}"")] |
| | | public async Task<MessageModel<{ClassName}>> Get(string id) |
| | | { |
| | | return new MessageModel<{ClassName}>() |
| | | { |
| | | msg = ""è·åæå"", |
| | | success = true, |
| | | response = await _{ClassName}Services.QueryById(id) |
| | | }; |
| | | } |
| | | |
| | | [HttpPost] |
| | | public async Task<MessageModel<string>> Post([FromBody] {ClassName} request) |
| | | { |
| | | var data = new MessageModel<string>(); |
| | | |
| | | var id = await _{ClassName}Services.Add(request); |
| | | data.success = id > 0; |
| | | if (data.success) |
| | | { |
| | | data.response = id.ObjToString(); |
| | | data.msg = ""æ·»å æå""; |
| | | } |
| | | |
| | | return data; |
| | | } |
| | | |
| | | [HttpPut] |
| | | public async Task<MessageModel<string>> Put([FromBody] {ClassName} request) |
| | | { |
| | | var data = new MessageModel<string>(); |
| | | data.success = await _{ClassName}Services.Update(request); |
| | | if (data.success) |
| | | { |
| | | data.msg = ""æ´æ°æå""; |
| | | data.response = request?.id.ObjToString(); |
| | | } |
| | | |
| | | return data; |
| | | } |
| | | |
| | | [HttpDelete] |
| | | public async Task<MessageModel<string>> Delete(int id) |
| | | { |
| | | var data = new MessageModel<string>(); |
| | | var model = await _{ClassName}Services.QueryById(id); |
| | | model.IsDeleted = true; |
| | | data.success = await _departmentServices.Update(model); |
| | | if (data.success) |
| | | { |
| | | data.msg = ""å 餿å""; |
| | | data.response = model?.Id.ObjToString(); |
| | | } |
| | | |
| | | return data; |
| | | } |
| | | } |
| | | }") |
| | | |
| | | .ToClassStringList(strNameSpace); |
| | | |
| | | Dictionary<string, string> newdic = new Dictionary<string, string>(); |
| | | //循ç¯å¤ç é¦åæ¯å°å å¹¶æå
¥æ°ç Dictionary |
| | | foreach (KeyValuePair<string, string> item in ls) |
| | | { |
| | | string newkey = "_" + item.Key.First().ToString().ToLower() + item.Key.Substring(1); |
| | | string newvalue = item.Value.Replace("_" + item.Key, newkey); |
| | | newdic.Add(item.Key, newvalue); |
| | | } |
| | | CreateFilesByClassStringList(newdic, strPath, "{0}Controller"); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region æ ¹æ®æ°æ®åºè¡¨ç产Modelå± |
| | | |
| | | /// <summary> |
| | | /// åè½æè¿°:æ ¹æ®æ°æ®åºè¡¨ç产Modelå± |
| | | /// ä½ããè
:Blog.Core |
| | | /// </summary> |
| | | /// <param name="sqlSugarClient"></param> |
| | | /// <param name="ConnId">æ°æ®åºé¾æ¥ID</param> |
| | | /// <param name="strPath">å®ä½ç±»åæ¾è·¯å¾</param> |
| | | /// <param name="strNameSpace">å½å空é´</param> |
| | | /// <param name="lstTableNames">ç产æå®ç表</param> |
| | | /// <param name="strInterface">å®ç°æ¥å£</param> |
| | | /// <param name="isMuti"></param> |
| | | /// <param name="blnSerializable">æ¯å¦åºåå</param> |
| | | private static void Create_Model_ClassFileByDBTalbe( |
| | | SqlSugarScope sqlSugarClient, |
| | | string ConnId, |
| | | string strPath, |
| | | string strNameSpace, |
| | | string[] lstTableNames, |
| | | string strInterface, |
| | | bool isMuti = false, |
| | | bool blnSerializable = false) |
| | | { |
| | | //å¤åºæä»¶å离 |
| | | if (isMuti) |
| | | { |
| | | strPath = strPath + @"\Models\" + ConnId; |
| | | strNameSpace = strNameSpace + "." + ConnId; |
| | | } |
| | | |
| | | var IDbFirst = sqlSugarClient.DbFirst; |
| | | if (lstTableNames != null && lstTableNames.Length > 0) |
| | | { |
| | | IDbFirst = IDbFirst.Where(lstTableNames); |
| | | } |
| | | var ls = IDbFirst.IsCreateDefaultValue().IsCreateAttribute() |
| | | |
| | | .SettingClassTemplate(p => p = |
| | | @"{using} |
| | | |
| | | namespace " + strNameSpace + @" |
| | | { |
| | | {ClassDescription} |
| | | [SugarTable( ""{ClassName}"", """ + ConnId + @""")]" + (blnSerializable ? "\n [Serializable]" : "") + @" |
| | | public class {ClassName}" + (string.IsNullOrEmpty(strInterface) ? "" : (" : " + strInterface)) + @" |
| | | { |
| | | public {ClassName}() |
| | | { |
| | | } |
| | | {PropertyName} |
| | | } |
| | | }") |
| | | //.SettingPropertyDescriptionTemplate(p => p = string.Empty) |
| | | .SettingPropertyTemplate(p => p = |
| | | @"{SugarColumn} |
| | | public {PropertyType} {PropertyName} { get; set; }") |
| | | |
| | | //.SettingConstructorTemplate(p => p = " this._{PropertyName} ={DefaultValue};") |
| | | |
| | | .ToClassStringList(strNameSpace); |
| | | CreateFilesByClassStringList(ls, strPath, "{0}"); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region æ ¹æ®æ°æ®åºè¡¨ç产IRepositoryå± |
| | | |
| | | /// <summary> |
| | | /// åè½æè¿°:æ ¹æ®æ°æ®åºè¡¨ç产IRepositoryå± |
| | | /// ä½ããè
:Blog.Core |
| | | /// </summary> |
| | | /// <param name="sqlSugarClient"></param> |
| | | /// <param name="ConnId">æ°æ®åºé¾æ¥ID</param> |
| | | /// <param name="strPath">å®ä½ç±»åæ¾è·¯å¾</param> |
| | | /// <param name="strNameSpace">å½å空é´</param> |
| | | /// <param name="lstTableNames">ç产æå®ç表</param> |
| | | /// <param name="strInterface">å®ç°æ¥å£</param> |
| | | /// <param name="isMuti"></param> |
| | | private static void Create_IRepository_ClassFileByDBTalbe( |
| | | SqlSugarScope sqlSugarClient, |
| | | string ConnId, |
| | | string strPath, |
| | | string strNameSpace, |
| | | string[] lstTableNames, |
| | | string strInterface, |
| | | bool isMuti = false |
| | | ) |
| | | { |
| | | //å¤åºæä»¶å离 |
| | | if (isMuti) |
| | | { |
| | | strPath = strPath + @"\" + ConnId; |
| | | strNameSpace = strNameSpace + "." + ConnId; |
| | | } |
| | | |
| | | var IDbFirst = sqlSugarClient.DbFirst; |
| | | if (lstTableNames != null && lstTableNames.Length > 0) |
| | | { |
| | | IDbFirst = IDbFirst.Where(lstTableNames); |
| | | } |
| | | var ls = IDbFirst.IsCreateDefaultValue().IsCreateAttribute() |
| | | |
| | | .SettingClassTemplate(p => p = |
| | | @"using Blog.Core.IRepository.Base; |
| | | using Blog.Core.Model.Models" + (isMuti ? "." + ConnId + "" : "") + @"; |
| | | |
| | | namespace " + strNameSpace + @" |
| | | { |
| | | /// <summary> |
| | | /// I{ClassName}Repository |
| | | /// </summary> |
| | | public interface I{ClassName}Repository : IBaseRepository<{ClassName}>" + (string.IsNullOrEmpty(strInterface) ? "" : (" , " + strInterface)) + @" |
| | | { |
| | | } |
| | | }") |
| | | |
| | | .ToClassStringList(strNameSpace); |
| | | CreateFilesByClassStringList(ls, strPath, "I{0}Repository"); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region æ ¹æ®æ°æ®åºè¡¨ç产IServiceså± |
| | | |
| | | /// <summary> |
| | | /// åè½æè¿°:æ ¹æ®æ°æ®åºè¡¨ç产IServiceså± |
| | | /// ä½ããè
:Blog.Core |
| | | /// </summary> |
| | | /// <param name="sqlSugarClient"></param> |
| | | /// <param name="ConnId">æ°æ®åºé¾æ¥ID</param> |
| | | /// <param name="strPath">å®ä½ç±»åæ¾è·¯å¾</param> |
| | | /// <param name="strNameSpace">å½å空é´</param> |
| | | /// <param name="lstTableNames">ç产æå®ç表</param> |
| | | /// <param name="strInterface">å®ç°æ¥å£</param> |
| | | /// <param name="isMuti"></param> |
| | | private static void Create_IServices_ClassFileByDBTalbe( |
| | | SqlSugarScope sqlSugarClient, |
| | | string ConnId, |
| | | string strPath, |
| | | string strNameSpace, |
| | | string[] lstTableNames, |
| | | string strInterface, |
| | | bool isMuti = false) |
| | | { |
| | | //å¤åºæä»¶å离 |
| | | if (isMuti) |
| | | { |
| | | strPath = strPath + @"\" + ConnId; |
| | | strNameSpace = strNameSpace + "." + ConnId; |
| | | } |
| | | |
| | | var IDbFirst = sqlSugarClient.DbFirst; |
| | | if (lstTableNames != null && lstTableNames.Length > 0) |
| | | { |
| | | IDbFirst = IDbFirst.Where(lstTableNames); |
| | | } |
| | | var ls = IDbFirst.IsCreateDefaultValue().IsCreateAttribute() |
| | | |
| | | .SettingClassTemplate(p => p = |
| | | @"using Blog.Core.IServices.BASE; |
| | | using Blog.Core.Model.Models" + (isMuti ? "." + ConnId + "" : "") + @"; |
| | | |
| | | namespace " + strNameSpace + @" |
| | | { |
| | | /// <summary> |
| | | /// I{ClassName}Services |
| | | /// </summary> |
| | | public interface I{ClassName}Services :IBaseServices<{ClassName}>" + (string.IsNullOrEmpty(strInterface) ? "" : (" , " + strInterface)) + @" |
| | | { |
| | | } |
| | | }") |
| | | |
| | | .ToClassStringList(strNameSpace); |
| | | CreateFilesByClassStringList(ls, strPath, "I{0}Services"); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | |
| | | #region æ ¹æ®æ°æ®åºè¡¨ç产 Repository å± |
| | | |
| | | /// <summary> |
| | | /// åè½æè¿°:æ ¹æ®æ°æ®åºè¡¨ç产 Repository å± |
| | | /// ä½ããè
:Blog.Core |
| | | /// </summary> |
| | | /// <param name="sqlSugarClient"></param> |
| | | /// <param name="ConnId">æ°æ®åºé¾æ¥ID</param> |
| | | /// <param name="strPath">å®ä½ç±»åæ¾è·¯å¾</param> |
| | | /// <param name="strNameSpace">å½å空é´</param> |
| | | /// <param name="lstTableNames">ç产æå®ç表</param> |
| | | /// <param name="strInterface">å®ç°æ¥å£</param> |
| | | /// <param name="isMuti"></param> |
| | | private static void Create_Repository_ClassFileByDBTalbe( |
| | | SqlSugarScope sqlSugarClient, |
| | | string ConnId, |
| | | string strPath, |
| | | string strNameSpace, |
| | | string[] lstTableNames, |
| | | string strInterface, |
| | | bool isMuti = false) |
| | | { |
| | | //å¤åºæä»¶å离 |
| | | if (isMuti) |
| | | { |
| | | strPath = strPath + @"\" + ConnId; |
| | | strNameSpace = strNameSpace + "." + ConnId; |
| | | } |
| | | |
| | | var IDbFirst = sqlSugarClient.DbFirst; |
| | | if (lstTableNames != null && lstTableNames.Length > 0) |
| | | { |
| | | IDbFirst = IDbFirst.Where(lstTableNames); |
| | | } |
| | | var ls = IDbFirst.IsCreateDefaultValue().IsCreateAttribute() |
| | | |
| | | .SettingClassTemplate(p => p = |
| | | @"using Blog.Core.IRepository" + (isMuti ? "." + ConnId + "" : "") + @"; |
| | | using Blog.Core.IRepository.UnitOfWork; |
| | | using Blog.Core.Model.Models" + (isMuti ? "." + ConnId + "" : "") + @"; |
| | | using Blog.Core.Repository.Base; |
| | | |
| | | namespace " + strNameSpace + @" |
| | | { |
| | | /// <summary> |
| | | /// {ClassName}Repository |
| | | /// </summary> |
| | | public class {ClassName}Repository : BaseRepository<{ClassName}>, I{ClassName}Repository" + (string.IsNullOrEmpty(strInterface) ? "" : (" , " + strInterface)) + @" |
| | | { |
| | | public {ClassName}Repository(IUnitOfWork unitOfWork) : base(unitOfWork) |
| | | { |
| | | } |
| | | } |
| | | }") |
| | | .ToClassStringList(strNameSpace); |
| | | |
| | | |
| | | CreateFilesByClassStringList(ls, strPath, "{0}Repository"); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region æ ¹æ®æ°æ®åºè¡¨ç产 Services å± |
| | | |
| | | /// <summary> |
| | | /// åè½æè¿°:æ ¹æ®æ°æ®åºè¡¨ç产 Services å± |
| | | /// ä½ããè
:Blog.Core |
| | | /// </summary> |
| | | /// <param name="sqlSugarClient"></param> |
| | | /// <param name="ConnId">æ°æ®åºé¾æ¥ID</param> |
| | | /// <param name="strPath">å®ä½ç±»åæ¾è·¯å¾</param> |
| | | /// <param name="strNameSpace">å½å空é´</param> |
| | | /// <param name="lstTableNames">ç产æå®ç表</param> |
| | | /// <param name="strInterface">å®ç°æ¥å£</param> |
| | | /// <param name="isMuti"></param> |
| | | private static void Create_Services_ClassFileByDBTalbe( |
| | | SqlSugarScope sqlSugarClient, |
| | | string ConnId, |
| | | string strPath, |
| | | string strNameSpace, |
| | | string[] lstTableNames, |
| | | string strInterface, |
| | | bool isMuti = false) |
| | | { |
| | | //å¤åºæä»¶å离 |
| | | if (isMuti) |
| | | { |
| | | strPath = strPath + @"\" + ConnId; |
| | | strNameSpace = strNameSpace + "." + ConnId; |
| | | } |
| | | |
| | | var IDbFirst = sqlSugarClient.DbFirst; |
| | | if (lstTableNames != null && lstTableNames.Length > 0) |
| | | { |
| | | IDbFirst = IDbFirst.Where(lstTableNames); |
| | | } |
| | | var ls = IDbFirst.IsCreateDefaultValue().IsCreateAttribute() |
| | | |
| | | .SettingClassTemplate(p => p = |
| | | @" |
| | | using Blog.Core.IServices" + (isMuti ? "." + ConnId + "" : "") + @"; |
| | | using Blog.Core.Model.Models" + (isMuti ? "." + ConnId + "" : "") + @"; |
| | | using Blog.Core.Services.BASE; |
| | | using Blog.Core.IRepository.Base; |
| | | |
| | | namespace " + strNameSpace + @" |
| | | { |
| | | public class {ClassName}Services : BaseServices<{ClassName}>, I{ClassName}Services" + (string.IsNullOrEmpty(strInterface) ? "" : (" , " + strInterface)) + @" |
| | | { |
| | | private readonly IBaseRepository<{ClassName}> _dal; |
| | | public {ClassName}Services(IBaseRepository<{ClassName}> dal) |
| | | { |
| | | this._dal = dal; |
| | | base.BaseDal = dal; |
| | | } |
| | | } |
| | | }") |
| | | .ToClassStringList(strNameSpace); |
| | | |
| | | CreateFilesByClassStringList(ls, strPath, "{0}Services"); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region æ ¹æ®æ¨¡æ¿å
容æ¹éçææä»¶ |
| | | /// <summary> |
| | | /// æ ¹æ®æ¨¡æ¿å
容æ¹éçææä»¶ |
| | | /// </summary> |
| | | /// <param name="ls">ç±»æä»¶å符串list</param> |
| | | /// <param name="strPath">çæè·¯å¾</param> |
| | | /// <param name="fileNameTp">æä»¶åæ ¼å¼æ¨¡æ¿</param> |
| | | private static void CreateFilesByClassStringList(Dictionary<string, string> ls, string strPath, string fileNameTp) |
| | | { |
| | | |
| | | foreach (var item in ls) |
| | | { |
| | | var fileName = $"{string.Format(fileNameTp, item.Key)}.cs"; |
| | | var fileFullPath = Path.Combine(strPath, fileName); |
| | | if (!Directory.Exists(strPath)) |
| | | { |
| | | Directory.CreateDirectory(strPath); |
| | | } |
| | | File.WriteAllText(fileFullPath, item.Value, Encoding.UTF8); |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Tenants |
| | | { |
| | | /// <summary> |
| | | /// ç§æ·æ¨¡åæ¥å£ |
| | | /// </summary> |
| | | public interface ITenantEntity |
| | | { |
| | | /// <summary> |
| | | /// ç§æ·Id |
| | | /// </summary> |
| | | [SugarColumn(DefaultValue = "0")] |
| | | public long TenantId { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Tenants |
| | | { |
| | | /// <summary> |
| | | /// æ è¯ å¤ç§æ· çä¸å¡è¡¨ <br/> |
| | | /// é»è®¤è®¾ç½®æ¯å¤åº <br/> |
| | | /// å
Œ
±è¡¨æ éåºå ç´æ¥ä½¿ç¨ä¸»åº åèªä¸å¡å¨åèªåºä¸ <br/> |
| | | /// </summary> |
| | | [AttributeUsage(AttributeTargets.Class)] |
| | | public class MultiTenantAttribute : Attribute |
| | | { |
| | | public MultiTenantAttribute() |
| | | { |
| | | } |
| | | |
| | | public MultiTenantAttribute(TenantTypeEnum tenantType) |
| | | { |
| | | TenantType = tenantType; |
| | | } |
| | | |
| | | |
| | | public TenantTypeEnum TenantType { get; set; } = TenantTypeEnum.Db; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç§æ·éç¦»æ¹æ¡ |
| | | /// </summary> |
| | | public enum TenantTypeEnum |
| | | { |
| | | None = 0, |
| | | |
| | | /// <summary> |
| | | /// Idé离 |
| | | /// </summary> |
| | | [Description("Idé离")] |
| | | Id = 1, |
| | | |
| | | /// <summary> |
| | | /// åºé离 |
| | | /// </summary> |
| | | [Description("åºé离")] |
| | | Db = 2, |
| | | |
| | | /// <summary> |
| | | /// 表é离 |
| | | /// </summary> |
| | | [Description("表é离")] |
| | | Tables = 3, |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.DB; |
| | | |
| | | namespace WIDESEAWCS_Core.Tenants |
| | | { |
| | | public static class TenantUtil |
| | | { |
| | | //public static SysTenant DefaultTenantConfig(this SysTenant tenant) |
| | | //{ |
| | | // tenant.DbType ??= DbType.Sqlite; |
| | | |
| | | // //å¦ææ²¡æé
ç½®è¿æ¥ |
| | | // if (tenant.Connection.IsNullOrEmpty()) |
| | | // { |
| | | // //æ¤å¤é»è®¤é
ç½® Sqlite å°å |
| | | // //å®é
ä¸å¡ä¸ ä¹ä¼æè¿ç»´ãç³»ç»ç®¡çåçæ¥ç»´æ¤ |
| | | // switch (tenant.DbType.Value) |
| | | // { |
| | | // case DbType.Sqlite: |
| | | // tenant.Connection = $"DataSource={Path.Combine(Environment.CurrentDirectory, tenant.ConfigId)}.db"; |
| | | // break; |
| | | // } |
| | | // } |
| | | |
| | | // return tenant; |
| | | //} |
| | | |
| | | //public static ConnectionConfig GetConnectionConfig(this SysTenant tenant) |
| | | //{ |
| | | // if (tenant.DbType is null) |
| | | // { |
| | | // throw new ArgumentException("Tenant DbType Must"); |
| | | // } |
| | | |
| | | |
| | | // return new ConnectionConfig() |
| | | // { |
| | | // ConfigId = tenant.ConfigId, |
| | | // DbType = tenant.DbType.Value, |
| | | // ConnectionString = tenant.Connection, |
| | | // IsAutoCloseConnection = true, |
| | | // MoreSettings = new ConnMoreSettings() |
| | | // { |
| | | // IsAutoRemoveDataCache = true |
| | | // }, |
| | | // }; |
| | | //} |
| | | |
| | | public static List<Type> GetTenantEntityTypes(TenantTypeEnum? tenantType = null) |
| | | { |
| | | List<Type> types = RepositorySetting.Entitys.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass).ToList(); |
| | | |
| | | List<Type> returnTypes = types.Where(s => IsTenantEntity(s, tenantType)).ToList(); |
| | | return returnTypes; |
| | | } |
| | | |
| | | public static bool IsTenantEntity(this Type u, TenantTypeEnum? tenantType = null) |
| | | { |
| | | var mta = u.GetCustomAttribute<MultiTenantAttribute>(); |
| | | if (mta is null) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if (tenantType != null) |
| | | { |
| | | if (mta.TenantType != tenantType) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | public static string GetTenantTableName(this Type type, ISqlSugarClient db, string id) |
| | | { |
| | | var entityInfo = db.EntityMaintenance.GetEntityInfo(type); |
| | | return $@"{entityInfo.DbTableName}_{id}"; |
| | | } |
| | | |
| | | //public static string GetTenantTableName(this Type type, ISqlSugarClient db, SysTenant tenant) |
| | | //{ |
| | | // return GetTenantTableName(type, db, tenant.Id.ToString()); |
| | | //} |
| | | |
| | | public static void SetTenantTable(this ISqlSugarClient db, string id) |
| | | { |
| | | var types = GetTenantEntityTypes(TenantTypeEnum.Tables); |
| | | |
| | | foreach (var type in types) |
| | | { |
| | | db.MappingTables.Add(type.Name, type.GetTenantTableName(db, id)); |
| | | } |
| | | } |
| | | |
| | | public static List<SelectModel> GetTenantSelectModels() |
| | | { |
| | | List<SelectModel> selectModels = new List<SelectModel>() |
| | | { |
| | | new SelectModel |
| | | { |
| | | FieldName = MainDb.TenantId |
| | | }, |
| | | //new SelectModel |
| | | //{ |
| | | // FieldName = MainDb.TenantName |
| | | //}, |
| | | new SelectModel |
| | | { |
| | | FieldName = MainDb.ConnectionString, |
| | | }, |
| | | new SelectModel |
| | | { |
| | | FieldName = MainDb.TenantDbType |
| | | } |
| | | }; |
| | | return selectModels; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel.DataAnnotations; |
| | | using System.ComponentModel.DataAnnotations.Schema; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.Helper; |
| | | |
| | | namespace WIDESEAWCS_Core.Utilities |
| | | { |
| | | public static class EntityProperties |
| | | { |
| | | /// <summary> |
| | | /// éªè¯æ°æ®åºå段类åä¸å¼æ¯å¦æ£ç¡®ï¼ |
| | | /// </summary> |
| | | /// <param name="dbType">æ°æ®åºå段类å(å¦varchar,nvarchar,decimal,ä¸è¦å¸¦åé¢é¿åº¦å¦:varchar(50))</param> |
| | | /// <param name="value">å¼</param> |
| | | /// <param name="propertyInfo">è¦éªè¯çç±»ç屿§ï¼è¥ä¸ä¸ºnullï¼åä¼å¤æå符串çé¿åº¦æ¯å¦æ£ç¡®</param> |
| | | /// <returns>(bool, string, object)boolæå¦æ ¡éªæå,stringæ ¡éªå¤±è´¥ä¿¡æ¯,object,å½åæ ¡éªçå¼</returns> |
| | | public static (bool, string, object) ValidationVal(this PropertyInfo propertyInfo, object value) |
| | | { |
| | | string dbType = ""; |
| | | SugarColumn sugarColumn = null; |
| | | if (propertyInfo != null) |
| | | { |
| | | sugarColumn = propertyInfo.GetCustomAttribute<SugarColumn>(); |
| | | dbType = propertyInfo.PropertyType != null ? propertyInfo.GetProperWithDbType() : SqlDbTypeName.NVarChar; |
| | | } |
| | | dbType = dbType.ToLower(); |
| | | string val = value?.ToString(); |
| | | //éªè¯é¿åº¦ |
| | | string reslutMsg = string.Empty; |
| | | if (dbType == SqlDbTypeName.Int) |
| | | { |
| | | if (!value.IsInt()) |
| | | reslutMsg = "åªè½ä¸ºæææ´æ°"; |
| | | } //2021.10.12å¢å 屿§æ ¡éªlongç±»åçæ¯æ |
| | | else if (dbType == SqlDbTypeName.BigInt) |
| | | { |
| | | if (!long.TryParse(val, out _)) |
| | | { |
| | | reslutMsg = "åªè½ä¸ºæææ´æ°"; |
| | | } |
| | | } |
| | | else if (dbType == SqlDbTypeName.DateTime |
| | | || dbType == SqlDbTypeName.Date |
| | | || dbType == SqlDbTypeName.SmallDateTime |
| | | || dbType == SqlDbTypeName.SmallDate |
| | | ) |
| | | { |
| | | if (!value.IsDate()) |
| | | reslutMsg = "å¿
é¡»ä¸ºæ¥ææ ¼å¼"; |
| | | } |
| | | else if (dbType == SqlDbTypeName.Float || dbType == SqlDbTypeName.Decimal || dbType == SqlDbTypeName.Double) |
| | | { |
| | | |
| | | if (!val.IsNumber(null)) |
| | | { |
| | | reslutMsg = "䏿¯æææ°å"; |
| | | } |
| | | } |
| | | else if (dbType == SqlDbTypeName.UniqueIdentifier) |
| | | { |
| | | if (!val.IsGuid()) |
| | | { |
| | | reslutMsg = propertyInfo.Name + "Guid䏿£ç¡®"; |
| | | } |
| | | } |
| | | else if (propertyInfo != null |
| | | && (dbType == SqlDbTypeName.VarChar |
| | | || dbType == SqlDbTypeName.NVarChar |
| | | || dbType == SqlDbTypeName.NChar |
| | | || dbType == SqlDbTypeName.Char |
| | | || dbType == SqlDbTypeName.Text)) |
| | | { |
| | | |
| | | //é»è®¤nvarchar(max) ãtext é¿åº¦ä¸è½è¶
è¿20000 |
| | | if (val.Length > 200000) |
| | | { |
| | | reslutMsg = $"å符é¿åº¦æå¤ã200000ã"; |
| | | } |
| | | else |
| | | { |
| | | |
| | | int length = sugarColumn.Length; |
| | | if (length == 0) { return (true, null, null); } |
| | | //夿ååèä¸ååæ®µ |
| | | else if (length < 8000 && |
| | | ((dbType.Substring(0, 1) != "n" |
| | | && Encoding.UTF8.GetBytes(val.ToCharArray()).Length > length) |
| | | || val.Length > length) |
| | | ) |
| | | { |
| | | reslutMsg = $"æå¤åªè½ã{length}ã个å符ã"; |
| | | } |
| | | } |
| | | } |
| | | if (!string.IsNullOrEmpty(reslutMsg) && propertyInfo != null) |
| | | { |
| | | reslutMsg = sugarColumn.ColumnDescription + reslutMsg; |
| | | } |
| | | return (reslutMsg == "" ? true : false, reslutMsg, value); |
| | | } |
| | | |
| | | public static List<(bool, string, object)> ValidationValueForDbType(this PropertyInfo propertyInfo, params object[] values) |
| | | { |
| | | List<(bool, string, object)> result = new List<(bool, string, object)>(); |
| | | foreach (object value in values) |
| | | { |
| | | result.Add(propertyInfo.ValidationVal(value)); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private static readonly Dictionary<Type, string> ProperWithDbType = new Dictionary<Type, string>() { |
| | | { typeof(string),SqlDbTypeName.NVarChar }, |
| | | { typeof(DateTime),SqlDbTypeName.DateTime}, |
| | | {typeof(long),SqlDbTypeName.BigInt }, |
| | | {typeof(int),SqlDbTypeName.Int}, |
| | | { typeof(decimal),SqlDbTypeName.Decimal }, |
| | | { typeof(float),SqlDbTypeName.Float }, |
| | | { typeof(double),SqlDbTypeName.Double }, |
| | | { typeof(byte),SqlDbTypeName.Int },//ç±»åå¾
å® |
| | | { typeof(Guid),SqlDbTypeName.UniqueIdentifier} |
| | | }; |
| | | |
| | | public static string GetProperWithDbType(this PropertyInfo propertyInfo) |
| | | { |
| | | bool result = ProperWithDbType.TryGetValue(propertyInfo.PropertyType, out string value); |
| | | if (result) |
| | | { |
| | | return value; |
| | | } |
| | | return SqlDbTypeName.NVarChar; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 夿hashç忝å¦ä¸ºå¯¹åºçå®ä½ï¼å¹¶ä¸å¼æ¯å¦ææ |
| | | /// </summary> |
| | | /// <param name="typeinfo"></param> |
| | | /// <param name="dic"></param> |
| | | /// <param name="removeNotContains">ç§»é¤ä¸åå¨å段</param> |
| | | /// <param name="removerKey">ç§»é¤ä¸»é®</param> |
| | | /// <returns></returns> |
| | | //public static string ValidateDicInEntity(this Type typeinfo, Dictionary<string, object> dic, bool removerKey, PropertyInfo[] propertyInfo, string[] ignoreFields = null) |
| | | //{ |
| | | // if (dic == null || dic.Count == 0) { return "åæ°æ æ"; } |
| | | |
| | | // // ä¸åå¨çåæ®µç´æ¥ç§»é¤ |
| | | // dic.Where(x => !propertyInfo.Any(p => p.Name.ToUpper() == x.Key.ToUpper())).Select(s => s.Key).ToList().ForEach(f => |
| | | // { |
| | | // dic.Remove(f); |
| | | // }); |
| | | |
| | | // string keyName = typeinfo.GetKeyName(); |
| | | // //ç§»é¤ä¸»é® |
| | | // if (removerKey) |
| | | // dic.Remove(keyName); |
| | | // //else |
| | | // //{ |
| | | // // if (!dic.ContainsKey(keyName)) |
| | | // // return "è¯·ä¼ å
¥ä¸»é®åæ°"; |
| | | // //} |
| | | |
| | | // foreach (PropertyInfo property in propertyInfo) |
| | | // { |
| | | // SugarColumn sugarColumn = property.GetCustomAttribute<SugarColumn>(); |
| | | // if (sugarColumn == null) |
| | | // return "请é
ç½®SugarColumn屿§"; |
| | | // //忽ç¥ä¸ä¸»é®çåæ®µä¸åéªè¯ |
| | | // if (property.Name.ToUpper() == keyName.ToUpper() || (ignoreFields != null && ignoreFields.Contains(property.Name)) || sugarColumn.IsOnlyIgnoreInsert || sugarColumn.IsOnlyIgnoreUpdate || sugarColumn.IsIgnore) |
| | | // continue; |
| | | |
| | | // //ä¸å¨ç¼è¾ä¸çåï¼æ¯å¦ä¹è¦å¿
å¡« |
| | | // if (!dic.ContainsKey(property.Name.ToUpper())) |
| | | // { |
| | | // if (!sugarColumn.IsNullable) |
| | | // { |
| | | // if (sugarColumn.DefaultValue == null) |
| | | // return sugarColumn.ColumnDescription + "为å¿
é¡»æäº¤é¡¹"; |
| | | // continue; |
| | | // } |
| | | // continue; |
| | | // } |
| | | // if(dic[property.Name.ToUpper()] != null) |
| | | // { |
| | | // string str = dic[property.Name.ToUpper()].ToString(); |
| | | // //å°ææç©ºå¼è®¾ç½®ä¸ºnull |
| | | // if (str == string.Empty) |
| | | // dic[property.Name.ToUpper()] = null; |
| | | // } |
| | | |
| | | // } |
| | | // return string.Empty; |
| | | //} |
| | | |
| | | public static string ValidateDicInEntity(this Type typeinfo, Dictionary<string, object> dic, bool removerKey, PropertyInfo[] propertyInfo, string[] ignoreFields = null) |
| | | { |
| | | if (dic == null || dic.Count == 0) { return "åæ°æ æ"; } |
| | | |
| | | // ä¸åå¨çåæ®µç´æ¥ç§»é¤ |
| | | dic.Where(x => !propertyInfo.Any(p => p.Name.ToUpper() == x.Key.ToUpper())).Select(s => s.Key).ToList().ForEach(f => |
| | | { |
| | | dic.Remove(f); |
| | | }); |
| | | |
| | | string keyName = typeinfo.GetKeyName(); |
| | | //ç§»é¤ä¸»é® |
| | | if (removerKey) |
| | | dic.Remove(keyName); |
| | | //else |
| | | //{ |
| | | // if (!dic.ContainsKey(keyName)) |
| | | // return "è¯·ä¼ å
¥ä¸»é®åæ°"; |
| | | //} |
| | | |
| | | foreach (PropertyInfo property in propertyInfo) |
| | | { |
| | | SugarColumn sugarColumn = property.GetCustomAttribute<SugarColumn>(); |
| | | if (sugarColumn == null) |
| | | return "请é
ç½®SugarColumn屿§"; |
| | | //忽ç¥ä¸ä¸»é®çåæ®µä¸åéªè¯ |
| | | if (property.Name == keyName.FirstLetterToUpper() || (ignoreFields != null && ignoreFields.Contains(property.Name)) || sugarColumn.IsOnlyIgnoreInsert || sugarColumn.IsOnlyIgnoreUpdate || sugarColumn.IsIgnore) |
| | | continue; |
| | | |
| | | //ä¸å¨ç¼è¾ä¸çåï¼æ¯å¦ä¹è¦å¿
å¡« |
| | | if (!dic.ContainsKey(property.Name.FirstLetterToLower())) |
| | | { |
| | | if (!sugarColumn.IsNullable) |
| | | { |
| | | if (sugarColumn.DefaultValue == null) |
| | | return sugarColumn.ColumnDescription + "为å¿
é¡»æäº¤é¡¹"; |
| | | continue; |
| | | } |
| | | continue; |
| | | } |
| | | if (dic[property.Name.FirstLetterToLower()] != null) |
| | | { |
| | | string str = dic[property.Name.FirstLetterToLower()].ToString(); |
| | | //å°ææç©ºå¼è®¾ç½®ä¸ºnull |
| | | if (str == string.Empty) |
| | | dic[property.Name.FirstLetterToLower()] = null; |
| | | } |
| | | |
| | | } |
| | | return string.Empty; |
| | | } |
| | | |
| | | public static string ValidateDicInEntity(this Type typeinfo, List<Dictionary<string, object>> dicList, bool removerKey, string[] ignoreFields = null) |
| | | { |
| | | PropertyInfo[] propertyInfo = typeinfo.GetProperties(); |
| | | string reslutMsg = string.Empty; |
| | | foreach (Dictionary<string, object> dic in dicList) |
| | | { |
| | | reslutMsg = typeinfo.ValidateDicInEntity(dic, removerKey, propertyInfo, ignoreFields); |
| | | if (!string.IsNullOrEmpty(reslutMsg)) |
| | | return reslutMsg; |
| | | } |
| | | return reslutMsg; |
| | | } |
| | | |
| | | public static string GetKeyName(this Type typeinfo) |
| | | { |
| | | return typeinfo.GetProperties().GetKeyName(); |
| | | } |
| | | |
| | | public static string GetKeyName(this PropertyInfo[] properties) |
| | | { |
| | | foreach (PropertyInfo property in properties) |
| | | { |
| | | SugarColumn sugarColumn = property.GetCustomAttribute<SugarColumn>(); |
| | | if (sugarColumn.IsPrimaryKey) |
| | | return property.Name; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static PropertyInfo GetKeyProperty(this Type typeinfo) |
| | | { |
| | | PropertyInfo[] properties = typeinfo.GetProperties(); |
| | | foreach (PropertyInfo property in properties) |
| | | { |
| | | SugarColumn sugarColumn = property.GetCustomAttribute<SugarColumn>(); |
| | | if (sugarColumn?.IsPrimaryKey ?? false) |
| | | { |
| | | return property; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static Type GetDetailType(this Type typeinfo) |
| | | { |
| | | PropertyInfo[] properties = typeinfo.GetProperties(); |
| | | foreach (PropertyInfo property in properties) |
| | | { |
| | | Navigate? navigate = property.GetCustomAttribute<Navigate>(); |
| | | if (navigate is not null) |
| | | { |
| | | if (navigate.GetNavigateType() == NavigateType.OneToOne) |
| | | return property.PropertyType; |
| | | else |
| | | return property.PropertyType.GenericTypeArguments[0]; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static string GetMainIdByDetail(this Type typeinfo) |
| | | { |
| | | PropertyInfo[] properties = typeinfo.GetProperties(); |
| | | foreach (PropertyInfo property in properties) |
| | | { |
| | | Navigate? navigate = property.GetCustomAttribute<Navigate>(); |
| | | if (navigate is not null) |
| | | { |
| | | return navigate.GetName(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static void SetDetailId<T>(this Type typeinfo, T enetiy, object id, string name) |
| | | { |
| | | PropertyInfo property = typeinfo.GetProperty(name); |
| | | if (property != null) |
| | | { |
| | | property.SetValue(enetiy, id); |
| | | } |
| | | } |
| | | |
| | | public static PropertyInfo? GetNavigatePro(this Type typeinfo) |
| | | { |
| | | PropertyInfo[] properties = typeinfo.GetProperties(); |
| | | foreach (PropertyInfo property in properties) |
| | | { |
| | | Navigate? navigate = property.GetCustomAttribute<Navigate>(); |
| | | if (navigate is not null) |
| | | { |
| | | return property; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static object GetPropertyValue<T>(this Type typeinfo, T data, string propertyName) |
| | | { |
| | | if (typeinfo != typeof(T)) |
| | | return null; |
| | | |
| | | PropertyInfo? property = typeinfo.GetProperty(propertyName); |
| | | if (property != null) |
| | | { |
| | | return property.GetValue(data); |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Linq.Expressions; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | |
| | | namespace WIDESEAWCS_Core.Utilities |
| | | { |
| | | public static class LambdaExtensions |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="propertyName">åæ®µå</param> |
| | | /// <param name="propertyValue">表达å¼çå¼</param> |
| | | /// <param name="expressionType">å建表达å¼çç±»å,å¦:p=>p.propertyName != propertyValue |
| | | /// p=>p.propertyName.Contains(propertyValue)</param> |
| | | /// <returns></returns> |
| | | public static Expression<Func<T, bool>> CreateExpression<T>(this string propertyName, object propertyValue, LinqExpressionType expressionType) |
| | | { |
| | | return propertyName.CreateExpression<T>(propertyValue, null, expressionType); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="propertyName">åæ®µå</param> |
| | | /// <param name="propertyValue">表达å¼çå¼</param> |
| | | /// <param name="expressionType">å建表达å¼çç±»å,å¦:p=>p.propertyName != propertyValue |
| | | /// p=>p.propertyName.Contains(propertyValue)</param> |
| | | /// <returns></returns> |
| | | private static Expression<Func<T, bool>> CreateExpression<T>( |
| | | this string propertyName, |
| | | object propertyValue, |
| | | ParameterExpression parameter, |
| | | LinqExpressionType expressionType) |
| | | { |
| | | Type proType = null; |
| | | PropertyInfo propertyInfo = typeof(T).GetProperty(propertyName); |
| | | if (propertyInfo != null) |
| | | proType = propertyInfo.PropertyType; |
| | | else |
| | | { |
| | | propertyInfo = typeof(T).GetProperty(propertyName.FirstLetterToLower()); |
| | | if (propertyInfo != null) |
| | | proType = propertyInfo.PropertyType; |
| | | else |
| | | { |
| | | propertyInfo = typeof(T).GetProperty(propertyName.FirstLetterToUpper()); |
| | | if (propertyInfo != null) |
| | | proType = propertyInfo.PropertyType; |
| | | else |
| | | { |
| | | throw new Exception($"æªæ¾å°è¯¥å±æ§,type:{typeof(T)}"); |
| | | } |
| | | } |
| | | } |
| | | //å建èç¹åéå¦p=>çèç¹p |
| | | // parameter ??= Expression.Parameter(typeof(T), "p");//åå»ºåæ°p |
| | | parameter = parameter ?? Expression.Parameter(typeof(T), "p"); |
| | | |
| | | //å建èç¹ç屿§p=>p.name 屿§name |
| | | MemberExpression memberProperty = Expression.PropertyOrField(parameter, propertyName); |
| | | if (expressionType == LinqExpressionType.In) |
| | | { |
| | | if (!(propertyValue is System.Collections.IList list) || list.Count == 0) throw new Exception("屿§å¼ç±»å䏿£ç¡®"); |
| | | |
| | | bool isStringValue = true; |
| | | List<object> objList = new List<object>(); |
| | | |
| | | if (proType.ToString() != "System.String") |
| | | { |
| | | isStringValue = false; |
| | | foreach (var value in list) |
| | | { |
| | | objList.Add(value.ToString().ChangeType(proType)); |
| | | } |
| | | list = objList; |
| | | } |
| | | |
| | | if (isStringValue) |
| | | { |
| | | //string ç±»åçåæ®µï¼å¦æå¼å¸¦æ'åå¼å·,EFä¼é»è®¤åæ''两个åå¼å· |
| | | MethodInfo method = typeof(System.Collections.IList).GetMethod("Contains"); |
| | | //å建éå常é并设置为常éçå¼ |
| | | ConstantExpression constantCollection = Expression.Constant(list); |
| | | //å建ä¸ä¸ªè¡¨ç¤ºè°ç¨å¸¦åæ°çæ¹æ³çï¼new string[]{"1","a"}.Contains("a"); |
| | | MethodCallExpression methodCall = Expression.Call(constantCollection, method, memberProperty); |
| | | return Expression.Lambda<Func<T, bool>>(methodCall, parameter); |
| | | } |
| | | //éstringåæ®µï¼æä¸é¢æ¹å¼å¤çæ¥å¼å¸¸Null TypeMapping in Sql Tree |
| | | BinaryExpression body = null; |
| | | foreach (var value in list) |
| | | { |
| | | ConstantExpression constantExpression = Expression.Constant(value); |
| | | UnaryExpression unaryExpression = Expression.Convert(memberProperty, constantExpression.Type); |
| | | |
| | | body = body == null |
| | | ? Expression.Equal(unaryExpression, constantExpression) |
| | | : Expression.OrElse(body, Expression.Equal(unaryExpression, constantExpression)); |
| | | } |
| | | return Expression.Lambda<Func<T, bool>>(body, parameter); |
| | | } |
| | | |
| | | // object value = propertyValue; |
| | | ConstantExpression constant = proType.ToString() == "System.String" |
| | | ? Expression.Constant(propertyValue) : Expression.Constant(propertyValue.ToString().ChangeType(proType)); |
| | | |
| | | // DateTimeåªéæ©äºæ¥æçæ¶åèªå¨å¨ç»ææ¥æå ä¸å¤©ï¼ä¿®å¤DateTimeç±»åä½¿ç¨æ¥æåºé´æ¥è¯¢æ æ³æ¥è¯¢å°ç»ææ¥æçé®é¢ |
| | | if ((proType == typeof(DateTime) || proType == typeof(DateTime?)) && expressionType == LinqExpressionType.LessThanOrEqual && propertyValue.ToString().Length == 10) |
| | | { |
| | | constant = Expression.Constant(Convert.ToDateTime(propertyValue.ToString()).AddDays(1)); |
| | | } |
| | | |
| | | UnaryExpression member = Expression.Convert(memberProperty, constant.Type); |
| | | Expression<Func<T, bool>> expression; |
| | | switch (expressionType) |
| | | { |
| | | //p=>p.propertyName == propertyValue |
| | | case LinqExpressionType.Equal: |
| | | expression = Expression.Lambda<Func<T, bool>>(Expression.Equal(member, constant), parameter); |
| | | break; |
| | | //p=>p.propertyName != propertyValue |
| | | case LinqExpressionType.NotEqual: |
| | | expression = Expression.Lambda<Func<T, bool>>(Expression.NotEqual(member, constant), parameter); |
| | | break; |
| | | // p => p.propertyName > propertyValue |
| | | case LinqExpressionType.GreaterThan: |
| | | expression = Expression.Lambda<Func<T, bool>>(Expression.GreaterThan(member, constant), parameter); |
| | | break; |
| | | // p => p.propertyName < propertyValue |
| | | case LinqExpressionType.LessThan: |
| | | expression = Expression.Lambda<Func<T, bool>>(Expression.LessThan(member, constant), parameter); |
| | | break; |
| | | // p => p.propertyName >= propertyValue |
| | | case LinqExpressionType.ThanOrEqual: |
| | | expression = Expression.Lambda<Func<T, bool>>(Expression.GreaterThanOrEqual(member, constant), parameter); |
| | | break; |
| | | // p => p.propertyName <= propertyValue |
| | | case LinqExpressionType.LessThanOrEqual: |
| | | expression = Expression.Lambda<Func<T, bool>>(Expression.LessThanOrEqual(member, constant), parameter); |
| | | break; |
| | | // p => p.propertyName.Contains(propertyValue) |
| | | // p => !p.propertyName.Contains(propertyValue) |
| | | case LinqExpressionType.Contains: |
| | | case LinqExpressionType.NotContains: |
| | | MethodInfo method = typeof(string).GetMethod("Contains", new[] { typeof(string) }); |
| | | constant = Expression.Constant(propertyValue, typeof(string)); |
| | | if (expressionType == LinqExpressionType.Contains) |
| | | { |
| | | expression = Expression.Lambda<Func<T, bool>>(Expression.Call(member, method, constant), parameter); |
| | | } |
| | | else |
| | | { |
| | | expression = Expression.Lambda<Func<T, bool>>(Expression.Not(Expression.Call(member, method, constant)), parameter); |
| | | } |
| | | break; |
| | | default: |
| | | // p => p.false |
| | | expression = False<T>(); |
| | | break; |
| | | } |
| | | return expression; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å建lambda表达å¼ï¼p=>false |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <returns></returns> |
| | | public static Expression<Func<T, bool>> False<T>() |
| | | { |
| | | |
| | | return p => false; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Attributes; |
| | | |
| | | namespace WIDESEAWCS_Core.Utilities |
| | | { |
| | | public class ModelValidate |
| | | { |
| | | /// <summary> |
| | | /// éªè¯å®ä½åæ° |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="data"></param> |
| | | /// <returns></returns> |
| | | public static (bool, string, object?) ValidateModelData<T>(T data) where T : class, new() |
| | | { |
| | | Type modelType = typeof(T); |
| | | if (data == null) return (false, "ä¼ å
¥åæ°ä¸å¯ä¸ºnull", data); |
| | | ModelValidateAttribute? modelAttribute = modelType.GetCustomAttribute<ModelValidateAttribute>(); |
| | | if (modelAttribute == null) return (false, $"{modelType.Name}æªå®ä¹ãModelValidateAttributeãç¹æ§", data); |
| | | PropertyInfo[] propertyInfos = modelType.GetProperties(); |
| | | return SimpleValidate(propertyInfos, data); |
| | | } |
| | | |
| | | public static (bool, string, object?) ValidateModelData<T>(List<T> datas) where T : class, new() |
| | | { |
| | | Type modelType = typeof(T); |
| | | if (datas == null) return (false, "ä¼ å
¥åæ°ä¸å¯ä¸ºnull", datas); |
| | | if (datas.Count == 0) return (false, "éå个æ°ä¸å¯çäº0", datas); |
| | | foreach (T data in datas) |
| | | { |
| | | if (data == null) return (false, "ä¼ å
¥åæ°ä¸å¯ä¸ºnull", data); |
| | | ModelValidateAttribute? modelAttribute = modelType.GetCustomAttribute<ModelValidateAttribute>(); |
| | | if (modelAttribute == null) return (false, $"{modelType.Name}æªå®ä¹ãModelValidateAttributeãç¹æ§", data); |
| | | PropertyInfo[] propertyInfos = modelType.GetProperties(); |
| | | (bool, string, object?) result = SimpleValidate(propertyInfos, data); |
| | | if (!result.Item1) return result; |
| | | } |
| | | |
| | | return (true, $"æå", datas); |
| | | } |
| | | |
| | | //private static (bool, string, object?) CustomMethodValidate<T>(ModelValidateAttribute modelAttribute, T data) where T : class, new() |
| | | //{ |
| | | // try |
| | | // { |
| | | // if (modelAttribute.CustomValidateMethodTypeName == null) return (false, $"èªå®ä¹éªè¯æ¹æ³éè¦æä¾æ¹æ³æå¨ç±»çç±»å对象", data); |
| | | // if (modelAttribute.CustomValidateMethodName == null) return (false, $"èªå®ä¹éªè¯æ¹æ³éè¦æä¾æ¹æ³å", data); |
| | | |
| | | // string path = Path.Combine(AppContext.BaseDirectory, $"{modelAttribute.CustomValidateAssemblyName}.dll"); |
| | | // Assembly assembly = Assembly.LoadFrom(path); |
| | | |
| | | // Type t = assembly.GetType(modelAttribute.CustomValidateAssemblyName + "." + modelAttribute.CustomValidateMethodTypeName); |
| | | // object bbb = App.GetService(t); |
| | | // MethodInfo? methodInfo = t.GetMethod(modelAttribute.CustomValidateMethodName); |
| | | // var result = methodInfo.Invoke(bbb, new object[] { data }); |
| | | // //MethodInfo? methodInfo = modelAttribute.CustomValidateMethodType.GetMethod(modelAttribute.CustomValidateMethodName); |
| | | // //if (methodInfo == null) return (false, $"æªå¨è¯¥ç±»å对象ã{modelAttribute.CustomValidateMethodType.Name}ã䏿¾å°è¯¥æ¹æ³ã{modelAttribute.CustomValidateMethodName}ã", data); |
| | | // //methodInfo.GetGenericArguments() |
| | | // return (true, "æå", data); |
| | | // } |
| | | // catch(Exception ex) |
| | | // { |
| | | // throw new Exception(); |
| | | // } |
| | | |
| | | //} |
| | | |
| | | private static (bool, string, object?) SimpleValidate<T>(PropertyInfo[] propertyInfos, T data) where T : class, new() |
| | | { |
| | | try |
| | | { |
| | | foreach (PropertyInfo propertyInfo in propertyInfos) |
| | | { |
| | | PropertyValidateAttribute? propertyAttribute = propertyInfo.GetCustomAttribute<PropertyValidateAttribute>(); |
| | | if (propertyAttribute == null) continue; |
| | | |
| | | object? value = propertyInfo.GetValue(data, null); |
| | | if (propertyAttribute.NotNullAndEmpty) |
| | | { |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}ä¸å¯ä¸ºnull", data); |
| | | if (string.IsNullOrEmpty(value.ToString())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}ä¸å¯ä¸ºç©ºå符串", data); |
| | | } |
| | | |
| | | if (propertyAttribute.MinValue > int.MinValue) |
| | | { |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}ä¸å¯ä¸ºnull", data); |
| | | if (propertyAttribute.IsContainMinValue) |
| | | { |
| | | if (Convert.ToInt32(value.ToString()) < propertyAttribute.MinValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}çå¼ã{value}ãä¸å¯å°äºã{propertyAttribute.MinValue}ã", data); |
| | | } |
| | | else |
| | | { |
| | | if (Convert.ToInt32(value.ToString()) <= propertyAttribute.MinValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}çå¼ã{value}ãè¦å¤§äºã{propertyAttribute.MinValue}ã", data); |
| | | } |
| | | } |
| | | |
| | | if (propertyAttribute.MaxValue < int.MaxValue) |
| | | { |
| | | if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}ä¸å¯ä¸ºnull", data); |
| | | if (propertyAttribute.IsContainMaxValue) |
| | | { |
| | | if (Convert.ToInt32(value.ToString()) >= propertyAttribute.MaxValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}çå¼ã{value}ãä¸å¯å¤§äºã{propertyAttribute.MaxValue}ã", data); |
| | | } |
| | | else |
| | | { |
| | | if (Convert.ToInt32(value.ToString()) > propertyAttribute.MaxValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}çå¼ã{value}ãè¦å°äºã{propertyAttribute.MaxValue}ã", data); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return (false, $"æ°æ®éªè¯å¼å¸¸,å¼å¸¸ä¿¡æ¯:{ex.Message}", data); |
| | | } |
| | | return (true, "éªè¯æå", data); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using SkiaSharp; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Drawing; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_Core.Utilities |
| | | { |
| | | public static class VierificationCode |
| | | { |
| | | private static readonly string[] _chars = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "P", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; |
| | | |
| | | private static readonly SKColor[] colors = { SKColors.Black, SKColors.Green, SKColors.Brown }; |
| | | |
| | | private static readonly string[] fonts = { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "å®ä½" }; |
| | | public static string RandomText() |
| | | { |
| | | string code = "";//产ççéæºæ° |
| | | int temp = -1; |
| | | Random rand = new Random(); |
| | | for (int i = 1; i < 5; i++) |
| | | { |
| | | if (temp != -1) |
| | | { |
| | | rand = new Random(i * temp * unchecked((int)DateTime.Now.Ticks)); |
| | | } |
| | | int t = rand.Next(61); |
| | | if (temp != -1 && temp == t) |
| | | { |
| | | return RandomText(); |
| | | } |
| | | temp = t; |
| | | code += _chars[t]; |
| | | } |
| | | return code; |
| | | } |
| | | public static string CreateBase64Imgage(string code) |
| | | { |
| | | var random = new Random(); |
| | | var info = new SKImageInfo((int)code.Length * 18, 32); |
| | | using var bitmap = new SKBitmap(info); |
| | | using var canvas = new SKCanvas(bitmap); |
| | | |
| | | canvas.Clear(SKColors.White); |
| | | |
| | | using var pen = new SKPaint(); |
| | | pen.FakeBoldText = true; |
| | | pen.Style = SKPaintStyle.Fill; |
| | | pen.TextSize = 20;// 0.6f * info.Width * pen.TextSize / pen.MeasureText(code); |
| | | |
| | | //ç»å¶éæºå符 |
| | | for (int i = 0; i < code.Length; i++) |
| | | { |
| | | pen.Color = random.GetRandom(colors);//éæºé¢è²ç´¢å¼å¼ |
| | | |
| | | pen.Typeface = SKTypeface.FromFamilyName(random.GetRandom(fonts), 700, 20, SKFontStyleSlant.Italic);//é
ç½®åä½ |
| | | var point = new SKPoint() |
| | | { |
| | | X = i * 16, |
| | | Y = 22// info.Height - ((i + 1) % 2 == 0 ? 2 : 4), |
| | | |
| | | }; |
| | | canvas.DrawText(code.Substring(i, 1), point, pen);//ç»å¶ä¸ä¸ªéªè¯å符 |
| | | |
| | | } |
| | | |
| | | // ç»å¶åªç¹ |
| | | var points = Enumerable.Range(0, 100).Select( |
| | | _ => new SKPoint(random.Next(bitmap.Width), random.Next(bitmap.Height)) |
| | | ).ToArray(); |
| | | canvas.DrawPoints( |
| | | SKPointMode.Points, |
| | | points, |
| | | pen); |
| | | |
| | | //ç»å¶è´å¡å°çº¿æ¡ |
| | | for (int i = 0; i < 2; i++) |
| | | { |
| | | var p1 = new SKPoint(0, 0); |
| | | var p2 = new SKPoint(0, 0); |
| | | var p3 = new SKPoint(0, 0); |
| | | var p4 = new SKPoint(0, 0); |
| | | |
| | | var touchPoints = new SKPoint[] { p1, p2, p3, p4 }; |
| | | |
| | | using var bPen = new SKPaint(); |
| | | bPen.Color = random.GetRandom(colors); |
| | | bPen.Style = SKPaintStyle.Stroke; |
| | | |
| | | using var path = new SKPath(); |
| | | path.MoveTo(touchPoints[0]); |
| | | path.CubicTo(touchPoints[1], touchPoints[2], touchPoints[3]); |
| | | canvas.DrawPath(path, bPen); |
| | | } |
| | | return bitmap.ToBase64String(SKEncodedImageFormat.Png); |
| | | } |
| | | |
| | | public static T GetRandom<T>(this Random random, T[] tArray) |
| | | { |
| | | if (random == null) random = new Random(); |
| | | return tArray[random.Next(tArray.Length)]; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// SKBitmap转Base64String |
| | | /// </summary> |
| | | /// <param name="bitmap"></param> |
| | | /// <param name="format"></param> |
| | | /// <returns></returns> |
| | | public static string ToBase64String(this SKBitmap bitmap, SKEncodedImageFormat format) |
| | | { |
| | | using var memStream = new MemoryStream(); |
| | | using var wstream = new SKManagedWStream(memStream); |
| | | bitmap.Encode(wstream, format, 32); |
| | | memStream.TryGetBuffer(out ArraySegment<byte> buffer); |
| | | return $"{Convert.ToBase64String(buffer.Array, 0, (int)memStream.Length)}"; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <Project Sdk="Microsoft.NET.Sdk"> |
| | | |
| | | <PropertyGroup> |
| | | <TargetFramework>net6.0</TargetFramework> |
| | | <ImplicitUsings>enable</ImplicitUsings> |
| | | <Nullable>enable</Nullable> |
| | | <Version>1.0.2</Version> |
| | | <Description>æ´æ°æ¥å£è®¿é®ææé®é¢</Description> |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="Autofac" Version="8.0.0" /> |
| | | <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="9.0.0" /> |
| | | <PackageReference Include="Autofac.Extras.DynamicProxy" Version="7.1.0" /> |
| | | <PackageReference Include="AutoMapper" Version="13.0.1" /> |
| | | <PackageReference Include="Magicodes.IE.EPPlus" Version="2.7.5.1" /> |
| | | <PackageReference Include="Magicodes.IE.Excel" Version="2.7.5.1" /> |
| | | <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.29" /> |
| | | <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" /> |
| | | <PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.3.8" /> |
| | | <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> |
| | | <PackageReference Include="OfficeOpenXml.Core.ExcelPackage" Version="1.0.0" /> |
| | | <PackageReference Include="SkiaSharp" Version="2.88.8" /> |
| | | <PackageReference Include="SqlSugarCore" Version="5.1.4.152" /> |
| | | <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> |
| | | <PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.5" /> |
| | | <PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.5.0" /> |
| | | <PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.0" /> |
| | | <PackageReference Include="System.Net.Http" Version="4.3.4" /> |
| | | <PackageReference Include="System.Security.Cryptography.Pkcs" Version="6.0.3" /> |
| | | <PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <Folder Include="ServiceExtensions\" /> |
| | | </ItemGroup> |
| | | |
| | | </Project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <Project Sdk="Microsoft.NET.Sdk"> |
| | | |
| | | <PropertyGroup> |
| | | <TargetFramework>net6.0</TargetFramework> |
| | | <ImplicitUsings>enable</ImplicitUsings> |
| | | <Nullable>enable</Nullable> |
| | | <Version>1.0.4</Version> |
| | | <Description>æ·»å åç¹ç»å½ï¼ |
| | | ä¿®å¤åè¡¨æ°æ®ä¿®æ¹-ä¿®æ¹äººä¿®æ¹æ¶é´é®é¢</Description> |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="Autofac" Version="8.0.0" /> |
| | | <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="9.0.0" /> |
| | | <PackageReference Include="Autofac.Extras.DynamicProxy" Version="7.1.0" /> |
| | | <PackageReference Include="AutoMapper" Version="13.0.1" /> |
| | | <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.9.5" /> |
| | | <PackageReference Include="Magicodes.IE.EPPlus" Version="2.7.5.1" /> |
| | | <PackageReference Include="Magicodes.IE.Excel" Version="2.7.5.1" /> |
| | | <PackageReference Include="Masuit.Tools.Core" Version="2024.5.0" /> |
| | | <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.29" /> |
| | | <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.2" /> |
| | | <PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.3.8" /> |
| | | <PackageReference Include="MoYu.Pure" Version="4.9.5.5" /> |
| | | <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> |
| | | <PackageReference Include="OfficeOpenXml.Core.ExcelPackage" Version="1.0.0" /> |
| | | <PackageReference Include="SkiaSharp" Version="2.88.8" /> |
| | | <PackageReference Include="SqlSugarCore" Version="5.1.4.152" /> |
| | | <PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.2" /> |
| | | <PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.5" /> |
| | | <PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.5.0" /> |
| | | <PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.0" /> |
| | | <PackageReference Include="System.Net.Http" Version="4.3.4" /> |
| | | <PackageReference Include="System.Security.Cryptography.Pkcs" Version="6.0.3" /> |
| | | <PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <Folder Include="ServiceExtensions\" /> |
| | | </ItemGroup> |
| | | |
| | | </Project> |
| | |
| | | { |
| | | return TaskTypeGroup.InboundGroup; |
| | | } |
| | | else if (!int.TryParse(Enum.Parse<AGVTaskStatusEnum>(taskType.ToString()).ToString(), out result)) |
| | | { |
| | | return TaskTypeGroup.AGVGroup; |
| | | } |
| | | else if (!int.TryParse(Enum.Parse<TaskRelocationTypeEnum>(taskType.ToString()).ToString(), out result)) |
| | | { |
| | | return TaskTypeGroup.RelocationGroup; |
| | |
| | | { |
| | | return type.GetEnumIndexList().Where(x => x > currentStatus && x < (int)TaskOutStatusEnum.OutFinish).OrderBy(x => x).FirstOrDefault(); |
| | | } |
| | | else if (type == typeof(AGVTaskStatusEnum)) |
| | | { |
| | | return type.GetEnumIndexList().Where(x => x > currentStatus && x < (int)AGVTaskStatusEnum.AGVFinish).OrderBy(x => x).FirstOrDefault(); |
| | | } |
| | | else |
| | | { |
| | | throw new NotImplementedException(); |
| | |
| | | [Description("åºåºä»»å¡å¼å¸¸")] |
| | | OutException = 199, |
| | | } |
| | | |
| | | public enum AGVTaskStatusEnum |
| | | { |
| | | /// <summary> |
| | | /// æ°å»ºAGVä»»å¡ |
| | | /// </summary> |
| | | [Description("æ°å»ºAGVä»»å¡")] |
| | | AGVNew = 400, |
| | | |
| | | /// <summary> |
| | | /// AGVæ§è¡ä¸ |
| | | /// </summary> |
| | | [Description("AGV任塿§è¡ä¸")] |
| | | AGV_Executing = 410, |
| | | |
| | | /// <summary> |
| | | /// AGVä»»å¡å®æ |
| | | /// </summary> |
| | | [Description("AGV任塿¬è¿å®æ")] |
| | | AGVFinish = 490, |
| | | |
| | | /// <summary> |
| | | /// åºåºä»»å¡æèµ· |
| | | /// </summary> |
| | | [Description("åºåºä»»å¡æèµ·")] |
| | | AGVPending = 497, |
| | | |
| | | /// <summary> |
| | | /// åºåºä»»å¡åæ¶ |
| | | /// </summary> |
| | | [Description("åºåºä»»å¡åæ¶")] |
| | | AGVCancel = 498, |
| | | |
| | | /// <summary> |
| | | /// åºåºä»»å¡å¼å¸¸ |
| | | /// </summary> |
| | | [Description("åºåºä»»å¡å¼å¸¸")] |
| | | AGVException = 499, |
| | | } |
| | | } |
| | |
| | | RelocationIn = 301 |
| | | } |
| | | |
| | | public enum AGVTaskTypeEnum |
| | | { |
| | | /// <summary> |
| | | /// AGVæ¬è¿ |
| | | /// </summary> |
| | | [Description("AGVæ¬è¿")] |
| | | AGVCarry =400 |
| | | } |
| | | |
| | | public enum TaskOtherTypeEnum |
| | | { |
| | | |
| | |
| | | public enum TaskTypeGroup |
| | | { |
| | | InboundGroup, |
| | | AGVGroup, |
| | | OutbondGroup, |
| | | RelocationGroup, |
| | | OtherGroup |
| | |
| | | <Folder Include="BasicInfo\" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="WIDESEAWCS_Core" Version="1.0.7" /> |
| | | </ItemGroup> |
| | | |
| | | </Project> |
ÎļþÃû´Ó ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs ÐÞ¸Ä |
| | |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | using WIDESEAWCS_Model.Models.BasicInfo; |
| | | |
| | | namespace WIDESEAWCS_ISystemRepository |
| | | namespace WIDESEAWCS_IBasicInfoRepository |
| | | { |
| | | public interface IAgvStationRepository : IRepository<AGVStation> |
| | | public interface IDt_StationManagerRepository : IRepository<Dt_StationManager> |
| | | { |
| | | |
| | | } |
| | |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="WIDESEAWCS_Core" Version="1.0.7" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\WIDESEAWCS_DTO\WIDESEAWCS_DTO.csproj" /> |
| | | </ItemGroup> |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_ITaskInfoService |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.BasicInfo; |
| | | |
| | | namespace WIDESEAWCS_IBasicInfoService |
| | | { |
| | | public interface IDt_StationManagerService : IService<Dt_StationManager> |
| | | { |
| | | public List<Dt_StationManager> QuerypLatform(string deviceNo, List<string> _Task); |
| | | |
| | | public List<Dt_StationManager> QuerypLatformarer(string deviceNo); |
| | | |
| | | public List<Dt_StationManager> QuerypLatformmaterial(int Station_Area); |
| | | |
| | | public List<Dt_StationManager> QuerypStation_Area(int Station_Area); |
| | | |
| | | public List<Dt_StationManager> QuerypStation_Area2(string Station_remark); |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®PLC设å¤è·åå½å设å¤ä¸çææå¯ç¨çç«å° |
| | | /// </summary> |
| | | /// <param name="DeviceCode"></param> |
| | | /// <returns></returns> |
| | | List<Dt_StationManager> GetAllStationByDeviceCode(string DeviceCode); |
| | | } |
| | | } |
| | |
| | | <Project Sdk="Microsoft.NET.Sdk"> |
| | | <Project Sdk="Microsoft.NET.Sdk"> |
| | | |
| | | <PropertyGroup> |
| | | <TargetFramework>net6.0</TargetFramework> |
| | |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="WIDESEAWCS_Core" Version="1.0.7" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\WIDESEAWCS_BasicInfoRepository\WIDESEAWCS_BasicInfoRepository.csproj" /> |
| | | <ProjectReference Include="..\WIDESEAWCS_ISystemServices\WIDESEAWCS_ISystemServices.csproj" /> |
| | | </ItemGroup> |
| | | |
| | | </Project> |
| | |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="WIDESEAWCS_Core" Version="1.0.7" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\WIDESEAWCS_DTO\WIDESEAWCS_DTO.csproj" /> |
| | | </ItemGroup> |
| | | |
| | |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="WIDESEAWCS_Core" Version="1.0.7" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\WIDESEAWCS_SystemRepository\WIDESEAWCS_SystemRepository.csproj" /> |
| | | </ItemGroup> |
| | | |
| | |
| | | { |
| | | public interface ITaskRepository : IRepository<Dt_Task> |
| | | { |
| | | |
| | | Task<int> GetTaskNo(); |
| | | } |
| | | } |
| | |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="WIDESEAWCS_Core" Version="1.0.7" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\WIDESEAWCS_DTO\WIDESEAWCS_DTO.csproj" /> |
| | | </ItemGroup> |
| | | |
| | |
| | | /// </summary> |
| | | /// <param name="taskDTOs">WMSä»»å¡å¯¹è±¡éå</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | WebResponseContent ReceiveWMSTask(Dt_Task taskDTOs); |
| | | WebResponseContent ReceiveWMSTask([NotNull] List<Dt_Task> taskDTOs); |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç¼å·ãå½åå°åæ¥è¯¢è¾éçº¿æªæ§è¡çä»»å¡ |
| | |
| | | /// <param name="currentAddress"></param> |
| | | /// <returns></returns> |
| | | List<string> QueryConveyorLineTaskSourceAddress(); |
| | | /// <summary> |
| | | /// æ¥æ¾ä»»å¡æ¯å¦éè¦å°å |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | Dt_Task QueryConveyorLineTaskRoadway(int agvarea); |
| | | |
| | | /// <summary> |
| | | /// æ¥æ¾è¯¥å°åæ¯å¦æèµ·ç¹è´§ç»ç¹ä»»å¡ |
| | |
| | | </PropertyGroup> |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="WIDESEAWCS_Core" Version="1.0.7" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\WIDESEAWCS_TaskInfoRepository\WIDESEAWCS_TaskInfoRepository.csproj" /> |
| | | </ItemGroup> |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.DB.Models; |
| | | using WIDESEAWCS_Core.Tenants; |
| | | |
| | | namespace WIDESEAWCS_Model.Models.BasicInfo |
| | | { |
| | | public class Dt_StationManager: BaseEntity |
| | | { |
| | | /// <summary> |
| | | /// ä¸»é® |
| | | /// </summary> |
| | | [ImporterHeader(Name = "主é®")] |
| | | [ExporterHeader(DisplayName = "主é®")] |
| | | [SugarColumn(IsPrimaryKey = true, IsIdentity = true,IsNullable =false, ColumnDescription = "主é®")] |
| | | public int stationID { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ç«å°ç¼å· |
| | | /// </summary> |
| | | [SugarColumn( ColumnDescription = "ç«å°ç¼å·")] |
| | | public string stationCode { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ç«å°åç§°remark |
| | | /// </summary> |
| | | [SugarColumn(Length = 50, ColumnDescription = "ç«å°åç§°")] |
| | | public string stationName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ç±»å |
| | | /// </summary> |
| | | [SugarColumn( ColumnDescription = "ç«å°ç±»å")] |
| | | public int stationMaterial { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ¯å¦å¯ç¨ |
| | | /// </summary> |
| | | [SugarColumn( ColumnDescription = "æ¯å¦å¯ç¨")] |
| | | public int stationEnable { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åºå |
| | | /// </summary> |
| | | [SugarColumn( ColumnDescription = "åºå")] |
| | | public int stationArea { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 夿³¨ |
| | | /// </summary> |
| | | [SugarColumn( Length = 50, ColumnDescription = "夿³¨")] |
| | | public string stationRemark { get; set; } |
| | | |
| | | |
| | | /// <summary> |
| | | /// ç«å°æå±è®¾å¤ |
| | | /// </summary> |
| | | [SugarColumn(Length = 50, IsNullable = false, ColumnDescription = "ç«å°æå±è®¾å¤")] |
| | | public string DeviceCode { get; set; } |
| | | } |
| | | } |
| | |
| | | [ImporterHeader(Name = "æçç¼å·")] |
| | | [ExporterHeader(DisplayName = "æçç¼å·")] |
| | | [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "æçç¼å·")] |
| | | public string PalletCode { get; set; } |
| | | public string AGVName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åºåå· |
| | |
| | | public int Grade { get; set; } |
| | | |
| | | /// <summary> |
| | | /// WMSä»»å¡ä¸»é® |
| | | /// </summary> |
| | | [ImporterHeader(Name = "WMSä»»å¡ä¸»é®")] |
| | | [ExporterHeader(DisplayName = "WMSä»»å¡ä¸»é®")] |
| | | [SugarColumn(IsNullable = false, ColumnDescription = "WMSä»»å¡ä¸»é®")] |
| | | public int WMSId { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡ä¸åæ¶é´ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "ä»»å¡ä¸åæ¶é´")] |
| | |
| | | [SugarColumn(IsNullable = true, Length = 255, ColumnDescription = "夿³¨")] |
| | | public string Remark { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æçæ°é |
| | | /// </summary> |
| | | [ImporterHeader(Name = "æçæ°é")] |
| | | [ExporterHeader(DisplayName = "æçæ°é")] |
| | | [SugarColumn(IsNullable = true, ColumnDescription = "æçæ°é")] |
| | | public int PalletCodequantity { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åææå»å |
| | | /// </summary> |
| | | [ImporterHeader(Name = "åææå»å")] |
| | | [ExporterHeader(DisplayName = "åææå»å")] |
| | | [SugarColumn(IsNullable = false, ColumnDescription = "åææå»å")] |
| | | public int PLCTo { get; set; } |
| | | /// <summary> |
| | | /// ç©æç±»å |
| | | /// </summary> |
| | | [ExporterHeader(DisplayName = "ç©æç±»å")] |
| | | [SugarColumn(IsNullable = false, ColumnDescription = "ç©æç±»å")] |
| | | public int MaterialType { get; set; } |
| | | } |
| | | } |
| | |
| | | [ImporterHeader(Name = "æçç¼å·")] |
| | | [ExporterHeader(DisplayName = "æçç¼å·")] |
| | | [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "æçç¼å·")] |
| | | public string PalletCode { get; set; } |
| | | public string AGVName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å··éå· |
| | |
| | | public int Grade { get; set; } |
| | | |
| | | /// <summary> |
| | | /// WMSä»»å¡ä¸»é® |
| | | /// </summary> |
| | | [ImporterHeader(Name = "WMSä»»å¡ä¸»é®")] |
| | | [ExporterHeader(DisplayName = "WMSä»»å¡ä¸»é®")] |
| | | [SugarColumn(IsNullable = false, ColumnDescription = "WMSä»»å¡ä¸»é®")] |
| | | public int WMSId { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡ä¸åæ¶é´ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "ä»»å¡ä¸åæ¶é´")] |
| | |
| | | [ExporterHeader(DisplayName = "夿³¨")] |
| | | [SugarColumn(IsNullable = true, Length = 255, ColumnDescription = "夿³¨")] |
| | | public string Remark { get; set; } |
| | | /// <summary> |
| | | /// æçæ°é |
| | | /// </summary> |
| | | [ImporterHeader(Name = "æçæ°é")] |
| | | [ExporterHeader(DisplayName = "æçæ°é")] |
| | | [SugarColumn(IsNullable = false, ColumnDescription = "æçæ°é")] |
| | | public int PalletCodequantity { get; set; } |
| | | /// <summary> |
| | | /// åææå»å |
| | | /// </summary> |
| | | [ImporterHeader(Name = "åææå»å")] |
| | | [ExporterHeader(DisplayName = "åææå»å")] |
| | | [SugarColumn(IsNullable = false, ColumnDescription = "åææå»å")] |
| | | public int PLCTo { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ç©æç±»åPalletCodequantity |
| | | /// </summary> |
| | | [ExporterHeader(DisplayName = "ç©æç±»å")] |
| | | [SugarColumn(IsNullable = false, ColumnDescription = "ç©æç±»å")] |
| | | public int MaterialType { get; set; } |
| | | } |
| | | } |
| | |
| | | |
| | | <ItemGroup> |
| | | <PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" /> |
| | | <PackageReference Include="WIDESEAWCS_Core" Version="1.0.7" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\WIDESEAWCS_Common\WIDESEAWCS_Common.csproj" /> |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <Folder Include="Models\BasicInfo\" /> |
| | | <ProjectReference Include="..\WIDESEAWCS_Core\WIDESEAWCS_Core.csproj" /> |
| | | </ItemGroup> |
| | | |
| | | </Project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ä¸è¬è¾é线å®ç°ç±» |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using HslCommunication; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Communicator; |
| | | using WIDESEAWCS_QuartzJob.ConveyorLine.Enum; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane.Enum; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob |
| | | { |
| | | [Description("è¾é线")] |
| | | public class CommonConveyorLine : IConveyorLine |
| | | { |
| | | #region Private Member |
| | | |
| | | /// <summary> |
| | | /// å åæºé讯对象 |
| | | /// </summary> |
| | | private readonly BaseCommunicator _communicator; |
| | | |
| | | /// <summary> |
| | | /// å åæºåè®®ä¿¡æ¯ |
| | | /// </summary> |
| | | private readonly List<DeviceProDTO> _deviceProDTOs; |
| | | |
| | | /// <summary> |
| | | /// å åæºåè®®æç»ä¿¡æ¯ |
| | | /// </summary> |
| | | private readonly List<DeviceProtocolDetailDTO> _deviceProtocolDetailDTOs; |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¼å· |
| | | /// </summary> |
| | | public readonly string _deviceCode; |
| | | |
| | | /// <summary> |
| | | /// 设å¤åç§° |
| | | /// </summary> |
| | | public readonly string _deviceName; |
| | | |
| | | private bool _heartStatr = true; |
| | | |
| | | private bool _isConnected = true; |
| | | |
| | | #endregion |
| | | |
| | | #region Public Member |
| | | |
| | | /// <summary> |
| | | /// è¾é线é讯对象 |
| | | /// </summary> |
| | | public BaseCommunicator Communicator => _communicator; |
| | | |
| | | /// <summary> |
| | | /// è¾é线åè®®ä¿¡æ¯ |
| | | /// </summary> |
| | | public List<DeviceProDTO> DeviceProDTOs => _deviceProDTOs; |
| | | |
| | | /// <summary> |
| | | /// è¾é线åè®®æç»ä¿¡æ¯ |
| | | /// </summary> |
| | | public List<DeviceProtocolDetailDTO> DeviceProtocolDetailDTOs => _deviceProtocolDetailDTOs; |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¼å· |
| | | /// </summary> |
| | | public string DeviceCode => _deviceCode; |
| | | |
| | | /// <summary> |
| | | /// 设å¤åç§° |
| | | /// </summary> |
| | | public string DeviceName => _deviceName; |
| | | |
| | | /// <summary> |
| | | /// æ¯å¦ææ
é |
| | | /// </summary> |
| | | public bool IsFault => false; |
| | | |
| | | /// <summary> |
| | | /// é讯æ¯å¦å·²è¿æ¥ |
| | | /// </summary> |
| | | public bool IsConnected => Communicator.IsConnected && _isConnected; |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¶æ |
| | | /// </summary> |
| | | public DeviceStatus Status => DeviceStatus.Offline; |
| | | |
| | | #endregion |
| | | |
| | | #region Constructor Function |
| | | |
| | | /// <summary> |
| | | /// æé 彿° |
| | | /// </summary> |
| | | /// <param name="communicator">å åæºé讯对象</param> |
| | | /// <param name="deviceProDTOs">å åæºå议信æ¯</param> |
| | | /// <param name="deviceProtocolDetailDTOs">å åæºåè®®æç»ä¿¡æ¯</param> |
| | | /// <param name="deviceCode">设å¤ç¼å·</param> |
| | | /// <param name="deviceName">设å¤åç§°</param> |
| | | public CommonConveyorLine(BaseCommunicator communicator, List<DeviceProDTO> deviceProDTOs, List<DeviceProtocolDetailDTO> deviceProtocolDetailDTOs, string deviceCode, string deviceName) |
| | | { |
| | | _communicator = communicator; |
| | | _deviceProDTOs = deviceProDTOs; |
| | | _deviceProtocolDetailDTOs = deviceProtocolDetailDTOs; |
| | | _deviceCode = deviceCode; |
| | | _deviceName = deviceName; |
| | | CheckConnect(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Private Method |
| | | |
| | | private void CheckConnect() |
| | | { |
| | | Task.Run(() => |
| | | { |
| | | while (_heartStatr) |
| | | { |
| | | try |
| | | { |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(); |
| | | if (devicePro == null) |
| | | _isConnected = false; |
| | | else |
| | | Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | _isConnected = true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _isConnected = false; |
| | | } |
| | | Thread.Sleep(500); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Public Method |
| | | |
| | | /// <summary> |
| | | /// 读åPLCåè®®å°åçæ°æ® |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">å议信æ¯çæä¸¾å¯¹è±¡ä¿¡æ¯ã</typeparam> |
| | | /// <typeparam name="TRsult">è¯»åæ°æ®çç±»å对象信æ¯ã</typeparam> |
| | | /// <param name="value">æä¸¾å¼</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·</param> |
| | | /// <returns>读åå°çæ°æ®</returns> |
| | | public TRsult GetValue<TEnum, TRsult>(TEnum value, string deviceChildCode) where TEnum : Enum |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»ã {DeviceName} ã"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString() && x.DeviceChildCode == deviceChildCode); |
| | | return devicePro == null ? throw new Exception() : (TRsult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¸è®¾å¤çå¿è·³ |
| | | /// </summary> |
| | | public void Heartbeat() |
| | | { |
| | | throw new NotImplementedException(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="command"></param> |
| | | /// <param name="deviceChildCode"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public bool SendCommand<T>(T command, string deviceChildCode) where T : IDataTransfer, new() |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»ã{DeviceName}ã"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | if (devicePro == null) |
| | | { |
| | | return false; |
| | | } |
| | | if (Communicator.WriteCustomer(devicePro.DeviceProAddress, command)) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读åPLCæ°æ®ï¼è¿åèªå®ä¹å¯¹è±¡ |
| | | /// </summary> |
| | | /// <typeparam name="T">æ³å</typeparam> |
| | | /// <param name="deviceChildCode">å设å¤ç¼å·</param> |
| | | /// <returns>è¿åèªå®ä¹å¯¹è±¡ææåºå¼å¸¸</returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public T ReadCustomer<T>(string deviceChildCode) where T : IDataTransfer, new() |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»ã{DeviceName}ã"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == "ReadDeviceCommand" && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | |
| | | if (devicePro == null) |
| | | { |
| | | throw new Exception("æªæ¾å°å议信æ¯:" + deviceChildCode); |
| | | } |
| | | else |
| | | { |
| | | return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读åPLCæ°æ®ï¼è¿åèªå®ä¹å¯¹è±¡ |
| | | /// </summary> |
| | | /// <typeparam name="T">æ³å</typeparam> |
| | | /// <param name="deviceChildCode">å设å¤ç¼å·</param> |
| | | /// <param name="deviceProParamType">åæ°ç±»å</param> |
| | | /// <returns>è¿åèªå®ä¹å¯¹è±¡ææåºå¼å¸¸</returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public T ReadCustomer<T>(string deviceChildCode, string deviceProParamType) where T : IDataTransfer, new() |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»ã{DeviceName}ã"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == deviceProParamType && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | |
| | | if (devicePro == null) |
| | | { |
| | | throw new Exception("æªæ¾å°å议信æ¯:" + deviceChildCode); |
| | | } |
| | | else |
| | | { |
| | | return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®åæ°åç§°ã设å¤åç¼å·åå
¥å¯¹åºçæ°æ®ã |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">åæ°åç§°æä¸¾ç±»åã</typeparam> |
| | | /// <typeparam name="TValue">è¦åå
¥çæ°æ®ç±»åã</typeparam> |
| | | /// <param name="enum">åæ°åç§°ã</param> |
| | | /// <param name="value">è¦åå
¥çæ°æ®ã</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·å</param> |
| | | /// <returns>è¿ååå
¥æåæå¤±è´¥</returns> |
| | | public bool SetValue<TEnum, TValue>(TEnum @enum, TValue value, string deviceChildCode) |
| | | where TEnum : Enum |
| | | where TValue : notnull |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»ã {DeviceName} ã"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode); |
| | | return devicePro == null ? throw new Exception() : Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ£æµç«å°æ¯å¦æè´§ |
| | | /// </summary> |
| | | /// <param name="deviceChildCode"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public bool IsOccupied(string deviceChildCode) |
| | | { |
| | | if (Communicator.IsConnected) |
| | | { |
| | | List<DeviceProDTO> devicePros = _deviceProDTOs.Where(x => x.DeviceProParamType == ConveyorLineStatus.IsOccupied.ToString()).ToList(); |
| | | if (devicePros.Count == 0) |
| | | { |
| | | //todo åè®®ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ |
| | | throw new Exception(); |
| | | } |
| | | for (int i = 0; i < devicePros.Count; i++) |
| | | { |
| | | object readStatus = Communicator.ReadAsObj(devicePros[i].DeviceProAddress, devicePros[i].DeviceDataType); |
| | | //todo åè®®æç»ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ |
| | | DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamName) ?? throw new Exception(); |
| | | deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamType && x.ProtocalDetailValue.Equals(readStatus.ToString())); |
| | | if (deviceProtocolDetail != null) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | //todo é讯æªè¿æ¥æ¶æåºå¼å¸¸ |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ£æµç«å°æ¯å¦æè´§ |
| | | /// </summary> |
| | | /// <param name="deviceChildCode"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public bool IsOccupiedx(string deviceChildCode) |
| | | { |
| | | if (Communicator.IsConnected) |
| | | { |
| | | var device = _deviceProDTOs.Where(x => x.DeviceChildCode == deviceChildCode && x.DeviceProParamName == "InteractiveSignal").FirstOrDefault(); |
| | | |
| | | object readStatus = Communicator.ReadAsObj(device.DeviceProAddress, device.DeviceDataType); |
| | | |
| | | //todo åè®®æç»ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ |
| | | if (readStatus.ToString() != "2") |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | //todo é讯æªè¿æ¥æ¶æåºå¼å¸¸ |
| | | return false; |
| | | } |
| | | |
| | | public void Dispose() |
| | | { |
| | | _heartStatr = false; |
| | | _communicator.Dispose(); |
| | | GC.SuppressFinalize(this); |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ä¸è¬è¾é线å®ç°ç±» |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using HslCommunication; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Communicator; |
| | | using WIDESEAWCS_QuartzJob.ConveyorLine.Enum; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane.Enum; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob |
| | | { |
| | | [Description("è¾é线")] |
| | | public class CommonConveyorLine_After : IConveyorLine |
| | | { |
| | | #region Private Member |
| | | |
| | | /// <summary> |
| | | /// å åæºé讯对象 |
| | | /// </summary> |
| | | private readonly BaseCommunicator _communicator; |
| | | |
| | | /// <summary> |
| | | /// å åæºåè®®ä¿¡æ¯ |
| | | /// </summary> |
| | | private readonly List<DeviceProDTO> _deviceProDTOs; |
| | | |
| | | /// <summary> |
| | | /// å åæºåè®®æç»ä¿¡æ¯ |
| | | /// </summary> |
| | | private readonly List<DeviceProtocolDetailDTO> _deviceProtocolDetailDTOs; |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¼å· |
| | | /// </summary> |
| | | public readonly string _deviceCode; |
| | | |
| | | /// <summary> |
| | | /// 设å¤åç§° |
| | | /// </summary> |
| | | public readonly string _deviceName; |
| | | |
| | | private bool _heartStatr = true; |
| | | |
| | | private bool _isConnected = true; |
| | | |
| | | #endregion |
| | | |
| | | #region Public Member |
| | | |
| | | /// <summary> |
| | | /// è¾é线é讯对象 |
| | | /// </summary> |
| | | public BaseCommunicator Communicator => _communicator; |
| | | |
| | | /// <summary> |
| | | /// è¾é线åè®®ä¿¡æ¯ |
| | | /// </summary> |
| | | public List<DeviceProDTO> DeviceProDTOs => _deviceProDTOs; |
| | | |
| | | /// <summary> |
| | | /// è¾é线åè®®æç»ä¿¡æ¯ |
| | | /// </summary> |
| | | public List<DeviceProtocolDetailDTO> DeviceProtocolDetailDTOs => _deviceProtocolDetailDTOs; |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¼å· |
| | | /// </summary> |
| | | public string DeviceCode => _deviceCode; |
| | | |
| | | /// <summary> |
| | | /// 设å¤åç§° |
| | | /// </summary> |
| | | public string DeviceName => _deviceName; |
| | | |
| | | /// <summary> |
| | | /// æ¯å¦ææ
é |
| | | /// </summary> |
| | | public bool IsFault => false; |
| | | |
| | | /// <summary> |
| | | /// é讯æ¯å¦å·²è¿æ¥ |
| | | /// </summary> |
| | | public bool IsConnected => Communicator.IsConnected && _isConnected; |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¶æ |
| | | /// </summary> |
| | | public DeviceStatus Status => DeviceStatus.Offline; |
| | | |
| | | #endregion |
| | | |
| | | #region Constructor Function |
| | | |
| | | /// <summary> |
| | | /// æé 彿° |
| | | /// </summary> |
| | | /// <param name="communicator">å åæºé讯对象</param> |
| | | /// <param name="deviceProDTOs">å åæºå议信æ¯</param> |
| | | /// <param name="deviceProtocolDetailDTOs">å åæºåè®®æç»ä¿¡æ¯</param> |
| | | /// <param name="deviceCode">设å¤ç¼å·</param> |
| | | /// <param name="deviceName">设å¤åç§°</param> |
| | | public CommonConveyorLine_After(BaseCommunicator communicator, List<DeviceProDTO> deviceProDTOs, List<DeviceProtocolDetailDTO> deviceProtocolDetailDTOs, string deviceCode, string deviceName) |
| | | { |
| | | _communicator = communicator; |
| | | _deviceProDTOs = deviceProDTOs; |
| | | _deviceProtocolDetailDTOs = deviceProtocolDetailDTOs; |
| | | _deviceCode = deviceCode; |
| | | _deviceName = deviceName; |
| | | CheckConnect(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Private Method |
| | | |
| | | private void CheckConnect() |
| | | { |
| | | Task.Run(() => |
| | | { |
| | | while (_heartStatr) |
| | | { |
| | | try |
| | | { |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(); |
| | | if (devicePro == null) |
| | | _isConnected = false; |
| | | else |
| | | Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | _isConnected = true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _isConnected = false; |
| | | } |
| | | Thread.Sleep(500); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Public Method |
| | | |
| | | /// <summary> |
| | | /// 读åPLCåè®®å°åçæ°æ® |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">å议信æ¯çæä¸¾å¯¹è±¡ä¿¡æ¯ã</typeparam> |
| | | /// <typeparam name="TRsult">è¯»åæ°æ®çç±»å对象信æ¯ã</typeparam> |
| | | /// <param name="value">æä¸¾å¼</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·</param> |
| | | /// <returns>读åå°çæ°æ®</returns> |
| | | public TRsult GetValue<TEnum, TRsult>(TEnum value, string deviceChildCode) where TEnum : Enum |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString() && x.DeviceChildCode == deviceChildCode); |
| | | return devicePro == null ? throw new Exception() : (TRsult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¸è®¾å¤çå¿è·³ |
| | | /// </summary> |
| | | public void Heartbeat() |
| | | { |
| | | throw new NotImplementedException(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="command"></param> |
| | | /// <param name="deviceChildCode"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public bool SendCommand<T>(T command, string deviceChildCode) where T : IDataTransfer, new() |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | if (devicePro == null) |
| | | { |
| | | return false; |
| | | } |
| | | if (Communicator.WriteCustomer(devicePro.DeviceProAddress, command)) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读åPLCæ°æ®ï¼è¿åèªå®ä¹å¯¹è±¡ |
| | | /// </summary> |
| | | /// <typeparam name="T">æ³å</typeparam> |
| | | /// <param name="deviceChildCode">å设å¤ç¼å·</param> |
| | | /// <returns>è¿åèªå®ä¹å¯¹è±¡ææåºå¼å¸¸</returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public T ReadCustomer<T>(string deviceChildCode) where T : IDataTransfer, new() |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == "DeviceCommand" && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | |
| | | if (devicePro == null) |
| | | { |
| | | throw new Exception("æªæ¾å°å议信æ¯"); |
| | | } |
| | | else |
| | | { |
| | | return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读åPLCæ°æ®ï¼è¿åèªå®ä¹å¯¹è±¡ |
| | | /// </summary> |
| | | /// <typeparam name="T">æ³å</typeparam> |
| | | /// <param name="deviceChildCode">å设å¤ç¼å·</param> |
| | | /// <param name="deviceProParamType">åæ°ç±»å</param> |
| | | /// <returns>è¿åèªå®ä¹å¯¹è±¡ææåºå¼å¸¸</returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public T ReadCustomer<T>(string deviceChildCode, string deviceProParamType) where T : IDataTransfer, new() |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == deviceProParamType && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | |
| | | if (devicePro == null) |
| | | { |
| | | throw new Exception("æªæ¾å°å议信æ¯"); |
| | | } |
| | | else |
| | | { |
| | | return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®åæ°åç§°ã设å¤åç¼å·åå
¥å¯¹åºçæ°æ®ã |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">åæ°åç§°æä¸¾ç±»åã</typeparam> |
| | | /// <typeparam name="TValue">è¦åå
¥çæ°æ®ç±»åã</typeparam> |
| | | /// <param name="enum">åæ°åç§°ã</param> |
| | | /// <param name="value">è¦åå
¥çæ°æ®ã</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·å</param> |
| | | /// <returns>è¿ååå
¥æåæå¤±è´¥</returns> |
| | | public bool SetValue<TEnum, TValue>(TEnum @enum, TValue value, string deviceChildCode) |
| | | where TEnum : Enum |
| | | where TValue : notnull |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode); |
| | | return devicePro == null ? throw new Exception() : Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®åæ°åç§°ã设å¤åç¼å·è¯»å对åºçæ°æ®ã |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">åæ°åç§°æä¸¾ç±»åã</typeparam> |
| | | /// <param name="enum">åæ°åç§°ã</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·å</param> |
| | | /// <returns>è¿ååå
¥æåæå¤±è´¥</returns> |
| | | public object ReadValue<TEnum>(TEnum @enum, string deviceChildCode) |
| | | where TEnum : Enum |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode); |
| | | return devicePro == null ? throw new Exception() : Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | } |
| | | |
| | | //public bool IsOccupied(string deviceChildCode) |
| | | //{ |
| | | // if (Communicator.IsConnected) |
| | | // { |
| | | |
| | | // } |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="deviceChildCode"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public bool IsOccupied(string deviceChildCode) |
| | | { |
| | | if (Communicator.IsConnected) |
| | | { |
| | | List<DeviceProDTO> devicePros = _deviceProDTOs.Where(x => x.DeviceChildCode == deviceChildCode && x.DeviceProParamName == "InteractiveSignal").ToList(); |
| | | if (devicePros.Count == 0) |
| | | { |
| | | //todo åè®®ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ |
| | | throw new Exception(); |
| | | } |
| | | |
| | | for (int i = 0; i < devicePros.Count; i++) |
| | | { |
| | | object readStatus = Communicator.ReadAsObj(devicePros[i].DeviceProAddress, devicePros[i].DeviceDataType); |
| | | //todo åè®®æç»ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ |
| | | DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamName) ?? throw new Exception(); |
| | | deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == "InteractiveSignal" && x.ProtocalDetailValue.Equals(readStatus.ToString())); |
| | | if (deviceProtocolDetail != null) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | //todo é讯æªè¿æ¥æ¶æåºå¼å¸¸ |
| | | return false; |
| | | } |
| | | |
| | | public void Dispose() |
| | | { |
| | | _heartStatr = false; |
| | | _communicator.Dispose(); |
| | | GC.SuppressFinalize(this); |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ä¸è¬è¾é线å®ç°ç±» |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using HslCommunication; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Communicator; |
| | | using WIDESEAWCS_QuartzJob.ConveyorLine.Enum; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane.Enum; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob |
| | | { |
| | | [Description("è¾é线")] |
| | | public class CommonConveyorLine_BZ : IConveyorLine |
| | | { |
| | | #region Private Member |
| | | |
| | | /// <summary> |
| | | /// å åæºé讯对象 |
| | | /// </summary> |
| | | private readonly BaseCommunicator _communicator; |
| | | |
| | | /// <summary> |
| | | /// å åæºåè®®ä¿¡æ¯ |
| | | /// </summary> |
| | | private readonly List<DeviceProDTO> _deviceProDTOs; |
| | | |
| | | /// <summary> |
| | | /// å åæºåè®®æç»ä¿¡æ¯ |
| | | /// </summary> |
| | | private readonly List<DeviceProtocolDetailDTO> _deviceProtocolDetailDTOs; |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¼å· |
| | | /// </summary> |
| | | public readonly string _deviceCode; |
| | | |
| | | /// <summary> |
| | | /// 设å¤åç§° |
| | | /// </summary> |
| | | public readonly string _deviceName; |
| | | |
| | | private bool _heartStatr = true; |
| | | |
| | | private bool _isConnected = true; |
| | | |
| | | #endregion |
| | | |
| | | #region Public Member |
| | | |
| | | /// <summary> |
| | | /// è¾é线é讯对象 |
| | | /// </summary> |
| | | public BaseCommunicator Communicator => _communicator; |
| | | |
| | | /// <summary> |
| | | /// è¾é线åè®®ä¿¡æ¯ |
| | | /// </summary> |
| | | public List<DeviceProDTO> DeviceProDTOs => _deviceProDTOs; |
| | | |
| | | /// <summary> |
| | | /// è¾é线åè®®æç»ä¿¡æ¯ |
| | | /// </summary> |
| | | public List<DeviceProtocolDetailDTO> DeviceProtocolDetailDTOs => _deviceProtocolDetailDTOs; |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¼å· |
| | | /// </summary> |
| | | public string DeviceCode => _deviceCode; |
| | | |
| | | /// <summary> |
| | | /// 设å¤åç§° |
| | | /// </summary> |
| | | public string DeviceName => _deviceName; |
| | | |
| | | /// <summary> |
| | | /// æ¯å¦ææ
é |
| | | /// </summary> |
| | | public bool IsFault => false; |
| | | |
| | | /// <summary> |
| | | /// é讯æ¯å¦å·²è¿æ¥ |
| | | /// </summary> |
| | | public bool IsConnected => Communicator.IsConnected && _isConnected; |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¶æ |
| | | /// </summary> |
| | | public DeviceStatus Status => DeviceStatus.Offline; |
| | | |
| | | #endregion |
| | | |
| | | #region Constructor Function |
| | | |
| | | /// <summary> |
| | | /// æé 彿° |
| | | /// </summary> |
| | | /// <param name="communicator">å åæºé讯对象</param> |
| | | /// <param name="deviceProDTOs">å åæºå议信æ¯</param> |
| | | /// <param name="deviceProtocolDetailDTOs">å åæºåè®®æç»ä¿¡æ¯</param> |
| | | /// <param name="deviceCode">设å¤ç¼å·</param> |
| | | /// <param name="deviceName">设å¤åç§°</param> |
| | | public CommonConveyorLine_BZ(BaseCommunicator communicator, List<DeviceProDTO> deviceProDTOs, List<DeviceProtocolDetailDTO> deviceProtocolDetailDTOs, string deviceCode, string deviceName) |
| | | { |
| | | _communicator = communicator; |
| | | _deviceProDTOs = deviceProDTOs; |
| | | _deviceProtocolDetailDTOs = deviceProtocolDetailDTOs; |
| | | _deviceCode = deviceCode; |
| | | _deviceName = deviceName; |
| | | CheckConnect(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Private Method |
| | | |
| | | private void CheckConnect() |
| | | { |
| | | Task.Run(() => |
| | | { |
| | | while (_heartStatr) |
| | | { |
| | | try |
| | | { |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(); |
| | | if (devicePro == null) |
| | | _isConnected = false; |
| | | else |
| | | Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | _isConnected = true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _isConnected = false; |
| | | } |
| | | Thread.Sleep(500); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Public Method |
| | | |
| | | /// <summary> |
| | | /// 读åPLCåè®®å°åçæ°æ® |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">å议信æ¯çæä¸¾å¯¹è±¡ä¿¡æ¯ã</typeparam> |
| | | /// <typeparam name="TRsult">è¯»åæ°æ®çç±»å对象信æ¯ã</typeparam> |
| | | /// <param name="value">æä¸¾å¼</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·</param> |
| | | /// <returns>读åå°çæ°æ®</returns> |
| | | public TRsult GetValue<TEnum, TRsult>(TEnum value, string deviceChildCode) where TEnum : Enum |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString() && x.DeviceChildCode == deviceChildCode); |
| | | return devicePro == null ? throw new Exception() : (TRsult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¸è®¾å¤çå¿è·³ |
| | | /// </summary> |
| | | public void Heartbeat() |
| | | { |
| | | throw new NotImplementedException(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="command"></param> |
| | | /// <param name="deviceChildCode"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public bool SendCommand<T>(T command, string deviceChildCode) where T : IDataTransfer, new() |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | if (devicePro == null) |
| | | { |
| | | return false; |
| | | } |
| | | if (Communicator.WriteCustomer(devicePro.DeviceProAddress, command)) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读åPLCæ°æ®ï¼è¿åèªå®ä¹å¯¹è±¡ |
| | | /// </summary> |
| | | /// <typeparam name="T">æ³å</typeparam> |
| | | /// <param name="deviceChildCode">å设å¤ç¼å·</param> |
| | | /// <returns>è¿åèªå®ä¹å¯¹è±¡ææåºå¼å¸¸</returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public T ReadCustomer<T>(string deviceChildCode) where T : IDataTransfer, new() |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == "DeviceCommand" && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | |
| | | if (devicePro == null) |
| | | { |
| | | throw new Exception($"ã{_deviceCode}ã--æªæ¾å°ã{deviceChildCode}ãå议信æ¯"); |
| | | } |
| | | else |
| | | { |
| | | return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读åPLCæ°æ®ï¼è¿åèªå®ä¹å¯¹è±¡ |
| | | /// </summary> |
| | | /// <typeparam name="T">æ³å</typeparam> |
| | | /// <param name="deviceChildCode">å设å¤ç¼å·</param> |
| | | /// <param name="deviceProParamType">åæ°ç±»å</param> |
| | | /// <returns>è¿åèªå®ä¹å¯¹è±¡ææåºå¼å¸¸</returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public T ReadCustomer<T>(string deviceChildCode, string deviceProParamType) where T : IDataTransfer, new() |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == deviceProParamType && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | |
| | | if (devicePro == null) |
| | | { |
| | | throw new Exception($"æªæ¾å°ã{deviceChildCode}ãå议信æ¯"); |
| | | } |
| | | else |
| | | { |
| | | return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®åæ°åç§°ã设å¤åç¼å·åå
¥å¯¹åºçæ°æ®ã |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">åæ°åç§°æä¸¾ç±»åã</typeparam> |
| | | /// <typeparam name="TValue">è¦åå
¥çæ°æ®ç±»åã</typeparam> |
| | | /// <param name="enum">åæ°åç§°ã</param> |
| | | /// <param name="value">è¦åå
¥çæ°æ®ã</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·å</param> |
| | | /// <returns>è¿ååå
¥æåæå¤±è´¥</returns> |
| | | public bool SetValue<TEnum, TValue>(TEnum @enum, TValue value, string deviceChildCode) |
| | | where TEnum : Enum |
| | | where TValue : notnull |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode); |
| | | return devicePro == null ? throw new Exception() : Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®åæ°åç§°ã设å¤åç¼å·è¯»å对åºçæ°æ®ã |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">åæ°åç§°æä¸¾ç±»åã</typeparam> |
| | | /// <param name="enum">åæ°åç§°ã</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·å</param> |
| | | /// <returns>è¿ååå
¥æåæå¤±è´¥</returns> |
| | | public object ReadValue<TEnum>(TEnum @enum, string deviceChildCode) |
| | | where TEnum : Enum |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode); |
| | | return devicePro == null ? throw new Exception() : Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | } |
| | | |
| | | //public bool IsOccupied(string deviceChildCode) |
| | | //{ |
| | | // if (Communicator.IsConnected) |
| | | // { |
| | | |
| | | // } |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="deviceChildCode"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public bool IsOccupied(string deviceChildCode) |
| | | { |
| | | if (Communicator.IsConnected) |
| | | { |
| | | List<DeviceProDTO> devicePros = _deviceProDTOs.Where(x => x.DeviceChildCode == deviceChildCode && x.DeviceProParamName == "InteractiveSignal").ToList(); |
| | | if (devicePros.Count == 0) |
| | | { |
| | | //todo åè®®ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ |
| | | throw new Exception(); |
| | | } |
| | | |
| | | for (int i = 0; i < devicePros.Count; i++) |
| | | { |
| | | object readStatus = Communicator.ReadAsObj(devicePros[i].DeviceProAddress, devicePros[i].DeviceDataType); |
| | | //todo åè®®æç»ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ |
| | | DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamName) ?? throw new Exception(); |
| | | deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == "InteractiveSignal" && x.ProtocalDetailValue.Equals(readStatus.ToString())); |
| | | if (deviceProtocolDetail != null) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | //todo é讯æªè¿æ¥æ¶æåºå¼å¸¸ |
| | | return false; |
| | | } |
| | | |
| | | public void Dispose() |
| | | { |
| | | _heartStatr = false; |
| | | _communicator.Dispose(); |
| | | GC.SuppressFinalize(this); |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ä¸è¬è¾é线å®ç°ç±» |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using HslCommunication; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Communicator; |
| | | using WIDESEAWCS_QuartzJob.ConveyorLine.Enum; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane.Enum; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob |
| | | { |
| | | [Description("è¾é线")] |
| | | public class CommonConveyorLine_GW : IConveyorLine |
| | | { |
| | | #region Private Member |
| | | |
| | | /// <summary> |
| | | /// å åæºé讯对象 |
| | | /// </summary> |
| | | private readonly BaseCommunicator _communicator; |
| | | |
| | | /// <summary> |
| | | /// å åæºåè®®ä¿¡æ¯ |
| | | /// </summary> |
| | | private readonly List<DeviceProDTO> _deviceProDTOs; |
| | | |
| | | /// <summary> |
| | | /// å åæºåè®®æç»ä¿¡æ¯ |
| | | /// </summary> |
| | | private readonly List<DeviceProtocolDetailDTO> _deviceProtocolDetailDTOs; |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¼å· |
| | | /// </summary> |
| | | public readonly string _deviceCode; |
| | | |
| | | /// <summary> |
| | | /// 设å¤åç§° |
| | | /// </summary> |
| | | public readonly string _deviceName; |
| | | |
| | | private bool _heartStatr = true; |
| | | |
| | | private bool _isConnected = true; |
| | | |
| | | #endregion |
| | | |
| | | #region Public Member |
| | | |
| | | /// <summary> |
| | | /// è¾é线é讯对象 |
| | | /// </summary> |
| | | public BaseCommunicator Communicator => _communicator; |
| | | |
| | | /// <summary> |
| | | /// è¾é线åè®®ä¿¡æ¯ |
| | | /// </summary> |
| | | public List<DeviceProDTO> DeviceProDTOs => _deviceProDTOs; |
| | | |
| | | /// <summary> |
| | | /// è¾é线åè®®æç»ä¿¡æ¯ |
| | | /// </summary> |
| | | public List<DeviceProtocolDetailDTO> DeviceProtocolDetailDTOs => _deviceProtocolDetailDTOs; |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¼å· |
| | | /// </summary> |
| | | public string DeviceCode => _deviceCode; |
| | | |
| | | /// <summary> |
| | | /// 设å¤åç§° |
| | | /// </summary> |
| | | public string DeviceName => _deviceName; |
| | | |
| | | /// <summary> |
| | | /// æ¯å¦ææ
é |
| | | /// </summary> |
| | | public bool IsFault => false; |
| | | |
| | | /// <summary> |
| | | /// é讯æ¯å¦å·²è¿æ¥ |
| | | /// </summary> |
| | | public bool IsConnected => Communicator.IsConnected && _isConnected; |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¶æ |
| | | /// </summary> |
| | | public DeviceStatus Status => DeviceStatus.Offline; |
| | | |
| | | #endregion |
| | | |
| | | #region Constructor Function |
| | | |
| | | /// <summary> |
| | | /// æé 彿° |
| | | /// </summary> |
| | | /// <param name="communicator">å åæºé讯对象</param> |
| | | /// <param name="deviceProDTOs">å åæºå议信æ¯</param> |
| | | /// <param name="deviceProtocolDetailDTOs">å åæºåè®®æç»ä¿¡æ¯</param> |
| | | /// <param name="deviceCode">设å¤ç¼å·</param> |
| | | /// <param name="deviceName">设å¤åç§°</param> |
| | | public CommonConveyorLine_GW(BaseCommunicator communicator, List<DeviceProDTO> deviceProDTOs, List<DeviceProtocolDetailDTO> deviceProtocolDetailDTOs, string deviceCode, string deviceName) |
| | | { |
| | | _communicator = communicator; |
| | | _deviceProDTOs = deviceProDTOs; |
| | | _deviceProtocolDetailDTOs = deviceProtocolDetailDTOs; |
| | | _deviceCode = deviceCode; |
| | | _deviceName = deviceName; |
| | | CheckConnect(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Private Method |
| | | |
| | | private void CheckConnect() |
| | | { |
| | | Task.Run(() => |
| | | { |
| | | while (_heartStatr) |
| | | { |
| | | try |
| | | { |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(); |
| | | if (devicePro == null) |
| | | _isConnected = false; |
| | | else |
| | | Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | _isConnected = true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _isConnected = false; |
| | | } |
| | | Thread.Sleep(500); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Public Method |
| | | |
| | | /// <summary> |
| | | /// 读åPLCåè®®å°åçæ°æ® |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">å议信æ¯çæä¸¾å¯¹è±¡ä¿¡æ¯ã</typeparam> |
| | | /// <typeparam name="TRsult">è¯»åæ°æ®çç±»å对象信æ¯ã</typeparam> |
| | | /// <param name="value">æä¸¾å¼</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·</param> |
| | | /// <returns>读åå°çæ°æ®</returns> |
| | | public TRsult GetValue<TEnum, TRsult>(TEnum value, string deviceChildCode) where TEnum : Enum |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString() && x.DeviceChildCode == deviceChildCode); |
| | | return devicePro == null ? throw new Exception() : (TRsult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¸è®¾å¤çå¿è·³ |
| | | /// </summary> |
| | | public void Heartbeat() |
| | | { |
| | | throw new NotImplementedException(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="command"></param> |
| | | /// <param name="deviceChildCode"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public bool SendCommand<T>(T command, string deviceChildCode) where T : IDataTransfer, new() |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | if (devicePro == null) |
| | | { |
| | | return false; |
| | | } |
| | | if (Communicator.WriteCustomer(devicePro.DeviceProAddress, command)) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读åPLCæ°æ®ï¼è¿åèªå®ä¹å¯¹è±¡ |
| | | /// </summary> |
| | | /// <typeparam name="T">æ³å</typeparam> |
| | | /// <param name="deviceChildCode">å设å¤ç¼å·</param> |
| | | /// <returns>è¿åèªå®ä¹å¯¹è±¡ææåºå¼å¸¸</returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public T ReadCustomer<T>(string deviceChildCode) where T : IDataTransfer, new() |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == "DeviceCommand" && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | |
| | | if (devicePro == null) |
| | | { |
| | | throw new Exception($"ã{_deviceCode}ã--æªæ¾å°ã{deviceChildCode}ãå议信æ¯"); |
| | | } |
| | | else |
| | | { |
| | | return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读åPLCæ°æ®ï¼è¿åèªå®ä¹å¯¹è±¡ |
| | | /// </summary> |
| | | /// <typeparam name="T">æ³å</typeparam> |
| | | /// <param name="deviceChildCode">å设å¤ç¼å·</param> |
| | | /// <param name="deviceProParamType">åæ°ç±»å</param> |
| | | /// <returns>è¿åèªå®ä¹å¯¹è±¡ææåºå¼å¸¸</returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public T ReadCustomer<T>(string deviceChildCode, string deviceProParamType) where T : IDataTransfer, new() |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == deviceProParamType && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | |
| | | if (devicePro == null) |
| | | { |
| | | throw new Exception($"æªæ¾å°ã{deviceChildCode}ãå议信æ¯"); |
| | | } |
| | | else |
| | | { |
| | | return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®åæ°åç§°ã设å¤åç¼å·åå
¥å¯¹åºçæ°æ®ã |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">åæ°åç§°æä¸¾ç±»åã</typeparam> |
| | | /// <typeparam name="TValue">è¦åå
¥çæ°æ®ç±»åã</typeparam> |
| | | /// <param name="enum">åæ°åç§°ã</param> |
| | | /// <param name="value">è¦åå
¥çæ°æ®ã</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·å</param> |
| | | /// <returns>è¿ååå
¥æåæå¤±è´¥</returns> |
| | | public bool SetValue<TEnum, TValue>(TEnum @enum, TValue value, string deviceChildCode) |
| | | where TEnum : Enum |
| | | where TValue : notnull |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode); |
| | | return devicePro == null ? throw new Exception() : Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®åæ°åç§°ã设å¤åç¼å·è¯»å对åºçæ°æ®ã |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">åæ°åç§°æä¸¾ç±»åã</typeparam> |
| | | /// <param name="enum">åæ°åç§°ã</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·å</param> |
| | | /// <returns>è¿ååå
¥æåæå¤±è´¥</returns> |
| | | public object ReadValue<TEnum>(TEnum @enum, string deviceChildCode) |
| | | where TEnum : Enum |
| | | { |
| | | if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); |
| | | DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode); |
| | | return devicePro == null ? throw new Exception() : Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); |
| | | } |
| | | |
| | | //public bool IsOccupied(string deviceChildCode) |
| | | //{ |
| | | // if (Communicator.IsConnected) |
| | | // { |
| | | |
| | | // } |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="deviceChildCode"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public bool IsOccupied(string deviceChildCode) |
| | | { |
| | | if (Communicator.IsConnected) |
| | | { |
| | | List<DeviceProDTO> devicePros = _deviceProDTOs.Where(x => x.DeviceChildCode == deviceChildCode && x.DeviceProParamName == "InteractiveSignal").ToList(); |
| | | if (devicePros.Count == 0) |
| | | { |
| | | //todo åè®®ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ |
| | | throw new Exception(); |
| | | } |
| | | |
| | | for (int i = 0; i < devicePros.Count; i++) |
| | | { |
| | | object readStatus = Communicator.ReadAsObj(devicePros[i].DeviceProAddress, devicePros[i].DeviceDataType); |
| | | //todo åè®®æç»ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ |
| | | DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamName) ?? throw new Exception(); |
| | | deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == "InteractiveSignal" && x.ProtocalDetailValue.Equals(readStatus.ToString())); |
| | | if (deviceProtocolDetail != null) |
| | | { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | //todo é讯æªè¿æ¥æ¶æåºå¼å¸¸ |
| | | return false; |
| | | } |
| | | |
| | | public void Dispose() |
| | | { |
| | | _heartStatr = false; |
| | | _communicator.Dispose(); |
| | | GC.SuppressFinalize(this); |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.ConveyorLine.Enum |
| | | { |
| | | public enum ConveyorLineStatus |
| | | { |
| | | /// <summary> |
| | | /// æªç¥ |
| | | /// </summary> |
| | | [Description("æªç¥")] |
| | | Unknown, |
| | | |
| | | /// <summary> |
| | | /// æ¯å¦è¢«å ç¨ |
| | | /// </summary> |
| | | [Description("æ¯å¦è¢«å ç¨")] |
| | | IsOccupied, |
| | | |
| | | InteractiveSignal, |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è¾é线æ¥å£å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using HslCommunication; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Communicator; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob |
| | | { |
| | | public interface IConveyorLine : IDevice |
| | | { |
| | | /// <summary> |
| | | /// è¾é线é讯对象 |
| | | /// </summary> |
| | | BaseCommunicator Communicator { get; } |
| | | |
| | | /// <summary> |
| | | /// è¾é线åè®®ä¿¡æ¯ |
| | | /// </summary> |
| | | List<DeviceProDTO> DeviceProDTOs { get; } |
| | | |
| | | /// <summary> |
| | | /// è¾é线åè®®æç»ä¿¡æ¯ |
| | | /// </summary> |
| | | List<DeviceProtocolDetailDTO> DeviceProtocolDetailDTOs { get; } |
| | | |
| | | /// <summary> |
| | | /// ä¸è®¾å¤çå¿è·³ |
| | | /// </summary> |
| | | void Heartbeat(); |
| | | |
| | | /// <summary> |
| | | /// 读åPLCåè®®å°åçæ°æ® |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">å议信æ¯çæä¸¾å¯¹è±¡ä¿¡æ¯ã</typeparam> |
| | | /// <typeparam name="TRsult">è¯»åæ°æ®çç±»å对象信æ¯ã</typeparam> |
| | | /// <param name="value">æä¸¾å¼</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·</param> |
| | | /// <returns>读åå°çæ°æ®</returns> |
| | | TRsult GetValue<TEnum, TRsult>(TEnum value, string deviceChildCode) where TEnum : Enum; |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®åæ°åç§°ã设å¤åç¼å·åå
¥å¯¹åºçæ°æ®ã |
| | | /// </summary> |
| | | /// <typeparam name="TEnum">åæ°åç§°æä¸¾ç±»åã</typeparam> |
| | | /// <typeparam name="TValue">è¦åå
¥çæ°æ®ç±»åã</typeparam> |
| | | /// <param name="enum">åæ°åç§°ã</param> |
| | | /// <param name="value">è¦åå
¥çæ°æ®ã</param> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·å</param> |
| | | /// <returns>è¿ååå
¥æåæå¤±è´¥</returns> |
| | | bool SetValue<TEnum, TValue>(TEnum @enum, TValue value, string deviceChildCode) where TEnum : Enum where TValue : notnull; |
| | | |
| | | /// <summary> |
| | | /// 读åç«å°æ¯å¦è¢«å ç¨ |
| | | /// </summary> |
| | | /// <param name="deviceChildCode">设å¤åç¼å·</param> |
| | | /// <returns></returns> |
| | | bool IsOccupied(string deviceChildCode); |
| | | |
| | | /// <summary> |
| | | /// åéä»»å¡å½ä»¤ |
| | | /// </summary> |
| | | /// <typeparam name="T">ä»»å¡å½ä»¤å¯¹è±¡çç±»åæ³å</typeparam> |
| | | /// <param name="command">ä»»å¡å½ä»¤</param> |
| | | /// <returns></returns> |
| | | bool SendCommand<T>(T command, string deviceChildCode) where T : IDataTransfer, new(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼èªå®ä¹è°åº¦æå¡å¼å¸¸ç±» |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.CustomException |
| | | { |
| | | /// <summary> |
| | | /// 宿¶å¨é误类 |
| | | /// </summary> |
| | | [Serializable] |
| | | public class QuartzJobException : Exception |
| | | { |
| | | |
| | | /// <summary> |
| | | /// é误代ç |
| | | /// </summary> |
| | | public int? ErrorCode { get; } |
| | | |
| | | /// <summary> |
| | | /// é误类å |
| | | /// </summary> |
| | | public string ErrorType { get; } |
| | | |
| | | public Exception? BaseException { get; } |
| | | |
| | | public override string Message => _message; |
| | | |
| | | private string _message; |
| | | |
| | | /// <summary> |
| | | /// åå§åä¸ä¸ªæ°ç CommunicationException å®ä¾ã |
| | | /// </summary> |
| | | /// <param name="message">é误çæè¿°ã</param> |
| | | /// <param name="errorType">é误类åã</param> |
| | | /// <param name="errorCode">é误代ç ï¼å¯éï¼ã</param> |
| | | /// <param name="innerException">导è´å½åå¼å¸¸çå¼å¸¸ï¼å¯éï¼ã</param> |
| | | public QuartzJobException(string message, string errorType = "", int? errorCode = null, Exception? innerException = null) |
| | | { |
| | | ErrorCode = errorCode; |
| | | ErrorType = errorType; |
| | | BaseException = innerException; |
| | | _message = message; |
| | | } |
| | | |
| | | public override string ToString() |
| | | { |
| | | return base.ToString(); |
| | | } |
| | | } |
| | | |
| | | |
| | | public enum QuartzJobErrorType |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | Warning, |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | Error, |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | Exception, |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | LogicError |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è°åº¦æå¡å¼å¸¸ |
| | | /// </summary> |
| | | public class QuartzJobExceptionMessage |
| | | { |
| | | public const string StartJobException = "è°åº¦æå¡å¼å¯å¼å¸¸ï¼é误信æ¯:{0}"; |
| | | |
| | | public const string StopJobException = "è°åº¦æå¡åæ¢å¼å¸¸ï¼é误信æ¯:{0}"; |
| | | |
| | | public const string AddJobException = "è°åº¦è®¡åæ·»å å¼å¸¸ï¼ã{0}ãï¼é误信æ¯:{1}"; |
| | | |
| | | public const string JobFactoryInstanceException = "ä»Factoryä¸è·åSchedulerå®ä¾å¼å¸¸ï¼é误信æ¯:{0}"; |
| | | |
| | | public const string StopAJobException = "è°åº¦è®¡åã{0}ã忢å¼å¸¸ï¼é误信æ¯:{1}"; |
| | | |
| | | public const string ResumeJobException = "è°åº¦è®¡åã{0}ãæ¢å¤å¼å¸¸ï¼é误信æ¯:{1}"; |
| | | |
| | | public const string ExecuteJobException = "ç«å³æ§è¡è°åº¦è®¡åï¼ã{0}ãå¼å¸¸ï¼é误信æ¯:{1}"; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è°åº¦æå¡ä¿¡æ¯ |
| | | /// </summary> |
| | | public class QuartzJobInfoMessage |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string JobHasStart = "è°åº¦æå¡å·²ç»å¼å¯"; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string StartJobSuccess = "è°åº¦æå¡å¼å¯æå"; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string JobHasStop = "è°åº¦æå¡å·²ç»åæ¢"; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string StopJobSuccess = "è°åº¦æå¡åæ¢æå"; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string JobHasAdd = "该è°åº¦è®¡åå·²ç»å¨æ§è¡ï¼ã{0}ã,请å¿éå¤å¯å¨ï¼"; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string JobAddSuccess = "ã{0}ãè°åº¦è®¡åæ·»å å°è°åº¦ä¸å¿æå"; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string JobNotExist = "è°åº¦è®¡åä¸åå¨ï¼ã{0}ã"; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string StopAJobSuccess = "è°åº¦è®¡åã{0}ã忢æå"; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string ResumeJobSuccess = "è°åº¦è®¡åã{0}ãæ¢å¤æå"; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string ResumeJobNotExist = "æªæ¾å°è¦æ¢å¤çè°åº¦è®¡åï¼ã{0}ã"; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string PauseJobSuccess = "è°åº¦è®¡åã{0}ãæåæå"; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string PauseJobNotExist = "æªæ¾å°è¦æåçè°åº¦è®¡åï¼ã{0}ã"; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public const string ExecuteJobSuccess = "ç«å³æ§è¡è°åº¦è®¡å:ã{0}ãæå"; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤ä¿¡æ¯DTOï¼ç»§æ¿è®¾å¤ä¿¡æ¯å®ä½ï¼å°è£
设å¤åºç¡æ¥å£å±å±æ§ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.DTO |
| | | { |
| | | public class DeviceInfoDTO : Dt_DeviceInfo |
| | | { |
| | | /// <summary> |
| | | /// 设å¤åºç¡æ¥å£å± |
| | | /// </summary> |
| | | public IDevice Device { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤åè®®DTO |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.DTO |
| | | { |
| | | public class DeviceProDTO |
| | | { |
| | | /// <summary> |
| | | /// åè®®ä¸»é® |
| | | /// </summary> |
| | | public int DeviceProId { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤ä¿¡æ¯ä¸»é® |
| | | /// </summary> |
| | | public int DeviceId { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å设å¤ç¼å· |
| | | /// </summary> |
| | | public string DeviceChildCode { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åè®®æ°æ®å |
| | | /// </summary> |
| | | public string DeviceProDataBlock { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åç§»é |
| | | /// </summary> |
| | | public decimal DeviceProOffset { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åè®®å°å |
| | | /// </summary> |
| | | public string DeviceProAddress |
| | | { |
| | | get |
| | | { |
| | | return DeviceProDataBlock + "." + DeviceProOffset; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ°æ®ç±»å |
| | | /// </summary> |
| | | public string DeviceDataType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ°æ®é¿åº¦ |
| | | /// </summary> |
| | | public int DeviceProDataLength { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åæ°åç§° |
| | | /// </summary> |
| | | public string DeviceProParamName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åæ°ç±»å |
| | | /// </summary> |
| | | public string DeviceProParamType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åæ°è¯´æ |
| | | /// </summary> |
| | | public string DeviceProParamDes { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤åè®®æç»DTO |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.DTO |
| | | { |
| | | public class DeviceProtocolDetailDTO |
| | | { |
| | | /// <summary> |
| | | /// 设å¤ç±»å |
| | | /// </summary> |
| | | public string DeviceType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åæ°åç§° |
| | | /// </summary> |
| | | public string DeviceProParamName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤åè®®æç»åå¼ |
| | | /// </summary> |
| | | public string ProtocalDetailValue { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤åè®®æç»ç±»å |
| | | /// </summary> |
| | | public string ProtocolDetailType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤åè®®æç»è¯´æ |
| | | /// </summary> |
| | | public string ProtocolDetailDes { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è°åº¦æå¡é
ç½®DTO |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.DTO |
| | | { |
| | | public class DispatchInfoDTO : Dt_DispatchInfo |
| | | { |
| | | /// <summary> |
| | | /// å·²å¾ªç¯æ¬¡æ° |
| | | /// </summary> |
| | | public int CycleHasRunTimes { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ§è¡ä¼ å |
| | | /// </summary> |
| | | public object JobParams { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç±»å |
| | | /// </summary> |
| | | public string DeviceType { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è°åº¦æå¡ç¶æä¿¡æ¯DTO |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.DTO |
| | | { |
| | | internal class DispatchStatusDTO |
| | | { |
| | | /// <summary> |
| | | /// ä»»å¡ID |
| | | /// </summary> |
| | | public string JobId { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡åç§° |
| | | /// </summary> |
| | | public string JobName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡åç» |
| | | /// </summary> |
| | | public string JobGroup { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 触åå¨ID |
| | | /// </summary> |
| | | public string TriggerId { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 触åå¨åç§° |
| | | /// </summary> |
| | | public string TriggerName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 触åå¨åç» |
| | | /// </summary> |
| | | public string TriggerGroup { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 触åå¨ç¶æ |
| | | /// </summary> |
| | | public string TriggerStatus { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_DTO.BasicInfo |
| | | { |
| | | public class RoutersAddDTO |
| | | { |
| | | /// <summary> |
| | | /// ä½ç½®ç¼å· |
| | | /// </summary> |
| | | public string PositionCode { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åä½ç½®ç¼å· |
| | | /// </summary> |
| | | public string ChildPositionCode { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å åæºè¡ |
| | | /// </summary> |
| | | public string SCRow { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å åæºå |
| | | /// </summary> |
| | | public string SCColumn { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å åæºå± |
| | | /// </summary> |
| | | public string SCLayer { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.DeviceBase.CustomException |
| | | { |
| | | internal class StackerCraneException |
| | | { |
| | | } |
| | | } |
copy from "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs"
copy to "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/DeviceBase/DataLengthAttribute.cs"
Îļþ´Ó ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs ¸´ÖÆ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_ITaskInfoRepository |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob.DeviceBase |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | |
| | | namespace WIDESEAWCS_ISystemRepository |
| | | namespace WIDESEAWCS_QuartzJob.DeviceBase |
| | | { |
| | | public interface IAgvStationRepository : IRepository<AGVStation> |
| | | [AttributeUsage(AttributeTargets.Property)] |
| | | public class DataLengthAttribute : Attribute |
| | | { |
| | | public DataLengthAttribute(ushort dataLength) |
| | | { |
| | | DataLength = dataLength; |
| | | } |
| | | |
| | | public ushort DataLength { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob.DeviceBase |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using HslCommunication; |
| | | using HslCommunication.Core; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.DeviceBase |
| | | { |
| | | public class DeviceCommand : IDataTransfer |
| | | { |
| | | #region <Const> |
| | | #endregion <Const> |
| | | |
| | | #region <Private Member> |
| | | public ushort ReadCount { get; } |
| | | |
| | | private IByteTransform byteTransform = new ReverseBytesTransform(); |
| | | #endregion <Private Member> |
| | | |
| | | #region <Public Menber> |
| | | |
| | | #endregion <Public Menber> |
| | | |
| | | #region <Constructor function> |
| | | public DeviceCommand() |
| | | { |
| | | ushort readCount = 0; |
| | | PropertyInfo[] propertyInfos = GetType().GetProperties().Where(x => x.CanWrite).ToArray(); |
| | | foreach (PropertyInfo propertyInfo in propertyInfos) |
| | | { |
| | | object? obj = propertyInfo.GetValue(this); |
| | | TypeCode typeCode = Type.GetTypeCode(propertyInfo.PropertyType); |
| | | switch (typeCode) |
| | | { |
| | | case TypeCode.Byte: |
| | | case TypeCode.SByte: |
| | | case TypeCode.Char: |
| | | readCount += sizeof(byte); |
| | | break; |
| | | case TypeCode.Int16: |
| | | case TypeCode.UInt16: |
| | | readCount += 2; |
| | | break; |
| | | case TypeCode.Single: |
| | | case TypeCode.Int32: |
| | | case TypeCode.UInt32: |
| | | readCount += 4; |
| | | break; |
| | | case TypeCode.String: |
| | | ushort dataLength = CheckStringAttribute(propertyInfo); |
| | | readCount += dataLength; |
| | | break; |
| | | default: |
| | | throw new NotSupportedException("Unsupported primitive type: " + propertyInfo.PropertyType); |
| | | } |
| | | } |
| | | ReadCount = readCount; |
| | | } |
| | | #endregion <Constructor function> |
| | | |
| | | #region <Private Method> |
| | | private ushort CheckStringAttribute(PropertyInfo propertyInfo) |
| | | { |
| | | Attribute? attribute = propertyInfo.GetCustomAttribute(typeof(DataLengthAttribute)); |
| | | if (attribute == null) |
| | | { |
| | | throw new Exception($"å符串éè¦é
ç½®ãDataLengthãç¹æ§"); |
| | | } |
| | | ushort dataLength = ((DataLengthAttribute)attribute).DataLength; |
| | | if (dataLength <= 0 || dataLength > 256) |
| | | { |
| | | throw new Exception($"ãDataLengthãç¹æ§è¯·é
ç½®ææåæ°,åæ°èå´ã1-256ã"); |
| | | } |
| | | if (dataLength % 2 != 0) |
| | | { |
| | | dataLength += 1; |
| | | } |
| | | dataLength += 2; |
| | | |
| | | return dataLength; |
| | | } |
| | | #endregion <Private Method> |
| | | |
| | | #region <Public Method> |
| | | public void ParseSource(byte[] Content) |
| | | { |
| | | PropertyInfo[] propertyInfos = GetType().GetProperties().Where(x => x.CanWrite).ToArray(); |
| | | int index = 0; |
| | | for (int i = 0; i < propertyInfos.Length; i++) |
| | | { |
| | | PropertyInfo propertyInfo = propertyInfos[i]; |
| | | |
| | | TypeCode typeCode = Type.GetTypeCode(propertyInfo.PropertyType); |
| | | switch (typeCode) |
| | | { |
| | | case TypeCode.Byte: |
| | | case TypeCode.SByte: |
| | | propertyInfo.SetValue(this, Content[index]); |
| | | index += sizeof(byte); |
| | | break; |
| | | case TypeCode.Char: |
| | | propertyInfo.SetValue(this, (char)Content[index]); |
| | | index += sizeof(char); |
| | | break; |
| | | case TypeCode.Int16: |
| | | propertyInfo.SetValue(this, byteTransform.TransInt16(Content, index)); |
| | | index += sizeof(short); |
| | | break; |
| | | case TypeCode.UInt16: |
| | | propertyInfo.SetValue(this, byteTransform.TransUInt16(Content, index)); |
| | | index += sizeof(ushort); |
| | | break; |
| | | case TypeCode.Single: |
| | | propertyInfo.SetValue(this, byteTransform.TransSingle(Content, index)); |
| | | index += sizeof(float); |
| | | break; |
| | | case TypeCode.Int32: |
| | | propertyInfo.SetValue(this, byteTransform.TransInt32(Content, index)); |
| | | index += sizeof(int); |
| | | break; |
| | | case TypeCode.UInt32: |
| | | propertyInfo.SetValue(this, byteTransform.TransUInt32(Content, index)); |
| | | index += sizeof(uint); |
| | | break; |
| | | case TypeCode.String: |
| | | ushort dataLength = CheckStringAttribute(propertyInfo); |
| | | propertyInfo.SetValue(this, Encoding.Default.GetString(Content, index + 2, Content[index + 1])); |
| | | index += dataLength; |
| | | break; |
| | | default: |
| | | throw new NotSupportedException("Unsupported primitive type: " + propertyInfo.PropertyType); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public byte[] ToSource() |
| | | { |
| | | int propertyValueHasNull = -1; |
| | | List<byte> bytes = new List<byte>(); |
| | | PropertyInfo[] propertyInfos = GetType().GetProperties().Where(x => x.CanWrite).ToArray(); |
| | | foreach (PropertyInfo propertyInfo in propertyInfos) |
| | | { |
| | | object? obj = propertyInfo.GetValue(this); |
| | | if (obj == null && propertyValueHasNull != -1) |
| | | { |
| | | throw new Exception($"{nameof(DeviceCommand)}é误"); |
| | | } |
| | | else |
| | | { |
| | | if (propertyValueHasNull == -1) |
| | | propertyValueHasNull = 2; |
| | | } |
| | | TypeCode typeCode = Type.GetTypeCode(propertyInfo.PropertyType); |
| | | switch (typeCode) |
| | | { |
| | | case TypeCode.Byte: |
| | | case TypeCode.SByte: |
| | | case TypeCode.Char: |
| | | if (obj != null) |
| | | { |
| | | bytes.Add((byte)obj); |
| | | } |
| | | else |
| | | { propertyValueHasNull = 1; } |
| | | break; |
| | | case TypeCode.Int16: |
| | | case TypeCode.UInt16: |
| | | if (obj != null) |
| | | { |
| | | byte[] bytesShort = BitConverter.GetBytes(Convert.ToUInt16(obj)); |
| | | Array.Reverse(bytesShort); |
| | | bytes.AddRange(bytesShort); |
| | | } |
| | | else |
| | | { propertyValueHasNull = 1; } |
| | | break; |
| | | case TypeCode.Single: |
| | | if (obj != null) |
| | | { |
| | | byte[] bytesSingle = BitConverter.GetBytes(Convert.ToSingle(obj)); |
| | | Array.Reverse(bytesSingle); |
| | | bytes.AddRange(bytesSingle); |
| | | } |
| | | else |
| | | { propertyValueHasNull = 1; } |
| | | break; |
| | | case TypeCode.Int32: |
| | | case TypeCode.UInt32: |
| | | if (obj != null) |
| | | { |
| | | byte[] bytesInt = BitConverter.GetBytes(Convert.ToUInt32(obj)); |
| | | Array.Reverse(bytesInt); |
| | | bytes.AddRange(bytesInt); |
| | | } |
| | | else |
| | | { propertyValueHasNull = 1; } |
| | | break; |
| | | case TypeCode.String: |
| | | |
| | | if (obj != null) |
| | | { |
| | | ushort dataLength = CheckStringAttribute(propertyInfo); |
| | | byte[] bytesString = Encoding.Default.GetBytes(obj.ToString()); |
| | | bytes.Add(Convert.ToByte(dataLength)); |
| | | bytes.Add(Convert.ToByte(obj.ToString().Length)); |
| | | bytes.AddRange(bytesString); |
| | | for (int i = 0; i < dataLength - obj.ToString().Length - 2; i++) |
| | | { |
| | | bytes.Add(0); |
| | | } |
| | | } |
| | | else |
| | | { propertyValueHasNull = 1; } |
| | | break; |
| | | default: |
| | | throw new NotSupportedException("Unsupported primitive type: " + propertyInfo.PropertyType); |
| | | } |
| | | } |
| | | |
| | | return bytes.ToArray(); |
| | | } |
| | | #endregion <Public Method> |
| | | |
| | | #region <Event> |
| | | #endregion <Event> |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤ç¶ææä¸¾ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.DeviceBase |
| | | { |
| | | public enum DeviceStatus |
| | | { |
| | | /// <summary> |
| | | /// ç©ºé² |
| | | /// </summary> |
| | | Idle, |
| | | |
| | | /// <summary> |
| | | /// å·¥ä½ä¸ |
| | | /// </summary> |
| | | Working, |
| | | |
| | | /// <summary> |
| | | /// æ
é |
| | | /// </summary> |
| | | Fault, |
| | | |
| | | /// <summary> |
| | | /// æªç¥ |
| | | /// </summary> |
| | | Unkonw, |
| | | |
| | | /// <summary> |
| | | /// 离线 |
| | | /// </summary> |
| | | Offline |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤æ¥å£å±ï¼ææè®¾å¤ç»§æ¿çåºå±æ¥å£ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using HslCommunication; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.DeviceBase |
| | | { |
| | | /// <summary> |
| | | /// è®¾å¤æ¥å£å± |
| | | /// </summary> |
| | | public interface IDevice : IDisposable |
| | | { |
| | | /// <summary> |
| | | /// 设å¤ç¼å· |
| | | /// </summary> |
| | | string DeviceCode { get; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤åç§° |
| | | /// </summary> |
| | | string DeviceName { get; } |
| | | |
| | | /// <summary> |
| | | /// è®¾å¤æ¯å¦ææ
é |
| | | /// </summary> |
| | | bool IsFault { get; } |
| | | |
| | | /// <summary> |
| | | /// è®¾å¤æ¯å¦å·²è¿æ¥ |
| | | /// </summary> |
| | | bool IsConnected { get; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¶æ(空é²/è¿è¡ä¸...) |
| | | /// </summary> |
| | | DeviceStatus Status { get; } |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤å¯ç¨ç¦ç¨ç¶ææä¸¾ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.DeviceEnum |
| | | { |
| | | public enum DeviceStatusEnum |
| | | { |
| | | /// <summary> |
| | | /// ç¦ç¨ |
| | | /// </summary> |
| | | [Description("ç¦ç¨")] |
| | | Disable, |
| | | |
| | | /// <summary> |
| | | /// å¯ç¨ |
| | | /// </summary> |
| | | [Description("å¯ç¨")] |
| | | Enable |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using HslCommunication; |
| | | using Quartz; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob |
| | | { |
| | | public class JobBase |
| | | { |
| | | /// <summary> |
| | | /// æ§è¡æå®ä»»å¡ |
| | | /// </summary> |
| | | /// <param name="context"></param> |
| | | /// <param name="action"></param> |
| | | public async void ExecuteJob(IJobExecutionContext context, Func<Task> func) |
| | | { |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | //JOBID |
| | | int jobid = context.JobDetail.Key.Name.ObjToInt(); |
| | | //JOBç»å |
| | | string groupName = context.JobDetail.Key.Group; |
| | | //æ¥å¿ |
| | | stringBuilder.AppendLine($"ã{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}ããæ§è¡å¼å§ããIdï¼{jobid}ï¼ç»å«ï¼{groupName}ã"); |
| | | try |
| | | { |
| | | await func();//æ§è¡ä»»å¡ |
| | | stringBuilder.AppendLine($"ã{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}ããæ§è¡æåã"); |
| | | |
| | | JobDataMap jobPars = context.JobDetail.JobDataMap; |
| | | stringBuilder.AppendLine(jobPars.GetString("JobParams")); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | JobExecutionException e2 = new JobExecutionException(ex); |
| | | //true æ¯ç«å³éæ°æ§è¡ä»»å¡ |
| | | e2.RefireImmediately = true; |
| | | stringBuilder.AppendLine($"ã{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}ããæ§è¡å¤±è´¥:{ex.Message}ã"); |
| | | stringBuilder.AppendLine($"ãå æ ä¿¡æ¯:{ex.StackTrace}ã"); |
| | | } |
| | | finally |
| | | { |
| | | //QuartzLogger.WriteLogToFile($"Debug_{fileName}", msg); |
| | | } |
| | | } |
| | | |
| | | public void WriteDebug(string fileName, string msg) |
| | | { |
| | | if( AppSettings.app(new string[] { "LogDeubgEnable" }).ObjToBool()) |
| | | { |
| | | StringBuilder builder = new StringBuilder(msg); |
| | | builder.Append(Environment.NewLine); |
| | | builder.Append(Environment.NewLine); |
| | | QuartzLogger.WriteLogToFile($"Debug_{fileName}", builder.ToString()); |
| | | } |
| | | } |
| | | |
| | | public void WriteInfo(string fileName, string msg) |
| | | { |
| | | StringBuilder builder = new StringBuilder(msg); |
| | | builder.Append(Environment.NewLine); |
| | | builder.Append(Environment.NewLine); |
| | | QuartzLogger.WriteLogToFile($"Info_{fileName}", builder.ToString()); |
| | | } |
| | | |
| | | public void WriteError(string fileName, string msg, Exception ex) |
| | | { |
| | | StringBuilder builder = new StringBuilder(msg); |
| | | builder.Append(Environment.NewLine); |
| | | builder.Append(StringResources.Language.ExceptionMessage); |
| | | builder.Append(ex.Message); |
| | | builder.Append(Environment.NewLine); |
| | | builder.Append(StringResources.Language.ExceptionSource); |
| | | builder.Append(ex.Source); |
| | | builder.Append(Environment.NewLine); |
| | | builder.Append(StringResources.Language.ExceptionStackTrace); |
| | | builder.Append(ex.StackTrace); |
| | | builder.Append(Environment.NewLine); |
| | | builder.Append(StringResources.Language.ExceptionType); |
| | | builder.Append(ex.GetType().ToString()); |
| | | builder.Append(Environment.NewLine); |
| | | builder.Append(StringResources.Language.ExceptionTargetSite); |
| | | builder.Append(ex.TargetSite?.ToString()); |
| | | builder.Append(Environment.NewLine); |
| | | builder.Append(Environment.NewLine); |
| | | QuartzLogger.WriteLogToFile($"Error_{fileName}", builder.ToString()); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤ä¿¡æ¯å®ä½ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.DB.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Models |
| | | { |
| | | /// <summary> |
| | | /// 设å¤ä¿¡æ¯ |
| | | /// </summary> |
| | | [SugarTable(nameof(Dt_DeviceInfo), "设å¤ä¿¡æ¯")] |
| | | public class Dt_DeviceInfo : BaseEntity |
| | | { |
| | | /// <summary> |
| | | /// ä¸»é® |
| | | /// </summary> |
| | | [ImporterHeader(IsIgnore = true)] |
| | | [ExporterHeader(DisplayName = "主é®")] |
| | | [SugarColumn(IsIdentity = true, IsNullable = true, IsPrimaryKey = true, ColumnDescription = "主é®")] |
| | | public int Id { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¼å· |
| | | /// </summary> |
| | | [ImporterHeader(Name = "设å¤ç¼å·")] |
| | | [ExporterHeader(DisplayName = "设å¤ç¼å·")] |
| | | [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "设å¤ç¼å·")] |
| | | public string DeviceCode { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤åç§° |
| | | /// </summary> |
| | | [ImporterHeader(Name = "设å¤åç§°")] |
| | | [ExporterHeader(DisplayName = "设å¤åç§°")] |
| | | [SugarColumn(IsNullable = true, Length = 50, ColumnDescription = "设å¤åç§°")] |
| | | public string DeviceName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç±»å |
| | | /// </summary> |
| | | [ImporterHeader(Name = "设å¤ç±»å")] |
| | | [ExporterHeader(DisplayName = "设å¤ç±»å")] |
| | | [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "设å¤ç±»å")] |
| | | public string DeviceType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç¶æ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "设å¤ç¶æ")] |
| | | [ExporterHeader(DisplayName = "设å¤ç¶æ")] |
| | | [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "设å¤ç¶æ")] |
| | | public string DeviceStatus { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤IP |
| | | /// </summary> |
| | | [ImporterHeader(Name = "设å¤IP")] |
| | | [ExporterHeader(DisplayName = "设å¤IP")] |
| | | [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "设å¤IP")] |
| | | public string DeviceIp { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç«¯å£ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "设å¤ç«¯å£")] |
| | | [ExporterHeader(DisplayName = "设å¤ç«¯å£")] |
| | | [SugarColumn(IsNullable = true, ColumnDescription = "设å¤ç«¯å£")] |
| | | public int DevicePort { get; set; } |
| | | |
| | | /// <summary> |
| | | /// PLCç±»å |
| | | /// </summary> |
| | | [ImporterHeader(Name = "PLCç±»å")] |
| | | [ExporterHeader(DisplayName = "PLCç±»å")] |
| | | [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "PLCç±»å")] |
| | | public string DevicePlcType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 夿³¨ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "夿³¨")] |
| | | [ExporterHeader(DisplayName = "夿³¨")] |
| | | [SugarColumn(Length = 200, IsNullable = true, ColumnDescription = "夿³¨")] |
| | | public string DeviceRemark { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤åè®®éå |
| | | /// </summary> |
| | | [ImporterHeader(IsIgnore =true)] |
| | | [ExporterHeader(IsIgnore = true)] |
| | | [Navigate(NavigateType.OneToMany, nameof(Dt_DeviceProtocol.DeviceId), nameof(Id)), SugarColumn(IsIgnore = true, IsNullable = true)] |
| | | public List<Dt_DeviceProtocol> ProtocolList { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤åè®®å®ä½ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.DB.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Models |
| | | { |
| | | /// <summary> |
| | | /// 设å¤åè®® |
| | | /// </summary> |
| | | [SugarTable(nameof(Dt_DeviceProtocol), "设å¤åè®®")] |
| | | public class Dt_DeviceProtocol : BaseEntity |
| | | { |
| | | /// <summary> |
| | | /// ä¸»é® |
| | | /// </summary> |
| | | [ImporterHeader(IsIgnore = true)] |
| | | [ExporterHeader(IsIgnore = true)] |
| | | [SugarColumn(IsIdentity = true, IsNullable = true, IsPrimaryKey = true, ColumnDescription = "主é®")] |
| | | public int Id { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤ä¸»é® |
| | | /// </summary> |
| | | [ImporterHeader(IsIgnore = true)] |
| | | [ExporterHeader(IsIgnore = true)] |
| | | [SugarColumn(IsNullable = false, ColumnDescription = "设å¤ä¸»é®")] |
| | | public int DeviceId { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤åç¼å· |
| | | /// </summary> |
| | | [ImporterHeader(Name = "设å¤åç¼å·")] |
| | | [ExporterHeader(DisplayName = "设å¤åç¼å·")] |
| | | [SugarColumn(IsNullable = true, Length = 20, ColumnDescription = "设å¤åç¼å·")] |
| | | public string DeviceChildCode { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åè®®æ°æ®å |
| | | /// </summary> |
| | | [ImporterHeader(Name = "åè®®æ°æ®å")] |
| | | [ExporterHeader(DisplayName = "åè®®æ°æ®å")] |
| | | [SugarColumn(IsNullable = true, Length = 10, ColumnDescription = "åè®®æ°æ®å")] |
| | | public string DeviceProDataBlock { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åç§»é |
| | | /// </summary> |
| | | [ImporterHeader(Name = "åç§»é")] |
| | | [ExporterHeader(DisplayName = "åç§»é")] |
| | | [SugarColumn(IsNullable = true, DecimalDigits = 1, ColumnDescription = "åç§»é")] |
| | | public decimal DeviceProOffset { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ°æ®ç±»å |
| | | /// </summary> |
| | | [ImporterHeader(Name = "æ°æ®ç±»å")] |
| | | [ExporterHeader(DisplayName = "æ°æ®ç±»å")] |
| | | [SugarColumn(IsNullable = true, Length = 10, ColumnDescription = "æ°æ®ç±»å")] |
| | | public string DeviceProDataType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ°æ®é¿åº¦ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "æ°æ®é¿åº¦")] |
| | | [ExporterHeader(DisplayName = "æ°æ®é¿åº¦")] |
| | | [SugarColumn(IsNullable = false, ColumnDescription = "æ°æ®é¿åº¦", DefaultValue = "1")] |
| | | public int DeviceProDataLength { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åæ°åç§° |
| | | /// </summary> |
| | | [ImporterHeader(Name = "åæ°åç§°")] |
| | | [ExporterHeader(DisplayName = "åæ°åç§°")] |
| | | [SugarColumn(IsNullable = true, Length = 50, ColumnDescription = "åæ°åç§°")] |
| | | public string DeviceProParamName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åæ°ç±»å |
| | | /// </summary> |
| | | [ImporterHeader(Name = "åæ°ç±»å")] |
| | | [ExporterHeader(DisplayName = "åæ°ç±»å")] |
| | | [SugarColumn(IsNullable = true, Length = 50, ColumnDescription = "åæ°ç±»å")] |
| | | public string DeviceProParamType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åæ°è¯´æ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "åæ°è¯´æ")] |
| | | [ExporterHeader(DisplayName = "åæ°è¯´æ")] |
| | | [SugarColumn(IsNullable = true, Length = 50, ColumnDescription = "åæ°è¯´æ")] |
| | | public string DeviceProParamDes { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 夿³¨ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "夿³¨")] |
| | | [ExporterHeader(DisplayName = "夿³¨")] |
| | | [SugarColumn(IsNullable = true, Length = 200, ColumnDescription = "夿³¨")] |
| | | public string DeviceProRemark { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤åè®®æç»å®ä½ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.DB.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Models |
| | | { |
| | | /// <summary> |
| | | /// 设å¤åè®®æç» |
| | | /// </summary> |
| | | [SugarTable(nameof(Dt_DeviceProtocolDetail), "设å¤åè®®æç»")] |
| | | public class Dt_DeviceProtocolDetail : BaseEntity |
| | | { |
| | | /// <summary> |
| | | /// ä¸»é® |
| | | /// </summary> |
| | | [ImporterHeader(Name = "主é®")] |
| | | [ExporterHeader(DisplayName = "主é®")] |
| | | [SugarColumn(IsIdentity = true, IsNullable = true, IsPrimaryKey = true, ColumnDescription = "主é®")] |
| | | public int Id { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤ç±»å |
| | | /// </summary> |
| | | [ImporterHeader(Name = "设å¤ç±»å")] |
| | | [ExporterHeader(DisplayName = "设å¤ç±»å")] |
| | | [SugarColumn(IsNullable = false, Length = 20, ColumnDescription = "设å¤ç±»å")] |
| | | public string DeviceType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤åè®®åæ°åç§° |
| | | /// </summary> |
| | | [ImporterHeader(Name = "设å¤åè®®åæ°åç§°")] |
| | | [ExporterHeader(DisplayName = "设å¤åè®®åæ°åç§°")] |
| | | [SugarColumn(IsNullable = false, ColumnDescription = "设å¤åè®®åæ°åç§°")] |
| | | public string DeviceProParamName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤åè®®æç»ç±»å |
| | | /// </summary> |
| | | [ImporterHeader(Name = "设å¤åè®®æç»ç±»å")] |
| | | [ExporterHeader(DisplayName = "设å¤åè®®æç»ç±»å")] |
| | | [SugarColumn(Length = 50, ColumnDescription = "设å¤åè®®æç»ç±»å")] |
| | | public string ProtocolDetailType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤åè®®æç»åå¼ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "设å¤åè®®æç»åå¼")] |
| | | [ExporterHeader(DisplayName = "设å¤åè®®æç»åå¼")] |
| | | [SugarColumn(Length = 50, IsNullable = false, ColumnDescription = "设å¤åè®®æç»åå¼")] |
| | | public string ProtocalDetailValue { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 设å¤åè®®æç»è¯´æ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "设å¤åè®®æç»è¯´æ")] |
| | | [ExporterHeader(DisplayName = "设å¤åè®®æç»è¯´æ")] |
| | | [SugarColumn(IsNullable = true, Length = 500, ColumnDescription = "设å¤åè®®æç»è¯´æ")] |
| | | public string ProtocolDetailDes { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 夿³¨ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "夿³¨")] |
| | | [ExporterHeader(DisplayName = "夿³¨")] |
| | | [SugarColumn(IsNullable = true, Length = 200, ColumnDescription = "夿³¨")] |
| | | public string Remark { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è°åº¦æå¡é
ç½®å®ä½ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.DB.Models; |
| | | using WIDESEAWCS_Core.Tenants; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Models |
| | | { |
| | | /// <summary> |
| | | /// è°åº¦æå¡é
ç½® |
| | | /// </summary> |
| | | [SugarTable(nameof(Dt_DispatchInfo), "è°åº¦æå¡é
ç½®")] |
| | | public class Dt_DispatchInfo : BaseEntity |
| | | { |
| | | /// <summary> |
| | | /// ä¸»é® |
| | | /// </summary> |
| | | [ImporterHeader(Name = "主é®")] |
| | | [ExporterHeader(DisplayName = "主é®")] |
| | | [SugarColumn(IsIdentity = true, IsNullable = true, IsPrimaryKey = true, ColumnDescription = "主é®")] |
| | | public int Id { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡åç§° |
| | | /// </summary> |
| | | [ImporterHeader(Name = "ä»»å¡åç§°")] |
| | | [ExporterHeader(DisplayName = "ä»»å¡åç§°")] |
| | | [SugarColumn(Length = 50, IsNullable = false, ColumnDescription = "ä»»å¡åç§°")] |
| | | public string Name { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡åç» |
| | | /// </summary> |
| | | [ImporterHeader(Name = "ä»»å¡åç»")] |
| | | [ExporterHeader(DisplayName = "ä»»å¡åç»")] |
| | | [SugarColumn(Length = 50, IsNullable = false, ColumnDescription = "ä»»å¡åç»")] |
| | | public string JobGroup { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 任塿å¨DLL对åºçç¨åºéåç§° |
| | | /// </summary> |
| | | [ImporterHeader(Name = "ç¨åºéåç§°")] |
| | | [ExporterHeader(DisplayName = "ç¨åºéåç§°")] |
| | | [SugarColumn(Length = 50, IsNullable = false, ColumnDescription = "任塿å¨DLL对åºçç¨åºéåç§°")] |
| | | public string AssemblyName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 任塿å¨ç±» |
| | | /// </summary> |
| | | [ImporterHeader(Name = "任塿å¨ç±»")] |
| | | [ExporterHeader(DisplayName = "任塿å¨ç±»")] |
| | | [SugarColumn(Length = 50, IsNullable = false, ColumnDescription = "任塿å¨ç±»")] |
| | | public string ClassName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ§è¡é´éæ¶é´, ç§ä¸ºåä½ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "æ§è¡é´éæ¶é´")] |
| | | [ExporterHeader(DisplayName = "æ§è¡é´éæ¶é´")] |
| | | [SugarColumn(IsNullable = false, ColumnDescription = "æ§è¡é´éæ¶é´")] |
| | | public int IntervalSecond { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å¼å§æ¶é´ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "å¼å§æ¶é´")] |
| | | [ExporterHeader(DisplayName = "å¼å§æ¶é´")] |
| | | [SugarColumn(IsNullable = true, ColumnDescription = "å¼å§æ¶é´")] |
| | | public DateTime? BeginTime { get; set; } |
| | | /// <summary> |
| | | /// ç»ææ¶é´ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "ç»ææ¶é´")] |
| | | [ExporterHeader(DisplayName = "ç»ææ¶é´")] |
| | | [SugarColumn(IsNullable = true, ColumnDescription = "ç»ææ¶é´")] |
| | | public DateTime? EndTime { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡æè¿° |
| | | /// </summary> |
| | | [ImporterHeader(Name = "ä»»å¡æè¿°")] |
| | | [ExporterHeader(DisplayName = "ä»»å¡æè¿°")] |
| | | [SugarColumn(Length = 1000, IsNullable = true, ColumnDescription = "ä»»å¡æè¿°")] |
| | | public string Remark { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Magicodes.ExporterAndImporter.Core; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.DB.Models; |
| | | using WIDESEAWCS_Core.Enums; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Models |
| | | { |
| | | [SugarTable(nameof(Dt_Router), "设å¤è·¯ç±é
ç½®")] |
| | | public class Dt_Router : BaseEntity |
| | | { |
| | | /// <summary> |
| | | /// ä¸»é® |
| | | /// </summary> |
| | | [ImporterHeader(Name = "主é®")] |
| | | [ExporterHeader(DisplayName = "主é®")] |
| | | [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnDescription = "主é®")] |
| | | public int Id { get; set; } |
| | | |
| | | /// <summary> |
| | | /// èµ·ç¹ä½ç½® |
| | | /// </summary> |
| | | [ImporterHeader(Name = "èµ·ç¹ä½ç½®")] |
| | | [ExporterHeader(DisplayName = "èµ·ç¹ä½ç½®")] |
| | | [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "èµ·ç¹ä½ç½®")] |
| | | public string StartPosi { get; set; } |
| | | |
| | | /// <summary> |
| | | /// ç»ç¹ä½ç½® |
| | | /// </summary> |
| | | [ImporterHeader(Name = "ç»ç¹ä½ç½®")] |
| | | [ExporterHeader(DisplayName = "ç»ç¹ä½ç½®")] |
| | | [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "ç»ç¹ä½ç½®")] |
| | | public string NextPosi { get; set; } |
| | | |
| | | /// <summary> |
| | | /// è·¯ç±ç±»å |
| | | /// </summary> |
| | | [ImporterHeader(Name = "è·¯ç±ç±»å")] |
| | | [ExporterHeader(DisplayName = "è·¯ç±ç±»å")] |
| | | [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "è·¯ç±ç±»å")] |
| | | public RouterInOutType InOutType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åä½ç½® |
| | | /// </summary> |
| | | [ImporterHeader(Name = "åä½ç½®")] |
| | | [ExporterHeader(DisplayName = "åä½ç½®")] |
| | | [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "åä½ç½®")] |
| | | public string ChildPosi { get; set; } |
| | | |
| | | /// <summary> |
| | | /// åä½ç½®æå±è®¾å¤ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "åä½ç½®æå±è®¾å¤")] |
| | | [ExporterHeader(DisplayName = "åä½ç½®æå±è®¾å¤")] |
| | | [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "åä½ç½®æå±è®¾å¤")] |
| | | public string ChildPosiDeviceCode { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å åæºåè´§/æ¾è´§è¡ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "å åæºåè´§/æ¾è´§è¡")] |
| | | [ExporterHeader(DisplayName = "å åæºåè´§/æ¾è´§è¡")] |
| | | [SugarColumn(IsNullable = true, ColumnDescription = "å åæºåè´§/æ¾è´§è¡")] |
| | | public int? SrmRow { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å åæºåè´§/æ¾è´§å |
| | | /// </summary> |
| | | [ImporterHeader(Name = "å åæºåè´§/æ¾è´§å")] |
| | | [ExporterHeader(DisplayName = "å åæºåè´§/æ¾è´§å")] |
| | | [SugarColumn(IsNullable = true, ColumnDescription = "å åæºåè´§/æ¾è´§å")] |
| | | public int? SrmColumn { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å åæºåè´§/æ¾è´§å± |
| | | /// </summary> |
| | | [ImporterHeader(Name = "å åæºåè´§/æ¾è´§å±")] |
| | | [ExporterHeader(DisplayName = "å åæºåè´§/æ¾è´§å±")] |
| | | [SugarColumn(IsNullable = true, ColumnDescription = "å åæºåè´§/æ¾è´§å±")] |
| | | public int? SrmLayer { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 深度 |
| | | /// </summary> |
| | | [ImporterHeader(Name = "深度")] |
| | | [ExporterHeader(DisplayName = "深度")] |
| | | [SugarColumn(IsNullable = true, ColumnDescription = "深度")] |
| | | public int? Depth { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ¯å¦æ¯æç»ç¹ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "æ¯å¦æ¯æç»ç¹")] |
| | | [ExporterHeader(DisplayName = "æ¯å¦æ¯æç»ç¹")] |
| | | [SugarColumn(IsNullable = false, ColumnDescription = "æ¯å¦æ¯æç»ç¹")] |
| | | public bool IsEnd { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 夿³¨ |
| | | /// </summary> |
| | | [ImporterHeader(Name = "夿³¨")] |
| | | [ExporterHeader(DisplayName = "夿³¨")] |
| | | [SugarColumn(IsNullable = true, ColumnDescription = "夿³¨")] |
| | | public string Remark { get; set; } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è°åº¦æå¡æ³¨å
¥ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Quartz.Spi; |
| | | using Quartz; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.QuartzExtensions |
| | | { |
| | | /// <summary> |
| | | /// è°åº¦æå¡æ³¨å
¥ |
| | | /// </summary> |
| | | public static class JobSetup |
| | | { |
| | | public static void AddJobSetup(this IServiceCollection services) |
| | | { |
| | | if (services == null) throw new ArgumentNullException(nameof(services)); |
| | | |
| | | services.AddSingleton<IJobFactory, JobFactory>(); |
| | | services.AddSingleton<ISchedulerCenter, SchedulerCenterServer>(); |
| | | //任塿³¨å
¥ |
| | | var baseType = typeof(IJob); |
| | | var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; |
| | | var referencedAssemblies = System.IO.Directory.GetFiles(path, "WIDESEAWCS_Tasks.dll").Select(Assembly.LoadFrom).ToArray(); |
| | | var types = referencedAssemblies |
| | | .SelectMany(a => a.DefinedTypes) |
| | | .Select(type => type.AsType()) |
| | | .Where(x => x != baseType && baseType.IsAssignableFrom(x)).ToArray(); |
| | | var implementTypes = types.Where(x => x.IsClass).ToArray(); |
| | | foreach (var implementType in implementTypes) |
| | | { |
| | | services.AddTransient(implementType); |
| | | } |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è°åº¦æå¡ä»å¨ä¸å¡å±æ³¨å
¥ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Autofac; |
| | | using Autofac.Extras.DynamicProxy; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.AOP; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.QuartzExtensions |
| | | { |
| | | public class QuartzJobAutofacModuleRegister : Autofac.Module |
| | | { |
| | | protected override void Load(ContainerBuilder builder) |
| | | { |
| | | var basePath = AppContext.BaseDirectory; |
| | | |
| | | #region å¸¦ææ¥å£å±çæå¡æ³¨å
¥ |
| | | |
| | | var dllFile = Path.Combine(basePath, "WIDESEAWCS_QuartzJob.dll"); |
| | | |
| | | if (!File.Exists(dllFile)) |
| | | { |
| | | var msg = "WIDESEAWCS_QuartzJob.dll 丢失ï¼å 为项ç®è§£è¦äºï¼æä»¥éè¦å
F6ç¼è¯ï¼åF5è¿è¡ï¼è¯·æ£æ¥ bin æä»¶å¤¹ï¼å¹¶æ·è´ã"; |
| | | //log.Error(msg); |
| | | throw new Exception(msg); |
| | | } |
| | | Type baseType = typeof(IDependency); |
| | | //builder.RegisterGeneric(typeof(RepositoryBase<>)).As(typeof(IRepository<>)).InstancePerDependency();//注åä»å¨ |
| | | //builder.RegisterGeneric(typeof(ServiceBase<,>)).As(typeof(IService<>)).InstancePerDependency();//注åæå¡ |
| | | |
| | | // è·å Service.dll ç¨åºéæå¡ï¼å¹¶æ³¨å |
| | | Assembly assemblysServices = Assembly.LoadFrom(dllFile); |
| | | builder.RegisterAssemblyTypes(assemblysServices).Where(type => (baseType.IsAssignableFrom(type)) && !type.IsAbstract) |
| | | .AsSelf().AsImplementedInterfaces() |
| | | .InstancePerLifetimeScope(); //å¼ç¨Autofac.Extras.DynamicProxy; |
| | | #endregion |
| | | |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è°åº¦æå¡å±å®ä½æ å° |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Microsoft.Extensions.Logging; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.Seed; |
| | | using WIDESEAWCS_Core; |
| | | using Microsoft.AspNetCore.Hosting; |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Microsoft.Extensions.Hosting; |
| | | using WIDESEAWCS_QuartzJob.Seed; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.QuartzExtensions |
| | | { |
| | | public sealed class QuartzJobDataTableHostedService : IHostedService |
| | | { |
| | | private readonly DBContext _dbContext; |
| | | private readonly ILogger<QuartzJobDataTableHostedService> _logger; |
| | | private readonly string _webRootPath; |
| | | private readonly IServiceProvider _serviceProvider; |
| | | |
| | | public QuartzJobDataTableHostedService( |
| | | IServiceProvider serviceProvider, |
| | | IWebHostEnvironment webHostEnvironment, |
| | | ILogger<QuartzJobDataTableHostedService> logger) |
| | | { |
| | | _serviceProvider = serviceProvider; |
| | | _logger = logger; |
| | | _webRootPath = webHostEnvironment.WebRootPath; |
| | | using var scope = _serviceProvider.CreateScope(); |
| | | DBContext dbContext = scope.ServiceProvider.GetService<DBContext>(); |
| | | _dbContext = dbContext; |
| | | } |
| | | |
| | | public async Task StartAsync(CancellationToken cancellationToken) |
| | | { |
| | | _logger.LogInformation("å¼å§åå»ºå®æ¶å¨è°åº¦æ°æ®è¡¨"); |
| | | await DoWork(); |
| | | } |
| | | |
| | | private async Task DoWork() |
| | | { |
| | | try |
| | | { |
| | | await QuartzJobCreateDataTabel.SeedAsync(_dbContext, _webRootPath); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogError(ex, "宿¶å¨è°åº¦æ°æ®è¡¨å建é误"); |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | public Task StopAsync(CancellationToken cancellationToken) |
| | | { |
| | | _logger.LogInformation("宿¶å¨è°åº¦æ°æ®è¡¨ç»æ"); |
| | | return Task.CompletedTask; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è°åº¦æå¡èªå¨å¼å¯ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Microsoft.Extensions.Hosting; |
| | | using Microsoft.Extensions.Logging; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.QuartzExtensions |
| | | { |
| | | public class QuartzJobHostedService : IHostedService |
| | | { |
| | | private readonly ISchedulerCenter _schedulerCenter; |
| | | private readonly ILogger<QuartzJobHostedService> _logger; |
| | | private readonly IDeviceInfoService _deviceInfoService; |
| | | private readonly IDispatchInfoService _dispatchInfoService; |
| | | private readonly IDeviceProtocolDetailService _deviceProtocolDetailService; |
| | | |
| | | public QuartzJobHostedService(ILogger<QuartzJobHostedService> logger, IDeviceInfoService deviceInfoService, IDispatchInfoService dispatchInfoService, ISchedulerCenter schedulerCenter, IDeviceProtocolDetailService deviceProtocolDetailService) |
| | | { |
| | | _logger = logger; |
| | | _deviceInfoService = deviceInfoService; |
| | | _dispatchInfoService = dispatchInfoService; |
| | | _schedulerCenter = schedulerCenter; |
| | | _deviceProtocolDetailService = deviceProtocolDetailService; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¯å¨ç¨åºèªå¨å¼å¯è°åº¦æå¡ |
| | | /// </summary> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public async Task StartAsync(CancellationToken cancellationToken) |
| | | { |
| | | try |
| | | { |
| | | List<DispatchInfoDTO> dispatches = _dispatchInfoService.QueryDispatchInfos(); |
| | | List<DeviceInfoDTO> deviceInfos = await _deviceInfoService.QueryDeviceProInfos(); |
| | | |
| | | deviceInfos.ForEach(x => |
| | | { |
| | | if (dispatches.Exists(d => d.JobGroup == x.DeviceType)) |
| | | { |
| | | #region è¿æ¥PLC |
| | | Assembly assembly = Assembly.Load($"WIDESEAWCS_Communicator"); |
| | | Type? type = assembly.GetType($"WIDESEAWCS_Communicator.{x.DevicePlcType}"); |
| | | object? obj = Activator.CreateInstance(type, new object[] { x.DeviceIp, x.DevicePort, x.DeviceName }); |
| | | bool? connectResult = (bool)type.InvokeMember("Connect", BindingFlags.Default | BindingFlags.InvokeMethod, null, obj, new object[] { }); |
| | | if (connectResult ?? false) ConsoleHelper.WriteSuccessLine(x.DeviceCode + "è¿æ¥æå"); else ConsoleHelper.WriteErrorLine(x.DeviceCode + "è¿æ¥å¤±è´¥"); |
| | | |
| | | #endregion |
| | | |
| | | #region å®ä¾å设å¤å¯¹è±¡ |
| | | |
| | | List<DeviceProDTO> devicePros = x.ProtocolList.Select(d => new DeviceProDTO |
| | | { |
| | | DeviceChildCode = d.DeviceChildCode, |
| | | DeviceDataType = d.DeviceProDataType, |
| | | DeviceId = d.DeviceId, |
| | | DeviceProId = d.Id, |
| | | DeviceProDataBlock = d.DeviceProDataBlock, |
| | | DeviceProDataLength = d.DeviceProDataLength, |
| | | DeviceProOffset = d.DeviceProOffset, |
| | | DeviceProParamDes = d.DeviceProParamDes, |
| | | DeviceProParamName = d.DeviceProParamName, |
| | | DeviceProParamType = d.DeviceProParamType, |
| | | }).ToList(); |
| | | |
| | | List<DeviceProtocolDetailDTO> deviceProtocolDetails = _deviceProtocolDetailService.GetDeviceProtocolDetailsByDeviceType(x.DeviceType); |
| | | |
| | | Assembly assemblyDevice = Assembly.Load($"WIDESEAWCS_QuartzJob"); |
| | | Type typeDevice = assemblyDevice.GetType($"WIDESEAWCS_QuartzJob.{x.DeviceType}"); |
| | | object deviceInstance = Activator.CreateInstance(typeDevice, new object[] { obj, devicePros, deviceProtocolDetails, x.DeviceCode, x.DeviceName }); |
| | | #endregion |
| | | |
| | | x.Device = (IDevice)deviceInstance; |
| | | |
| | | Storage.Devices.Add((IDevice)deviceInstance); |
| | | } |
| | | }); |
| | | for (int i = 0; i < dispatches.Count; i++) |
| | | { |
| | | DeviceInfoDTO? deviceProInfo = deviceInfos.FirstOrDefault(x => x.Id == dispatches[i].Id); |
| | | dispatches[i].JobParams = deviceProInfo?.Device; |
| | | WebResponseContent responseContent = await _schedulerCenter.AddScheduleJobAsync(dispatches[i]); |
| | | if (responseContent.Status) ConsoleHelper.WriteSuccessLine(dispatches[i].JobGroup + "è°åº¦æå¡æ·»å æå"); else ConsoleHelper.WriteErrorLine(dispatches[i].JobGroup + "è°åº¦æå¡æ·»å 失败"); |
| | | } |
| | | await _schedulerCenter.StartScheduleAsync(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogError(ex, "è°åº¦æå¡å¼å¯å¼å¸¸"); |
| | | Console.WriteLine("è°åº¦æå¡å¼å¯å¼å¸¸" + ex.ToString()); |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | public Task StopAsync(CancellationToken cancellationToken) |
| | | { |
| | | _logger.LogInformation("Stop QuartzJob Service!"); |
| | | return Task.CompletedTask; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è°åº¦æå¡æ¥å£å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob |
| | | { |
| | | /// <summary> |
| | | /// è°åº¦æå¡æ¥å£ |
| | | /// </summary> |
| | | public interface ISchedulerCenter |
| | | { |
| | | |
| | | /// <summary> |
| | | /// å¼å¯ä»»å¡è°åº¦ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | Task<WebResponseContent> StartScheduleAsync(); |
| | | |
| | | /// <summary> |
| | | /// 忢任å¡è°åº¦ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | Task<WebResponseContent> StopScheduleAsync(); |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="sysSchedule"></param> |
| | | /// <returns></returns> |
| | | Task<WebResponseContent> AddScheduleJobAsync(DispatchInfoDTO sysSchedule); |
| | | |
| | | /// <summary> |
| | | /// 忢ä¸ä¸ªä»»å¡ |
| | | /// </summary> |
| | | /// <param name="sysSchedule"></param> |
| | | /// <returns></returns> |
| | | Task<WebResponseContent> StopScheduleJobAsync(DispatchInfoDTO sysSchedule); |
| | | |
| | | /// <summary> |
| | | /// æ£æµä»»å¡æ¯å¦åå¨ |
| | | /// </summary> |
| | | /// <param name="sysSchedule"></param> |
| | | /// <returns></returns> |
| | | Task<bool> IsExistScheduleJobAsync(DispatchInfoDTO sysSchedule); |
| | | |
| | | /// <summary> |
| | | /// æåæå®ç计åä»»å¡ |
| | | /// </summary> |
| | | /// <param name="sysSchedule"></param> |
| | | /// <returns></returns> |
| | | Task<WebResponseContent> PauseJob(DispatchInfoDTO sysSchedule); |
| | | |
| | | /// <summary> |
| | | /// æ¢å¤ä¸ä¸ªä»»å¡ |
| | | /// </summary> |
| | | /// <param name="sysSchedule"></param> |
| | | /// <returns></returns> |
| | | Task<WebResponseContent> ResumeJob(DispatchInfoDTO sysSchedule); |
| | | |
| | | /// <summary> |
| | | /// è·åä»»å¡è§¦åå¨ç¶æ |
| | | /// </summary> |
| | | /// <param name="sysSchedule"></param> |
| | | /// <returns></returns> |
| | | //Task<List<DispatchInfoDTO>> GetTaskStaus(DispatchInfoDTO sysSchedule); |
| | | |
| | | /// <summary> |
| | | /// è·å触å卿 è¯ |
| | | /// </summary> |
| | | /// <param name="key"></param> |
| | | /// <returns></returns> |
| | | string GetTriggerState(string key); |
| | | |
| | | /// <summary> |
| | | /// ç«å³æ§è¡ ä¸ä¸ªä»»å¡ |
| | | /// </summary> |
| | | /// <param name="tasksQz"></param> |
| | | /// <returns></returns> |
| | | Task<WebResponseContent> ExecuteJobAsync(DispatchInfoDTO tasksQz); |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼Jobå·¥åç±» |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Quartz.Spi; |
| | | using Quartz; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob |
| | | { |
| | | public class JobFactory : IJobFactory |
| | | { |
| | | /// <summary> |
| | | /// 注å
¥åå°è·åä¾èµå¯¹è±¡ |
| | | /// </summary> |
| | | private readonly IServiceProvider _serviceProvider; |
| | | public JobFactory(IServiceProvider serviceProvider) |
| | | { |
| | | _serviceProvider = serviceProvider; |
| | | } |
| | | /// <summary> |
| | | /// å®ç°æ¥å£Job |
| | | /// </summary> |
| | | /// <param name="bundle"></param> |
| | | /// <param name="scheduler"></param> |
| | | /// <returns></returns> |
| | | public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) |
| | | { |
| | | try |
| | | { |
| | | IServiceScope serviceScope = _serviceProvider.CreateScope(); |
| | | IJob? job = serviceScope.ServiceProvider.GetService(bundle.JobDetail.JobType) as IJob; |
| | | return job; |
| | | } |
| | | catch (Exception) |
| | | { |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | public void ReturnJob(IJob job) |
| | | { |
| | | IDisposable? disposable = job as IDisposable; |
| | | disposable?.Dispose(); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è°åº¦æå¡å®ç°ç±» |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Quartz.Impl.Triggers; |
| | | using Quartz.Impl; |
| | | using Quartz.Spi; |
| | | using Quartz; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Collections.Specialized; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.CustomException; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob |
| | | { |
| | | public class SchedulerCenterServer : ISchedulerCenter |
| | | { |
| | | private Task<IScheduler> _scheduler; |
| | | private readonly IJobFactory _iocjobFactory; |
| | | public SchedulerCenterServer(IJobFactory jobFactory) |
| | | { |
| | | _iocjobFactory = jobFactory; |
| | | _scheduler = GetSchedulerAsync(); |
| | | } |
| | | private Task<IScheduler> GetSchedulerAsync() |
| | | { |
| | | if (_scheduler != null) |
| | | return this._scheduler; |
| | | else |
| | | { |
| | | try |
| | | { |
| | | // ä»Factoryä¸è·åSchedulerå®ä¾ |
| | | NameValueCollection collection = new NameValueCollection |
| | | { |
| | | { "quartz.serializer.type", "binary" }, |
| | | }; |
| | | StdSchedulerFactory factory = new StdSchedulerFactory(collection); |
| | | return _scheduler = factory.GetScheduler(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new QuartzJobException(string.Format(QuartzJobExceptionMessage.JobFactoryInstanceException, ex.Message), innerException: ex); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¼å¯ä»»å¡è°åº¦ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> StartScheduleAsync() |
| | | { |
| | | WebResponseContent result = new WebResponseContent(); |
| | | try |
| | | { |
| | | this._scheduler.Result.JobFactory = this._iocjobFactory; |
| | | if (!this._scheduler.Result.IsStarted) |
| | | { |
| | | //çå¾
ä»»å¡è¿è¡å®æ |
| | | await this._scheduler.Result.Start(); |
| | | await Console.Out.WriteLineAsync(QuartzJobInfoMessage.StartJobSuccess); |
| | | result = WebResponseContent.Instance.OK(QuartzJobInfoMessage.StartJobSuccess); |
| | | return result; |
| | | } |
| | | else |
| | | { |
| | | result = WebResponseContent.Instance.Error(QuartzJobInfoMessage.JobHasStart); |
| | | return result; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new QuartzJobException(string.Format(QuartzJobExceptionMessage.StartJobException, ex.Message), innerException: ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 忢任å¡è°åº¦ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> StopScheduleAsync() |
| | | { |
| | | WebResponseContent result = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (!this._scheduler.Result.IsShutdown) |
| | | { |
| | | //çå¾
ä»»å¡è¿è¡å®æ |
| | | await this._scheduler.Result.Shutdown(); |
| | | await Console.Out.WriteLineAsync(QuartzJobInfoMessage.StopJobSuccess); |
| | | result = WebResponseContent.Instance.OK(QuartzJobInfoMessage.StopJobSuccess); |
| | | return result; |
| | | } |
| | | else |
| | | { |
| | | result = WebResponseContent.Instance.Error(QuartzJobInfoMessage.JobHasStop); |
| | | return result; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new QuartzJobException(string.Format(QuartzJobExceptionMessage.StopJobException, ex.Message), innerException: ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ·»å ä¸ä¸ªè®¡åä»»å¡ï¼æ å°ç¨åºéæå®IJobå®ç°ç±»ï¼ |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="tasksQz"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> AddScheduleJobAsync(DispatchInfoDTO tasksQz) |
| | | { |
| | | WebResponseContent result = new WebResponseContent(); |
| | | |
| | | if (tasksQz != null) |
| | | { |
| | | try |
| | | { |
| | | JobKey jobKey = new JobKey(tasksQz.Id.ToString(), tasksQz.JobGroup); |
| | | if (await _scheduler.Result.CheckExists(jobKey)) |
| | | { |
| | | result = WebResponseContent.Instance.Error(string.Format(QuartzJobInfoMessage.JobHasAdd, tasksQz.Name)); |
| | | return result; |
| | | } |
| | | #region 设置å¼å§æ¶é´åç»ææ¶é´ |
| | | |
| | | if (tasksQz.BeginTime == null) |
| | | { |
| | | tasksQz.BeginTime = DateTime.Now; |
| | | } |
| | | DateTimeOffset starRunTime = DateBuilder.NextGivenSecondDate(tasksQz.BeginTime, 1);//设置å¼å§æ¶é´ |
| | | if (tasksQz.EndTime == null) |
| | | { |
| | | tasksQz.EndTime = DateTime.MaxValue.AddDays(-1); |
| | | } |
| | | DateTimeOffset endRunTime = DateBuilder.NextGivenSecondDate(tasksQz.EndTime, 1);//设置æåæ¶é´ |
| | | |
| | | #endregion |
| | | |
| | | #region éè¿åå°è·åç¨åºéç±»ååç±» |
| | | |
| | | var basePath = AppContext.BaseDirectory; |
| | | var dllFile = Path.Combine(basePath, $"{tasksQz.AssemblyName}.dll"); |
| | | |
| | | if (!File.Exists(dllFile)) |
| | | { |
| | | var msg = $"{tasksQz.AssemblyName}.dllæªæ¾å°ï¼è¯·æ£æ¥æ°æ®ææä»¶"; |
| | | //log.Error(msg); |
| | | throw new Exception(msg); |
| | | } |
| | | |
| | | Assembly assembly = Assembly.Load(new AssemblyName(tasksQz.AssemblyName)); |
| | | Type jobType = assembly.GetType(tasksQz.AssemblyName + "." + tasksQz.ClassName); |
| | | |
| | | #endregion |
| | | |
| | | //ä¼ å
¥åå°åºæ¥çæ§è¡ç¨åºé |
| | | //IJobDetail jobDetail = JobBuilder.Create(jobType) |
| | | // .WithIdentity(tasksQz.Id.ToString(), tasksQz.JobGroup) |
| | | // .Build(); |
| | | //jobDetail.JobDataMap.Add("JobParams", tasksQz.JobParams); |
| | | |
| | | IJobDetail job = new JobDetailImpl(tasksQz.Id.ToString(), tasksQz.JobGroup, jobType); |
| | | job.JobDataMap.Add("JobParams", tasksQz.JobParams); |
| | | |
| | | ITrigger trigger = CreateSimpleTrigger(tasksQz); |
| | | |
| | | // åè¯Quartzä½¿ç¨æä»¬ç触å卿¥å®æä½ä¸ |
| | | await _scheduler.Result.ScheduleJob(job, trigger); |
| | | //await _scheduler.Result.ScheduleJob(jobDetail, trigger); |
| | | |
| | | result = WebResponseContent.Instance.OK(string.Format(QuartzJobInfoMessage.JobAddSuccess, tasksQz.Name)); |
| | | return result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new QuartzJobException(string.Format(QuartzJobExceptionMessage.AddJobException, tasksQz.Name, ex.Message), innerException: ex); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result = WebResponseContent.Instance.Error(string.Format(QuartzJobInfoMessage.JobNotExist, tasksQz?.Name)); |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 任塿¯å¦åå¨? |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public async Task<bool> IsExistScheduleJobAsync(DispatchInfoDTO sysSchedule) |
| | | { |
| | | JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup); |
| | | if (await _scheduler.Result.CheckExists(jobKey)) |
| | | { |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 忢ä¸ä¸ªæå®ç计åä»»å¡ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> StopScheduleJobAsync(DispatchInfoDTO sysSchedule) |
| | | { |
| | | WebResponseContent result = new WebResponseContent(); |
| | | try |
| | | { |
| | | JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup); |
| | | if (!await _scheduler.Result.CheckExists(jobKey)) |
| | | { |
| | | result = WebResponseContent.Instance.Error(string.Format(QuartzJobInfoMessage.JobNotExist, sysSchedule.Name)); |
| | | return result; |
| | | } |
| | | else |
| | | { |
| | | await this._scheduler.Result.DeleteJob(jobKey); |
| | | result = WebResponseContent.Instance.OK(string.Format(QuartzJobInfoMessage.StopAJobSuccess, sysSchedule.Name)); |
| | | return result; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new QuartzJobException(string.Format(QuartzJobExceptionMessage.StopAJobException, sysSchedule.Name, ex.Message), innerException: ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¢å¤æå®ç计åä»»å¡ |
| | | /// </summary> |
| | | /// <param name="sysSchedule"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> ResumeJob(DispatchInfoDTO sysSchedule) |
| | | { |
| | | WebResponseContent result = new WebResponseContent(); |
| | | try |
| | | { |
| | | JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup); |
| | | if (!await _scheduler.Result.CheckExists(jobKey)) |
| | | { |
| | | result = WebResponseContent.Instance.Error(string.Format(QuartzJobInfoMessage.ResumeJobNotExist, sysSchedule.Name)); |
| | | return result; |
| | | } |
| | | await this._scheduler.Result.ResumeJob(jobKey); |
| | | result = WebResponseContent.Instance.OK(string.Format(QuartzJobInfoMessage.ResumeJobSuccess, sysSchedule.Name)); |
| | | return result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new QuartzJobException(string.Format(QuartzJobExceptionMessage.ResumeJobException, sysSchedule.Name, ex.Message), innerException: ex); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æåæå®ç计åä»»å¡ |
| | | /// </summary> |
| | | /// <param name="sysSchedule"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> PauseJob(DispatchInfoDTO sysSchedule) |
| | | { |
| | | WebResponseContent result = new WebResponseContent(); |
| | | try |
| | | { |
| | | JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup); |
| | | if (!await _scheduler.Result.CheckExists(jobKey)) |
| | | { |
| | | result = WebResponseContent.Instance.Error(string.Format(QuartzJobInfoMessage.PauseJobNotExist, sysSchedule.Name)); |
| | | return result; |
| | | } |
| | | await this._scheduler.Result.PauseJob(jobKey); |
| | | result = WebResponseContent.Instance.OK(string.Format(QuartzJobInfoMessage.PauseJobSuccess, sysSchedule.Name)); |
| | | return result; |
| | | } |
| | | catch (Exception) |
| | | { |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | #region ç¶æç¶æå¸®å©æ¹æ³ |
| | | //public async Task<List<DispatchInfoDTO>> GetTaskStaus(DispatchInfoDTO sysSchedule) |
| | | //{ |
| | | |
| | | // var ls = new List<TaskInfoDto>(); |
| | | // var noTask = new List<TaskInfoDto>{ new TaskInfoDto { |
| | | // jobId = sysSchedule.Id.ObjToString(), |
| | | // jobGroup = sysSchedule.JobGroup, |
| | | // triggerId = "", |
| | | // triggerGroup = "", |
| | | // triggerStatus = "ä¸åå¨" |
| | | // } }; |
| | | // JobKey jobKey = new JobKey(sysSchedule.Id.ToString(), sysSchedule.JobGroup); |
| | | // IJobDetail job = await this._scheduler.Result.GetJobDetail(jobKey); |
| | | // if (job == null) |
| | | // { |
| | | // return noTask; |
| | | // } |
| | | // //info.Append(string.Format("ä»»å¡ID:{0}\r\nä»»å¡åç§°:{1}\r\n", job.Key.Name, job.Description)); |
| | | // var triggers = await this._scheduler.Result.GetTriggersOfJob(jobKey); |
| | | // if (triggers == null || triggers.Count == 0) |
| | | // { |
| | | // return noTask; |
| | | // } |
| | | // foreach (var trigger in triggers) |
| | | // { |
| | | // var triggerStaus = await this._scheduler.Result.GetTriggerState(trigger.Key); |
| | | // string state = GetTriggerState(triggerStaus.ObjToString()); |
| | | // ls.Add(new TaskInfoDto |
| | | // { |
| | | // jobId = job.Key.Name, |
| | | // jobGroup = job.Key.Group, |
| | | // triggerId = trigger.Key.Name, |
| | | // triggerGroup = trigger.Key.Group, |
| | | // triggerStatus = state |
| | | // }); |
| | | // //info.Append(string.Format("触åå¨ID:{0}\r\n触åå¨åç§°:{1}\r\nç¶æ:{2}\r\n", item.Key.Name, item.Description, state)); |
| | | |
| | | // } |
| | | // return ls; |
| | | //} |
| | | public string GetTriggerState(string key) |
| | | { |
| | | string state = null; |
| | | if (key != null) |
| | | key = key.ToUpper(); |
| | | switch (key) |
| | | { |
| | | case "1": |
| | | state = "æå"; |
| | | break; |
| | | case "2": |
| | | state = "宿"; |
| | | break; |
| | | case "3": |
| | | state = "åºé"; |
| | | break; |
| | | case "4": |
| | | state = "é»å¡"; |
| | | break; |
| | | case "0": |
| | | state = "æ£å¸¸"; |
| | | break; |
| | | case "-1": |
| | | state = "ä¸åå¨"; |
| | | break; |
| | | case "BLOCKED": |
| | | state = "é»å¡"; |
| | | break; |
| | | case "COMPLETE": |
| | | state = "宿"; |
| | | break; |
| | | case "ERROR": |
| | | state = "åºé"; |
| | | break; |
| | | case "NONE": |
| | | state = "ä¸åå¨"; |
| | | break; |
| | | case "NORMAL": |
| | | state = "æ£å¸¸"; |
| | | break; |
| | | case "PAUSED": |
| | | state = "æå"; |
| | | break; |
| | | } |
| | | return state; |
| | | } |
| | | #endregion |
| | | |
| | | #region å建触åå¨å¸®å©æ¹æ³ |
| | | |
| | | /// <summary> |
| | | /// å建SimpleTrigger触åå¨ï¼ç®å触åå¨ï¼ |
| | | /// </summary> |
| | | /// <param name="sysSchedule"></param> |
| | | /// <returns></returns> |
| | | private ITrigger CreateSimpleTrigger(DispatchInfoDTO sysSchedule) |
| | | { |
| | | ITrigger trigger = TriggerBuilder.Create() |
| | | .WithIdentity(sysSchedule.Id.ToString(), sysSchedule.JobGroup) |
| | | .StartAt(sysSchedule.BeginTime.GetValueOrDefault()) |
| | | .WithSimpleSchedule(x => x |
| | | .WithIntervalInSeconds(sysSchedule.IntervalSecond) |
| | | .RepeatForever() |
| | | ) |
| | | .EndAt(sysSchedule.EndTime.GetValueOrDefault()) |
| | | .Build(); |
| | | return trigger; |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// ç«å³æ§è¡ ä¸ä¸ªä»»å¡ æ§è¡ä¸æ¬¡ |
| | | /// </summary> |
| | | /// <param name="tasksQz"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> ExecuteJobAsync(DispatchInfoDTO tasksQz) |
| | | { |
| | | var result = new WebResponseContent(); |
| | | try |
| | | { |
| | | JobKey jobKey = new JobKey(tasksQz.Id.ToString(), tasksQz.JobGroup); |
| | | |
| | | //夿任塿¯å¦åå¨ï¼åå¨å 触å䏿¬¡ï¼ä¸åå¨åå
æ·»å ä¸ä¸ªä»»å¡ï¼è§¦å以åå åæ¢ä»»å¡ |
| | | if (!await _scheduler.Result.CheckExists(jobKey)) |
| | | { |
| | | //ä¸åå¨ å æ·»å ä¸ä¸ªè®¡åä»»å¡ |
| | | await AddScheduleJobAsync(tasksQz); |
| | | |
| | | //è§¦åæ§è¡ä¸æ¬¡ |
| | | await _scheduler.Result.TriggerJob(jobKey); |
| | | |
| | | //åæ¢ä»»å¡ |
| | | await StopScheduleJobAsync(tasksQz); |
| | | |
| | | result = WebResponseContent.Instance.OK(string.Format(QuartzJobInfoMessage.ExecuteJobSuccess, tasksQz.Name)); |
| | | } |
| | | else |
| | | { |
| | | await _scheduler.Result.TriggerJob(jobKey); |
| | | result = WebResponseContent.Instance.OK(string.Format(QuartzJobInfoMessage.ExecuteJobSuccess, tasksQz.Name)); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new QuartzJobException(string.Format(QuartzJobExceptionMessage.ResumeJobException, tasksQz.Name, ex.Message), innerException: ex); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | } |
| | | } |
copy from "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemRepository/AgvStationRepository.cs"
copy to "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Repository/DeviceInfoRepository.cs"
Îļþ´Ó ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemRepository/AgvStationRepository.cs ¸´ÖÆ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_TaskInfoRepository |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * æè¿°ï¼è®¾å¤ä¿¡æ¯ä»å¨å®ç°å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_ISystemRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | |
| | | namespace WIDESEAWCS_SystemRepository |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Repository |
| | | { |
| | | public class AgvStationRepository : RepositoryBase<AGVStation>, IAgvStationRepository |
| | | public class DeviceInfoRepository : RepositoryBase<Dt_DeviceInfo>, IDeviceInfoRepository |
| | | { |
| | | public AgvStationRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage) |
| | | public DeviceInfoRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage) |
| | | { |
| | | } |
| | | } |
copy from "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemRepository/AgvStationRepository.cs"
copy to "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Repository/DeviceProtocolDetailRepository.cs"
Îļþ´Ó ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemRepository/AgvStationRepository.cs ¸´ÖÆ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_TaskInfoRepository |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * æè¿°ï¼è®¾å¤åè®®æç»ä¿¡æ¯ä»å¨å®ç°å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_ISystemRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | |
| | | namespace WIDESEAWCS_SystemRepository |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Repository |
| | | { |
| | | public class AgvStationRepository : RepositoryBase<AGVStation>, IAgvStationRepository |
| | | public class DeviceProtocolDetailRepository : RepositoryBase<Dt_DeviceProtocolDetail>, IDeviceProtocolDetailRepository |
| | | { |
| | | public AgvStationRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage) |
| | | public DeviceProtocolDetailRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage) |
| | | { |
| | | } |
| | | } |
copy from "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs"
copy to "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Repository/DeviceProtocolRepository.cs"
Îļþ´Ó ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs ¸´ÖÆ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_ITaskInfoRepository |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * æè¿°ï¼è®¾å¤åè®®ä»å¨å®ç°å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | |
| | | namespace WIDESEAWCS_ISystemRepository |
| | | { |
| | | public interface IAgvStationRepository : IRepository<AGVStation> |
| | | { |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Repository |
| | | { |
| | | public class DeviceProtocolRepository : RepositoryBase<Dt_DeviceProtocol>, IDeviceProtocolRepository |
| | | { |
| | | public DeviceProtocolRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage) |
| | | { |
| | | } |
| | | } |
| | | } |
copy from "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs"
copy to "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Repository/DispatchInfoRepository.cs"
Îļþ´Ó ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs ¸´ÖÆ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_ITaskInfoRepository |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * æè¿°ï¼è°åº¦æå¡é
ç½®ä»å¨å®ç°å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | |
| | | namespace WIDESEAWCS_ISystemRepository |
| | | { |
| | | public interface IAgvStationRepository : IRepository<AGVStation> |
| | | { |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Repository |
| | | { |
| | | public class DispatchInfoRepository : RepositoryBase<Dt_DispatchInfo>, IDispatchInfoRepository |
| | | { |
| | | public DispatchInfoRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage) |
| | | { |
| | | } |
| | | } |
| | | } |
copy from "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs"
copy to "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Repository/IDeviceInfoRepository.cs"
Îļþ´Ó ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs ¸´ÖÆ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_ITaskInfoRepository |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * æè¿°ï¼è®¾å¤ä¿¡æ¯ä»å¨æ¥å£å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | |
| | | namespace WIDESEAWCS_ISystemRepository |
| | | { |
| | | public interface IAgvStationRepository : IRepository<AGVStation> |
| | | { |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Repository |
| | | { |
| | | public interface IDeviceInfoRepository : IRepository<Dt_DeviceInfo> |
| | | { |
| | | } |
| | | } |
copy from "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs"
copy to "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Repository/IDeviceProtocolDetailRepository.cs"
Îļþ´Ó ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs ¸´ÖÆ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_ITaskInfoRepository |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * æè¿°ï¼è®¾å¤åè®®æç»ä»å¨æ¥å£å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | |
| | | namespace WIDESEAWCS_ISystemRepository |
| | | { |
| | | public interface IAgvStationRepository : IRepository<AGVStation> |
| | | { |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Repository |
| | | { |
| | | public interface IDeviceProtocolDetailRepository : IRepository<Dt_DeviceProtocolDetail> |
| | | { |
| | | } |
| | | } |
copy from "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs"
copy to "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Repository/IDeviceProtocolRepository.cs"
Îļþ´Ó ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs ¸´ÖÆ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_ITaskInfoRepository |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * æè¿°ï¼è®¾å¤åè®®ä»å¨æ¥å£å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | |
| | | namespace WIDESEAWCS_ISystemRepository |
| | | { |
| | | public interface IAgvStationRepository : IRepository<AGVStation> |
| | | { |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Repository |
| | | { |
| | | public interface IDeviceProtocolRepository : IRepository<Dt_DeviceProtocol> |
| | | { |
| | | } |
| | | } |
copy from "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs"
copy to "\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Repository/IDispatchInfoRepository.cs"
Îļþ´Ó ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_ISystemRepository/IAgvStationRepository.cs ¸´ÖÆ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_ITaskInfoRepository |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ |
| | | * æè¿°ï¼è°åº¦æå¡é
ç½®ä»å¨æ¥å£å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_Model.Models.System; |
| | | |
| | | namespace WIDESEAWCS_ISystemRepository |
| | | { |
| | | public interface IAgvStationRepository : IRepository<AGVStation> |
| | | { |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Repository |
| | | { |
| | | public interface IDispatchInfoRepository : IRepository<Dt_DispatchInfo> |
| | | { |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Repository |
| | | { |
| | | public interface IRouterRepository : IRepository<Dt_Router> |
| | | { |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Repository |
| | | { |
| | | public class RouterRepository : RepositoryBase<Dt_Router>, IRouterRepository |
| | | { |
| | | public RouterRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage) |
| | | { |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼æ å°QuartzJobæ°æ®åºè¡¨ |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.DB; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.Seed; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Seed |
| | | { |
| | | public class QuartzJobCreateDataTabel |
| | | { |
| | | private static string SeedDataFolder = "WIDESEAWCS_DB.DBSeed.Json/{0}.tsv"; |
| | | |
| | | /// <summary> |
| | | /// æ å°QuartzJobæ°æ®åºè¡¨ |
| | | /// </summary> |
| | | /// <param name="dbContext"></param> |
| | | /// <returns></returns> |
| | | public static async Task SeedAsync(DBContext dbContext, string WebRootPath) |
| | | { |
| | | try |
| | | { |
| | | Console.WriteLine("Create QuartzJob Tables..."); |
| | | |
| | | var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; |
| | | var referencedAssemblies = System.IO.Directory.GetFiles(path, "WIDESEAWCS_QuartzJob.dll").Select(Assembly.LoadFrom).ToArray(); |
| | | |
| | | var modelTypes = referencedAssemblies |
| | | .SelectMany(a => a.DefinedTypes) |
| | | .Select(type => type.AsType()) |
| | | .Where(x => x.IsClass && x.Namespace is "WIDESEAWCS_QuartzJob.Models" && x.GetCustomAttribute<SugarTable>() != null) |
| | | .ToList(); |
| | | SeedDataFolder = Path.Combine(WebRootPath, SeedDataFolder); |
| | | modelTypes.ForEach(t => |
| | | { |
| | | //var diffString = dbContext.Db.CodeFirst.GetDifferenceTables(t).ToDiffString(); |
| | | // è¿éåªæ¯ææ·»å 表ï¼ä¸æ¯æå é¤ |
| | | // 妿æ³è¦å é¤ï¼æ°æ®åºç´æ¥å³é®å é¤ï¼æè
èç³»SqlSugarä½è
ï¼ |
| | | IDbMaintenance dbMaintenance = dbContext.Db.DbMaintenance; |
| | | if (!dbMaintenance.IsAnyTable(t.Name, false)) |
| | | { |
| | | Console.WriteLine(t.Name); |
| | | dbContext.Db.CodeFirst.InitTables(t); |
| | | |
| | | string seedData = FileHelper.ReadFile(string.Format(SeedDataFolder, t.Name), Encoding.UTF8); |
| | | |
| | | |
| | | #region AddSeedData |
| | | if (seedData != "ä¸åå¨ç¸åºçç®å½") |
| | | { |
| | | List<Dictionary<string, object>> dicFile = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(seedData); |
| | | |
| | | if (dicFile.Count > 0) |
| | | { |
| | | List<Dictionary<string, object>> dic = new List<Dictionary<string, object>>(); |
| | | |
| | | List<string> columnNames = dbContext.Db.DbMaintenance.GetColumnInfosByTableName(t.Name, false).Select(x => x.DbColumnName).ToList(); |
| | | var a = t.GetProperties().FirstOrDefault(x => !columnNames.Contains(x.Name)); |
| | | |
| | | List<PropertyInfo> propertyInfos = t.GetProperties().Where(x => columnNames.Contains(x.Name)).ToList(); |
| | | for (int j = 0; j < dicFile.Count; j++) |
| | | { |
| | | Dictionary<string, object> keyValuePairs = new Dictionary<string, object>(); |
| | | for (int i = 0; i < propertyInfos.Count; i++) |
| | | { |
| | | PropertyInfo propertyInfo = propertyInfos[i]; |
| | | SugarColumn sugarColumn = propertyInfo.GetCustomAttribute<SugarColumn>(); |
| | | if (sugarColumn != null) |
| | | { |
| | | if (!sugarColumn.IsIgnore) |
| | | { |
| | | keyValuePairs.Add(propertyInfo.Name, dicFile[j][propertyInfo.Name]); |
| | | } |
| | | } |
| | | } |
| | | dic.Add(keyValuePairs); |
| | | } |
| | | |
| | | if (dic.Count > 0) |
| | | { |
| | | for (int i = 0; i < dic.Count; i++) |
| | | { |
| | | if (dic[i].ContainsKey("CreateDate")) |
| | | dic[i]["CreateDate"] = DateTime.Now; |
| | | else |
| | | dic[i].Add("CreateDate", DateTime.Now); |
| | | } |
| | | string str = $"SET IDENTITY_INSERT {t.Name} ON;"; |
| | | |
| | | str += dbContext.Db.Insertable(dic).AS(t.Name).ToSqlString(); |
| | | |
| | | str += ($"SET IDENTITY_INSERT {t.Name} OFF;"); |
| | | |
| | | dbContext.Db.Ado.ExecuteCommand(str); |
| | | |
| | | ConsoleHelper.WriteSuccessLine($"Table [{t.Name}] SeedData Added Successfully"); |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | }); |
| | | ConsoleHelper.WriteSuccessLine($"QuartzJob Tables Created Successfully!"); |
| | | Console.WriteLine(); |
| | | |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 1ãè¥æ¯Mysql,æ¥ç常è§é®é¢:https://github.com/anjoy8/Blog.Core/issues/148#issue-776281770 |
| | | //2ãè¥æ¯Oracle,æ¥ç常è§é®é¢:https://github.com/anjoy8/Blog.Core/issues/148#issuecomment-752340231 |
| | | throw new Exception("é误ï¼" + ex.Message); |
| | | } |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤ä¿¡æ¯ä¸å¡å®ç°å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using AutoMapper; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_QuartzJob.DeviceEnum; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Service |
| | | { |
| | | public class DeviceInfoService : ServiceBase<Dt_DeviceInfo, IDeviceInfoRepository>, IDeviceInfoService |
| | | { |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IMapper _mapper; |
| | | public DeviceInfoService(IDeviceInfoRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IMapper mapper) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _mapper = mapper; |
| | | } |
| | | |
| | | public override WebResponseContent AddData(SaveModel saveModel) |
| | | { |
| | | return base.AddData(saveModel); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢è®¾å¤ä»¥å对åºçå议信æ¯ã |
| | | /// </summary> |
| | | /// <returns>è¿å设å¤ä¿¡æ¯ä»¥å对åºå议信æ¯çéåã</returns> |
| | | public async Task<List<DeviceInfoDTO>> QueryDeviceProInfos() |
| | | { |
| | | List<Dt_DeviceInfo> deviceInfos = await Db.Queryable<Dt_DeviceInfo>().Where(x => x.DeviceStatus == ((int)DeviceStatusEnum.Enable).ToString()).Includes(x => x.ProtocolList).ToListAsync(); |
| | | return _mapper.Map<List<DeviceInfoDTO>>(deviceInfos); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤åè®®æç»ä¸å¡å®ç°å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using AutoMapper; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | |
| | | using WIDESEAWCS_QuartzJob.DeviceEnum; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Service |
| | | { |
| | | public class DeviceProtocolDetailService : ServiceBase<Dt_DeviceProtocolDetail, IDeviceProtocolDetailRepository>, IDeviceProtocolDetailService |
| | | { |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IMapper _mapper; |
| | | public DeviceProtocolDetailService(IDeviceProtocolDetailRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IMapper mapper) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _mapper = mapper; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç±»åè·ååè®®æç»ä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="deviceType">设å¤ç±»å</param> |
| | | /// <returns>è¿å设å¤åè®®æç»DTOéå</returns> |
| | | public List<DeviceProtocolDetailDTO> GetDeviceProtocolDetailsByDeviceType(string deviceType) |
| | | { |
| | | return BaseDal.QueryData(x => x.DeviceType == deviceType).Select(x => new DeviceProtocolDetailDTO { DeviceType = x.DeviceType, DeviceProParamName = x.DeviceProParamName, ProtocalDetailValue = x.ProtocalDetailValue, ProtocolDetailDes = x.ProtocolDetailDes, ProtocolDetailType = x.ProtocolDetailType }).ToList(); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤åè®®ä¸å¡å®ç°å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Magicodes.ExporterAndImporter.Core.Models; |
| | | using Magicodes.ExporterAndImporter.Excel; |
| | | using Microsoft.AspNetCore.Http; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Service |
| | | { |
| | | public class DeviceProtocolService : ServiceBase<Dt_DeviceProtocol, IDeviceProtocolRepository>, IDeviceProtocolService |
| | | { |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | public DeviceProtocolService(IDeviceProtocolRepository BaseDal, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读å导å
¥æä»¶çæ°æ®è¿åå°å端 |
| | | /// </summary> |
| | | /// <param name="fileInput">æä»¶</param> |
| | | /// <returns>è¿å读åç»æï¼æåè¿åæ°æ®ï¼å¤±è´¥è¿åé误信æ¯</returns> |
| | | public WebResponseContent GetImportData(List<IFormFile> fileInput) |
| | | { |
| | | try |
| | | { |
| | | if (fileInput == null || fileInput.Count == 0) |
| | | return new WebResponseContent { Status = true, Message = "è¯·éæ©ä¸ä¼ çæä»¶" }; |
| | | Microsoft.AspNetCore.Http.IFormFile formFile = fileInput[0]; |
| | | string dicPath = AppDomain.CurrentDomain.BaseDirectory + $"ExcelImprot/{DateTime.Now.ToString("yyyMMdd")}/{typeof(Dt_DeviceProtocol).Name}/"; |
| | | if (!Directory.Exists(dicPath)) Directory.CreateDirectory(dicPath); |
| | | string fileName = $"{Guid.NewGuid()}_{formFile.FileName}"; |
| | | dicPath = $"{dicPath}{fileName}"; |
| | | using (FileStream stream = new FileStream(dicPath, FileMode.Create)) |
| | | { |
| | | formFile.CopyTo(stream); |
| | | } |
| | | ExcelImporter importer = new ExcelImporter(); |
| | | ImportResult<Dt_DeviceProtocol> importResult = importer.Import<Dt_DeviceProtocol>(dicPath, "").Result; |
| | | if (importResult.HasError) |
| | | { |
| | | return WebResponseContent.Instance.Error(importResult.TemplateErrors.Serialize()); |
| | | } |
| | | return WebResponseContent.Instance.OK(data: importResult.Data); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public override WebResponseContent AddData(SaveModel saveModel) |
| | | { |
| | | //saveModel.MainData[""] |
| | | return base.AddData(saveModel); |
| | | } |
| | | |
| | | //public WebResponseContent InsertProtocol_Line(int PLCid, string ChildCode,decimal ProOffsetStart) |
| | | //{ |
| | | // Type type = typeof(); |
| | | //} |
| | | |
| | | |
| | | // å°è£
æ£æ¥é»è¾ |
| | | private bool DeviceProtocolExists(int DeviceID, string DeviceChildCode, decimal DeviceProOffset) |
| | | { |
| | | return BaseDal.QueryFirst(x => x.DeviceId == DeviceID && x.DeviceChildCode == DeviceChildCode && x.DeviceProOffset == DeviceProOffset) != null; |
| | | } |
| | | |
| | | // å°è£
对象å建é»è¾ |
| | | private Dt_DeviceProtocol CreateDeviceProtocol(int DeviceID, string DeviceChildCode, decimal DeviceProOffset, int additionalOffset, string dataType, int dataLength, string paramName, string DeviceProDataBlock, string DeviceProParamType) |
| | | { |
| | | decimal DeviceProOffsets = DeviceProOffset + additionalOffset; |
| | | return new Dt_DeviceProtocol |
| | | { |
| | | DeviceId = DeviceID, |
| | | DeviceChildCode = DeviceChildCode, |
| | | DeviceProDataBlock = DeviceProDataBlock, |
| | | DeviceProOffset = DeviceProOffsets, |
| | | DeviceProDataLength = dataLength, |
| | | DeviceProDataType = dataType, |
| | | DeviceProParamName = paramName, |
| | | DeviceProParamType = DeviceProParamType, |
| | | DeviceProParamDes = "1", |
| | | DeviceProRemark = "", |
| | | Creater = "admin", |
| | | CreateDate = DateTime.Now, |
| | | }; |
| | | } |
| | | |
| | | public WebResponseContent AddAfterDeviceProtocol(int DeviceID, string DeviceChildCode, decimal DeviceProOffset) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (DeviceProtocolExists(DeviceID, DeviceChildCode, DeviceProOffset)) |
| | | { |
| | | throw new InvalidOperationException("å·²åå¨è¯¥èç¹æç»"); |
| | | } |
| | | |
| | | var protocols = new List<Dt_DeviceProtocol> |
| | | { |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffset, 0, "int", 1, "ConveyorLineTargetAddress","DB1000", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffset, 2, "int", 1, "ConveyorLineTaskNum", "DB1000", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffset, 6, "string", 25, "ConveyorLineBarcode", "DB1000", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffset, 34, "int", 1, "Reserve1", "DB1000", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffset, 36, "int", 1, "Reserve2", "DB1000", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffset, 38, "int", 1, "Reserve3", "DB1000", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffset, 40, "byte", 1, "InteractiveSignal", "DB1000", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffset, 42, "int", 1, "HasPallet", "DB1000", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffset, 44, "int", 1, "ConveyorLineAlarm", "DB1000", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffset, 46, "int", 1, "ResponState", "DB1000", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffset, 48, "int", 1, "Reserve5", "DB1000", "DeviceCommand") |
| | | |
| | | }; |
| | | var result = BaseDal.AddData(protocols); |
| | | return content.OK(data: result); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | |
| | | } |
| | | |
| | | public WebResponseContent AddBeforeDeviceProtocol(int DeviceID, string DeviceChildCode, decimal DeviceProOffsetRead, decimal DeviceProOffsetWrite) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (DeviceProtocolExists(DeviceID, DeviceChildCode, DeviceProOffsetRead)) |
| | | { |
| | | throw new InvalidOperationException("å·²åå¨è¯¥èç¹æç»"); |
| | | } |
| | | |
| | | var protocols = new List<Dt_DeviceProtocol> |
| | | { |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetRead, 0, "int", 1, "InteractiveSignal","DB900", "ReadDeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetRead, 2, "string", 25, "ConveyorLineBarcode", "DB900", "ReadDeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetRead, 30, "dint", 1, "ConveyorLineTargetAddress", "DB900", "ReadDeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetRead, 34, "dint", 1, "ConveyorLineTaskNum", "DB900", "ReadDeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetRead, 38, "dint", 1, "ConveyorLineAlarm", "DB900", "ReadDeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetWrite, 0, "w", 1, "WriteInteractiveSignal", "DB901", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetWrite, 2, "string", 25, "WriteConveyorLineBarcode", "DB901", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetWrite, 30, "dint", 1, "WriteConveyorLineTargetAddress", "DB901", "DeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetWrite, 34, "dint", 1, "WriteConveyorLineTaskNum", "DB901", "DeviceCommand"), |
| | | |
| | | }; |
| | | var result = BaseDal.AddData(protocols); |
| | | return content.OK(data: result); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent AddBeforReadDeviceProtocol(int DeviceID, string DeviceChildCode, decimal DeviceProOffsetRead) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (DeviceProtocolExists(DeviceID, DeviceChildCode, DeviceProOffsetRead)) |
| | | { |
| | | throw new InvalidOperationException("å·²åå¨è¯¥èç¹æç»"); |
| | | } |
| | | |
| | | var protocols = new List<Dt_DeviceProtocol> |
| | | { |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetRead, 0, "int", 1, "InteractiveSignal","DB900", "ReadDeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetRead, 2, "string", 25, "ConveyorLineBarcode", "DB900", "ReadDeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetRead, 30, "dint", 1, "ConveyorLineTargetAddress", "DB900", "ReadDeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetRead, 34, "dint", 1, "ConveyorLineTaskNum", "DB900", "ReadDeviceCommand"), |
| | | CreateDeviceProtocol(DeviceID, DeviceChildCode, DeviceProOffsetRead, 38, "dint", 1, "ConveyorLineAlarm", "DB900", "ReadDeviceCommand"), |
| | | }; |
| | | var result = BaseDal.AddData(protocols); |
| | | return content.OK(data: result); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è°åº¦æå¡é
ç½®ä¸å¡å®ç°å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
| | | using Quartz.Impl.Matchers; |
| | | using Quartz; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Helper; |
| | | |
| | | using WIDESEAWCS_QuartzJob.DeviceEnum; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | using Quartz.Impl; |
| | | using System.Collections.Specialized; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Service |
| | | { |
| | | public class DispatchInfoService : ServiceBase<Dt_DispatchInfo, IDispatchInfoRepository>, IDispatchInfoService |
| | | { |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IDeviceInfoRepository _deviceInfoRepository; |
| | | private readonly ISchedulerCenter _schedulerCenter; |
| | | public DispatchInfoService(IDispatchInfoRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IDeviceInfoRepository deviceInfoRepository, ISchedulerCenter schedulerCenter) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _deviceInfoRepository = deviceInfoRepository; |
| | | _schedulerCenter = schedulerCenter; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢è°åº¦æå¡Jobä¸å¯¹åºç设å¤ä¿¡æ¯ã |
| | | /// </summary> |
| | | /// <returns>è¿åè°åº¦æå¡JobDTOéåã</returns> |
| | | public List<DispatchInfoDTO> QueryDispatchInfos() |
| | | { |
| | | return Db.Queryable<Dt_DispatchInfo, Dt_DeviceInfo>((a, b) => a.JobGroup == b.DeviceType && b.DeviceStatus == ((int)DeviceStatusEnum.Enable).ToString()).Select((a, b) => new DispatchInfoDTO |
| | | { |
| | | JobGroup = a.JobGroup, |
| | | AssemblyName = a.AssemblyName, |
| | | BeginTime = a.BeginTime, |
| | | ClassName = a.ClassName, |
| | | CreateDate = a.CreateDate, |
| | | Creater = a.Creater, |
| | | CycleHasRunTimes = 0, |
| | | EndTime = a.EndTime, |
| | | Id = b.Id, |
| | | IntervalSecond = a.IntervalSecond, |
| | | Modifier = a.Modifier, |
| | | ModifyDate = a.ModifyDate, |
| | | Name = a.Name, |
| | | Remark = a.Remark, |
| | | DeviceType = b.DeviceType |
| | | }).ToList(); |
| | | } |
| | | |
| | | public async Task<WebResponseContent> GetDispatchInfosAsync() |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | NameValueCollection collection = new NameValueCollection |
| | | { |
| | | { "quartz.serializer.type", "binary" }, |
| | | }; |
| | | StdSchedulerFactory factory = new StdSchedulerFactory(collection); |
| | | IScheduler scheduler = await factory.GetScheduler(); |
| | | var jobKeys = await scheduler.GetJobKeys(GroupMatcher<JobKey>.AnyGroup()); |
| | | foreach (var jobKey in jobKeys) |
| | | { |
| | | // å¨è¿éå¤çæ¯ä¸ªJobKey |
| | | IJobDetail jobDetail = await scheduler.GetJobDetail(jobKey); |
| | | if (jobDetail != null) |
| | | { |
| | | // å¯ä»¥è·åJobçæè¿°ä¿¡æ¯ |
| | | string jobDescription = jobDetail.Description; |
| | | // 以åJobçæ°æ®æ å°ï¼JobDataMapï¼ |
| | | JobDataMap jobDataMap = jobDetail.JobDataMap; |
| | | } |
| | | } |
| | | |
| | | var triggerKeys = await scheduler.GetTriggerKeys(GroupMatcher<TriggerKey>.AnyGroup()); |
| | | foreach (var triggerKey in triggerKeys) |
| | | { |
| | | // å¨è¿éå¤çæ¯ä¸ªTriggerKey |
| | | ITrigger trigger = await scheduler.GetTrigger(triggerKey); |
| | | if (trigger != null) |
| | | { |
| | | // è·åä¸ä¸æ¬¡è§¦åæ¶é´ï¼å¦ææï¼ |
| | | DateTimeOffset? nextFireTime = trigger.GetNextFireTimeUtc(); |
| | | // è·å䏿¬¡è§¦åæ¶é´ï¼å¦ææï¼ |
| | | DateTimeOffset? previousFireTime = trigger.GetPreviousFireTimeUtc(); |
| | | // è·å触åç±»åï¼å¦SimpleTriggerãCronTriggerï¼ |
| | | string triggerType = trigger.GetType().Name; |
| | | // 对äºCronTriggerï¼è¿å¯ä»¥è·åCron表达å¼ï¼å¦ææ¯ï¼ |
| | | //if (trigger is CronTrigger cronTrigger) |
| | | //{ |
| | | // string cronExpression = cronTrigger.CronExpressionString; |
| | | //} |
| | | if (!previousFireTime.HasValue && nextFireTime.HasValue) |
| | | { |
| | | Console.WriteLine($"Jobå¤äºçå¾
触åç¶æï¼Triggeråç§°: {triggerKey.Name}"); |
| | | } |
| | | } |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤ä¿¡æ¯ä¸å¡æ¥å£å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Service |
| | | { |
| | | public interface IDeviceInfoService : IService<Dt_DeviceInfo> |
| | | { |
| | | /// <summary> |
| | | /// æ¥è¯¢è®¾å¤ä»¥å对åºçå议信æ¯ã |
| | | /// </summary> |
| | | /// <returns>è¿å设å¤ä¿¡æ¯ä»¥å对åºå议信æ¯çéåã</returns> |
| | | Task<List<DeviceInfoDTO>> QueryDeviceProInfos(); |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤åè®®æç»ä¸å¡æ¥å£å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Service |
| | | { |
| | | public interface IDeviceProtocolDetailService : IService<Dt_DeviceProtocolDetail> |
| | | { |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç±»åè·ååè®®æç»ä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="deviceType">设å¤ç±»å</param> |
| | | /// <returns>è¿å设å¤åè®®æç»DTOéå</returns> |
| | | List<DeviceProtocolDetailDTO> GetDeviceProtocolDetailsByDeviceType(string deviceType); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼è®¾å¤åè®®ä¸å¡æ¥å£å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using Microsoft.AspNetCore.Http; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Service |
| | | { |
| | | public interface IDeviceProtocolService : IService<Dt_DeviceProtocol> |
| | | { |
| | | /// <summary> |
| | | /// 读å导å
¥æä»¶çæ°æ®è¿åå°å端 |
| | | /// </summary> |
| | | /// <param name="fileInput">æä»¶</param> |
| | | /// <returns>è¿å读åç»æï¼æåè¿åæ°æ®ï¼å¤±è´¥è¿åé误信æ¯</returns> |
| | | WebResponseContent GetImportData(List<IFormFile> fileInput); |
| | | WebResponseContent AddAfterDeviceProtocol(int DeviceID, string DeviceChildCode, decimal DeviceProOffset); |
| | | |
| | | WebResponseContent AddBeforeDeviceProtocol(int DeviceID, string DeviceChildCode, decimal DeviceProOffsetRead, decimal DeviceProOffsetWrite); |
| | | WebResponseContent AddBeforReadDeviceProtocol(int DeviceID, string DeviceChildCode, decimal DeviceProOffsetRead); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | #region << ç æ¬ 注 é >> |
| | | /*---------------------------------------------------------------- |
| | | * å½å空é´ï¼WIDESEAWCS_QuartzJob |
| | | * å建è
ï¼è¡ç«¥åº |
| | | * å建æ¶é´ï¼2024/8/2 16:13:36 |
| | | * çæ¬ï¼V1.0.0 |
| | | * æè¿°ï¼ä»»å¡è°åº¦é
ç½®ä¸å¡æ¥å£å± |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * ä¿®æ¹äººï¼ |
| | | * ä¿®æ¹æ¶é´ï¼ |
| | | * çæ¬ï¼V1.0.1 |
| | | * ä¿®æ¹è¯´æï¼ |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Service |
| | | { |
| | | public interface IDispatchInfoService : IService<Dt_DispatchInfo> |
| | | { |
| | | /// <summary> |
| | | /// æ¥è¯¢å®æ¶å¨Jobä¸å¯¹åºç设å¤ä¿¡æ¯ã |
| | | /// </summary> |
| | | /// <returns>è¿å宿¶å¨Jobä¸å¯¹åºç设å¤ä¿¡æ¯DTOéåã</returns> |
| | | List<DispatchInfoDTO> QueryDispatchInfos(); |
| | | |
| | | Task<WebResponseContent> GetDispatchInfosAsync(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_DTO.BasicInfo; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | |
| | | namespace WIDESEAWCS_QuartzJob.Service |
| | | { |
| | | public interface IRouterService : IService<Dt_Router> |
| | | { |
| | | /// <summary> |
| | | /// æ ¹æ®èµ·ç¹/å½åä½ç½®ãç»ç¹è·åä¸ä¸ä¸ªåèç¹ã |
| | | /// </summary> |
| | | /// <param name="startPosi">èµ·ç¹/å½åä½ç½®ã</param> |
| | | /// <param name="endPosi">ç»ç¹ã</param> |
| | | /// <returns>è¿åè·¯ç±å®ä½éåã</returns> |
| | | List<Dt_Router> QueryNextRoutes(string startPosi, string endPosi); |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç¼å·è·å对åºçè·¯ç±ç¹ä½ç¼å·(è¾é线ç«å°ç¼å·)ä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="deviceCode">设å¤ç¼å·</param> |
| | | /// <returns>è¿åè·¯ç±ç¹ä½ç¼å·(è¾é线ç«å°ç¼å·)éå</returns> |
| | | List<string> QueryAllPositions(string deviceCode); |
| | | |
| | | /// <summary> |
| | | /// è·åè·¯ç±è¡¨ä¸ææå®æ´çè·¯ç±ä¿¡æ¯(å端å±ç¤º) |
| | | /// </summary> |
| | | /// <returns>å¿å对象éå</returns> |
| | | List<object> GetAllWholeRouters(); |
| | | |
| | | WebResponseContent AddRouters(List<RoutersAddDTO> routersAddDTOs, int routerType); |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç¼å·è·å对åºçåºç«è·¯ç±ç¹ä½ç¼å·(è¾é线ç«å°ç¼å·)ä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="deviceCode">设å¤ç¼å·</param> |
| | | /// <returns>è¿åè·¯ç±ç¹ä½ç¼å·(è¾é线ç«å°ç¼å·)éå</returns> |
| | | List<string> QueryOutDeviceCodes(string deviceCode); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Masuit.Tools; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_DTO.BasicInfo; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | |
| | | namespace WIDESEAWCS_BasicInfoService |
| | | { |
| | | public class RouterService : ServiceBase<Dt_Router, IRouterRepository>, IRouterService |
| | | { |
| | | private readonly IDeviceProtocolRepository _deviceProtocolRepository; |
| | | private readonly IDeviceInfoRepository _deviceInfoRepository; |
| | | public RouterService(IRouterRepository BaseDal, IDeviceProtocolRepository deviceProtocolRepository, IDeviceInfoRepository deviceInfoRepository) : base(BaseDal) |
| | | { |
| | | _deviceProtocolRepository = deviceProtocolRepository; |
| | | _deviceInfoRepository = deviceInfoRepository; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®èµ·ç¹/å½åä½ç½®ãç»ç¹è·åä¸ä¸ä¸ªåèç¹ã |
| | | /// </summary> |
| | | /// <param name="startPosi">èµ·ç¹/å½åä½ç½®ã</param> |
| | | /// <param name="endPosi">ç»ç¹ã</param> |
| | | /// <returns>è¿åè·¯ç±å®ä½éåã</returns> |
| | | //public List<Dt_Router> QueryNextRoutes(string startPosi, string endPosi) |
| | | //{ |
| | | // //todo æ¹æ³éä¼å |
| | | // List<Dt_Router> routers = new List<Dt_Router>(); |
| | | // try |
| | | // { |
| | | // List<Dt_Router> dt_Routers = BaseDal.QueryData(x => x.NextPosi == endPosi || x.ChildPosi == endPosi, new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } }); |
| | | // if (dt_Routers.Count > 0) |
| | | // { |
| | | // foreach (var item in dt_Routers) |
| | | // { |
| | | // if (item.StartPosi == startPosi && !routers.Any(x => x.Id == item.Id)) |
| | | // { |
| | | // routers.Add(item); |
| | | // } |
| | | // else |
| | | // { |
| | | // List<Dt_Router> tempRouters = QueryNextRoutes(startPosi, item.StartPosi); |
| | | // foreach (var router in tempRouters) |
| | | // { |
| | | // if (router.StartPosi == startPosi && !routers.Any(x => x.Id == router.Id)) |
| | | // { |
| | | // routers.Add(router); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // throw new Exception($"è¯¥è·¯å¾æªé
ç½®æé
ç½®é误,è¯·æ£æ¥è®¾å¤è·¯ç±ä¿¡æ¯,èµ·ç¹:ã{startPosi}ã,ç»ç¹:ã{endPosi}ã"); |
| | | // } |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // //throw new Exception(ex.Message); |
| | | // //è®°å½éè¯¯ä¿¡æ¯ |
| | | // } |
| | | // return routers; |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®èµ·ç¹/å½åä½ç½®ãç»ç¹è·åä¸ä¸ä¸ªåèç¹ã |
| | | /// </summary> |
| | | /// <param name="startPosi">èµ·ç¹/å½åä½ç½®ã</param> |
| | | /// <param name="endPosi">ç»ç¹ã</param> |
| | | /// <returns>è¿åè·¯ç±å®ä½éåã</returns> |
| | | public List<Dt_Router> QueryNextRoutes(string startPosi, string endPosi) |
| | | { |
| | | // ç¨äºè®°å½å·²ç»è®¿é®è¿çèµ·ç¹åç»ç¹ç»åï¼é¿å
éå¤è®¿é®è¿å
¥æ»å¾ªç¯ |
| | | HashSet<string> visitedRoutes = new HashSet<string>(); |
| | | return QueryNextRoutesInternal(startPosi, endPosi, visitedRoutes); |
| | | } |
| | | |
| | | private List<Dt_Router> QueryNextRoutesInternal(string startPosi, string endPosi, HashSet<string> visitedRoutes) |
| | | { |
| | | List<Dt_Router> routers = new List<Dt_Router>(); |
| | | try |
| | | { |
| | | // æå»ºä¸ä¸ªå¯ä¸æ è¯å½åèµ·ç¹åç»ç¹ç»åçå符串 |
| | | string routeKey = $"{startPosi}_{endPosi}"; |
| | | if (visitedRoutes.Contains(routeKey)) |
| | | { |
| | | // 妿已ç»è®¿é®è¿ï¼ç´æ¥è¿å空å表ï¼é¿å
éå¤è¿å
¥ç¸åçéå½åæ¯ |
| | | return routers; |
| | | } |
| | | visitedRoutes.Add(routeKey); |
| | | |
| | | List<Dt_Router> dt_Routers = BaseDal.QueryData(x => (x.NextPosi == endPosi || x.ChildPosi == endPosi) && x.StartPosi == startPosi, new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } }); |
| | | if (dt_Routers.IsNullOrEmpty()) |
| | | { |
| | | dt_Routers = BaseDal.QueryData(x => x.NextPosi == endPosi || x.ChildPosi == endPosi, new Dictionary<string, OrderByType> { { nameof(Dt_Router.IsEnd), OrderByType.Desc } }); |
| | | } |
| | | if (dt_Routers.Count > 0) |
| | | { |
| | | foreach (var item in dt_Routers) |
| | | { |
| | | if (item.StartPosi == startPosi && !routers.Any(x => x.Id == item.Id)) |
| | | { |
| | | routers.Add(item); |
| | | } |
| | | else |
| | | { |
| | | List<Dt_Router> tempRouters = QueryNextRoutesInternal(startPosi, item.StartPosi, visitedRoutes); |
| | | foreach (var router in tempRouters) |
| | | { |
| | | if (router.StartPosi == startPosi && !routers.Any(x => x.Id == router.Id)) |
| | | { |
| | | routers.Add(router); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | throw new Exception($"è¯¥è·¯å¾æªé
ç½®æé
ç½®é误,è¯·æ£æ¥è®¾å¤è·¯ç±ä¿¡æ¯,èµ·ç¹:ã{startPosi}ã,ç»ç¹:ã{endPosi}ã"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // è¿éå¯ä»¥æ ¹æ®å®é
éæ±æ´å¥½å°å¤çå¼å¸¸ï¼æ¯å¦è®°å½æ¥å¿çï¼ç®ååªæ¯æ³¨éæäºç´æ¥æåºå¼å¸¸ |
| | | //throw new Exception(ex.Message); |
| | | //è®°å½éè¯¯ä¿¡æ¯ |
| | | } |
| | | return routers; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç¼å·è·å对åºçè·¯ç±ç¹ä½ç¼å·(è¾é线ç«å°ç¼å·)ä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="deviceCode">设å¤ç¼å·</param> |
| | | /// <returns>è¿åè·¯ç±ç¹ä½ç¼å·(è¾é线ç«å°ç¼å·)éå</returns> |
| | | public List<string> QueryAllPositions(string deviceCode) |
| | | { |
| | | List<string> positions = new List<string>(); |
| | | try |
| | | { |
| | | List<string> inRouterPositions = BaseDal.QueryData(x => x.ChildPosiDeviceCode == deviceCode && x.InOutType == RouterInOutType.In).GroupBy(x => x.StartPosi).Select(x => x.Key).ToList(); |
| | | |
| | | List<string> outRouterPositions = BaseDal.QueryData(x => x.ChildPosiDeviceCode == deviceCode && x.InOutType == RouterInOutType.Out).GroupBy(x => x.ChildPosi).Select(x => x.Key).ToList(); |
| | | |
| | | positions.AddRange(inRouterPositions); |
| | | positions.AddRange(outRouterPositions); |
| | | return positions.GroupBy(x => x).Select(x => x.Key).ToList(); |
| | | } |
| | | catch |
| | | { |
| | | |
| | | } |
| | | return positions; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åè·¯ç±è¡¨ä¸ææå®æ´çè·¯ç±ä¿¡æ¯(å端è°ç¨å±ç¤ºæ°æ®)ã |
| | | /// </summary> |
| | | /// <returns>å¿å对象éåã</returns> |
| | | public List<object> GetAllWholeRouters() |
| | | { |
| | | List<object> data = new List<object>(); |
| | | List<Dt_Router> allRouters = BaseDal.QueryData(x => true); |
| | | List<Dt_Router> dt_Routers = allRouters.Where(x => x.IsEnd).OrderBy(x => x.Id).ToList(); |
| | | |
| | | foreach (var item in dt_Routers) |
| | | { |
| | | string routes = $"{item.ChildPosi},"; |
| | | string str = GetPreviousRoutes(item.StartPosi, allRouters, item.InOutType); |
| | | if (!string.IsNullOrEmpty(str)) |
| | | { |
| | | if (str.EndsWith(",")) |
| | | str = str.Substring(0, str.Length - 1); |
| | | routes += str; |
| | | } |
| | | if (item.InOutType == RouterInOutType.In) |
| | | { |
| | | List<string> itemRouters = routes.Split(",").Reverse().ToList(); |
| | | object obj = new { type = RouterInOutType.In, routes = itemRouters }; |
| | | data.Add(obj); |
| | | } |
| | | else |
| | | { |
| | | List<string> itemRouters = routes.Split(",").Reverse().ToList(); |
| | | object obj = new { type = RouterInOutType.Out, routes = itemRouters }; |
| | | data.Add(obj); |
| | | } |
| | | } |
| | | |
| | | return data; |
| | | } |
| | | |
| | | private string GetPreviousRoutes(string startPosi, List<Dt_Router> allRouters, RouterInOutType routerType) |
| | | { |
| | | string routers = string.Empty; |
| | | if (!string.IsNullOrEmpty(startPosi)) |
| | | { |
| | | if (!routers.EndsWith(",")) |
| | | routers += $"{startPosi},"; |
| | | else |
| | | routers += $"{startPosi}"; |
| | | } |
| | | List<Dt_Router> preRouters = allRouters.Where(x => x.NextPosi == startPosi && x.InOutType == routerType).ToList(); |
| | | foreach (var item in preRouters) |
| | | { |
| | | string str = GetPreviousRoutes(item.StartPosi, allRouters, routerType); |
| | | if (!string.IsNullOrEmpty(str)) |
| | | { |
| | | if (routers.EndsWith(",")) |
| | | routers += $"{str}"; |
| | | else |
| | | routers += $"{str},"; |
| | | } |
| | | } |
| | | return routers; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ·»å 宿´è·¯ç±ä¿¡æ¯(å端è°ç¨é
置路ç±ä¿¡æ¯)ã |
| | | /// </summary> |
| | | /// <param name="routersAddDTOs">设å¤è·¯ç±é
置添å DTO</param> |
| | | /// <param name="routerType">è·¯ç±ç±»å</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | public WebResponseContent AddRouters(List<RoutersAddDTO> routersAddDTOs, int routerType) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (routersAddDTOs.GroupBy(x => x.ChildPositionCode).Where(x => !string.IsNullOrEmpty(x.Key)).Select(x => x.Count()).Any(x => x > 1)) |
| | | { |
| | | return content = WebResponseContent.Instance.Error("åä½ç½®ç¼å·éå¤"); |
| | | } |
| | | |
| | | if (routersAddDTOs.GroupBy(x => x.PositionCode).Select(x => x.Count()).Any(x => x > 1)) |
| | | { |
| | | return content = WebResponseContent.Instance.Error("æ ¹ä½ç½®ç¼å·éå¤"); |
| | | } |
| | | List<dynamic> deviceCode = _deviceInfoRepository.QueryTabs<Dt_DeviceInfo, Dt_DeviceProtocol, dynamic>((a, b) => new object[] { JoinType.Inner, a.Id == b.DeviceId }, (a, b) => new { b.DeviceChildCode, a.DeviceCode }, (a, b) => true, x => true).Distinct().ToList(); |
| | | |
| | | List<Dt_Router> routers = new List<Dt_Router>(); |
| | | for (int i = 0; i < routersAddDTOs.Count - 1; i++) |
| | | { |
| | | dynamic obj = deviceCode.FirstOrDefault(x => x.DeviceChildCode == routersAddDTOs[i + 1].PositionCode || x.DeviceChildCode == routersAddDTOs[i + 1].ChildPositionCode); |
| | | Dt_Router router = new Dt_Router() |
| | | { |
| | | ChildPosi = routersAddDTOs[i + 1].PositionCode, |
| | | ChildPosiDeviceCode = obj.DeviceCode, |
| | | Depth = 1, |
| | | InOutType = (RouterInOutType)routerType, |
| | | NextPosi = routersAddDTOs[i + 1].PositionCode, |
| | | SrmColumn = string.IsNullOrEmpty(routersAddDTOs[i].SCColumn) ? int.TryParse(routersAddDTOs[i + 1].SCColumn, out int col) ? col : null : int.TryParse(routersAddDTOs[i].SCColumn, out int col2) ? col2 : null, |
| | | SrmLayer = string.IsNullOrEmpty(routersAddDTOs[i].SCLayer) ? int.TryParse(routersAddDTOs[i + 1].SCLayer, out int lay) ? lay : null : int.TryParse(routersAddDTOs[i].SCLayer, out int lay2) ? lay2 : null, |
| | | SrmRow = string.IsNullOrEmpty(routersAddDTOs[i].SCRow) ? int.TryParse(routersAddDTOs[i + 1].SCRow, out int row) ? row : null : int.TryParse(routersAddDTOs[i].SCRow, out int row2) ? row2 : null, |
| | | StartPosi = routersAddDTOs[i].PositionCode, |
| | | IsEnd = false |
| | | }; |
| | | if (i == routersAddDTOs.Count - 2) |
| | | { |
| | | if (routerType == (int)RouterInOutType.Out) |
| | | router.ChildPosi = routersAddDTOs[i + 1].ChildPositionCode; |
| | | router.IsEnd = true; |
| | | } |
| | | routers.Add(router); |
| | | } |
| | | if (routers.Any(x => x.StartPosi == x.ChildPosi)) |
| | | { |
| | | return content = WebResponseContent.Instance.Error("è¾å
¥æ°æ®èµ·ç¹ä½ç½®ç¼å·ä¸åä½ç½®ç¼å·ç¸å"); |
| | | } |
| | | if (routers.Any(x => x.StartPosi == x.NextPosi)) |
| | | { |
| | | return content = WebResponseContent.Instance.Error("è¾å
¥æ°æ®èµ·ç¹ä½ç½®ç¼å·ä¸ç»ç¹ä½ç½®ç¼å·ç¸å"); |
| | | } |
| | | List<Dt_Router> dt_Routers = BaseDal.QueryData(x => x.InOutType == (RouterInOutType)routerType); |
| | | |
| | | dt_Routers.ForEach(x => |
| | | { |
| | | var t = routers.FirstOrDefault(v => v.StartPosi == x.StartPosi && v.NextPosi == x.NextPosi); |
| | | if (t != null) |
| | | { |
| | | routers.Remove(t); |
| | | } |
| | | var r = routers.FirstOrDefault(v => v.StartPosi == x.StartPosi && v.ChildPosi == x.ChildPosi); |
| | | if (r != null) |
| | | { |
| | | routers.Remove(r); |
| | | } |
| | | }); |
| | | |
| | | BaseDal.AddData(routers); |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¹æ®è®¾å¤ç¼å·è·ååºåºè·¯ç±ç¹ä½ |
| | | /// </summary> |
| | | /// <param name="deviceCode"></param> |
| | | /// <returns></returns> |
| | | public List<string> QueryOutDeviceCodes(string deviceCode) |
| | | { |
| | | List<string> positions = new List<string>(); |
| | | try |
| | | { |
| | | List<string> outRouterPositions = BaseDal.QueryData(x => x.ChildPosiDeviceCode == deviceCode && x.InOutType == RouterInOutType.Out).GroupBy(x => x.ChildPosi).Select(x => x.Key).ToList(); |
| | | |
| | | positions.AddRange(outRouterPositions); |
| | | return positions.GroupBy(x => x).Select(x => x.Key).ToList(); |
| | | } |
| | | catch |
| | | { |
| | | |
| | | } |
| | | return positions; |
| | | } |
| | | } |
| | | } |
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ShuttleCar/IShuttleCar.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ShuttleCar/ShuttleCar.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerCrane.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Common/CommonStackerStationCrane.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Enum/StackerCraneStatus.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/IStackerCrane.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/Spec/SpeStackerCrane.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/StackerCrane/StackerCraneTaskCompletedEventArgs.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Storage.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/WIDESEAWCS_QuartzJob.csproj
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server.sln
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/.config/dotnet-tools.json
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/BasicInfo/Dt_StationManagerController.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/QuartzJob/DeviceProtocolController.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/QuartzJob/SchedulerController.cs (已删除)
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/System/AgvStationController.cs (已删除)
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/System/Sys_DictionaryController.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/System/Sys_LogController.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Controllers/Task/TaskController.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Filter/CustomProfile.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Log/站台读取信息记录/2024-12-23/B202站台241223.txt (已删除)
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Log/站台读取信息记录/2024-12-23/LineJob站台241223.txt (已删除)
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Log/站台读取信息记录/2024-12-23/LineJob错误信息站台241223.txt (已删除)
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Log/站台读取信息记录/2024-12-29/LineJob站台241229.txt (已删除)
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Log/站台读取信息记录/2024-12-29/LineJob错误信息站台241229.txt (已删除)
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Log/站台读取信息记录/2024-12-30/B202站台241230.txt (已删除)
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Log/站台读取信息记录/2024-12-30/LineJob站台241230.txt (已删除)
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Log/站台读取信息记录/2024-12-30/LineJob错误信息站台241230.txt (已删除)
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Properties/PublishProfiles/FolderProfile.pubxml
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Properties/PublishProfiles/FolderProfile1.pubxml
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Server.csproj
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/appsettings.json
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SignalR/GlobalUsing.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SignalR/Hub/ISimpleHub.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SignalR/Hub/SimpleHub.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SignalR/Provider/UserIdProvider.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SignalR/Service/INoticeService.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SignalR/Service/SignalrNoticeService.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SignalR/WIDESEAWCS_SignalR.csproj
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemRepository/WIDESEAWCS_SystemRepository.csproj
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/AgvStationService.cs (已删除)
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_SystemServices/WIDESEAWCS_SystemServices.csproj
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoRepository/TaskRepository.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoRepository/WIDESEAWCS_TaskInfoRepository.csproj
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskExecuteDetailService.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/Task_HtyService.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/WIDESEAWCS_TaskInfoService.csproj
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/ConveyorLineTaskCommand.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/StackerCraneDBName.cs
项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/WIDESEAWCS_Tasks.csproj
项目代码/大屏/package-lock.json
项目代码/大屏/src/views/centerRight1.vue
项目资料/AGV交互协议/AGV RCS --WCS 交互协议表V1.0.docx (已删除)
项目资料/AGV交互协议/PC交互(1).xls
项目资料/AGV交互协议/江西AGV与WCS和输送通信协议 2025.6.10(1).xlsx |