feat(WMS/WCS): 增加机器人历史信息记录
fix(WMS/WCS): 修复前端bug
| | |
| | | let loadingInstance; |
| | | let loadingStatus = false; |
| | | if (process.env.NODE_ENV == 'development') { |
| | | axios.defaults.baseURL = window.webConfig.webApiProduction; |
| | | axios.defaults.baseURL = window.webConfig.webApiBaseUrl; |
| | | } |
| | | else if (process.env.NODE_ENV == 'debug') { |
| | | axios.defaults.baseURL = window.webConfig.webApiBaseUrl; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // 该æ©å±æä»¶ç¨äºä»»å¡åå²é¡µé¢çä¸å¡æ©å±ã
|
| | | // æ¹æ³ç®çï¼ç»ä¸é¢çå表æ¥è¯¢ãä¿ååååå¼¹çªæå¼æ¶çæ©å±å
¥å£ï¼ä¿æä¸é¡¹ç®å
task 页é¢ä¸è´çæ©å±ç¹ã
|
| | | // åæ°å«ä¹ï¼ç±æ¡æ¶æçå½å¨æä¼ å
¥ï¼å
嫿¥è¯¢åæ°ãè¡¨åæ°æ®ãè¡æ°æ®çä¸ä¸æã
|
| | | // è¿åå¼è¯´æï¼è¿å true 代表继ç»é»è®¤è¡ä¸ºï¼è¿å false ä»£è¡¨ä¸æé»è®¤è¡ä¸ºã
|
| | | // å¼å¸¸å¤ç说æï¼å½åæªå¼å
¥å¤é¨è°ç¨ï¼è¥åç»æ°å¢æ¥å£è°ç¨ï¼é卿¹æ³å
è¡¥å
try-catch å¹¶è®°å½å
³é®ä¸å¡åæ°ã
|
| | |
|
| | | let extension = {
|
| | | components: {
|
| | | gridHeader: "",
|
| | | gridBody: "",
|
| | | gridFooter: "",
|
| | | modelHeader: "",
|
| | | modelBody: "",
|
| | | modelFooter: "",
|
| | | },
|
| | | tableAction: "",
|
| | | buttons: { view: [], box: [], detail: [] },
|
| | | methods: {
|
| | | // æ¹æ³ç®çï¼é¡µé¢åå§åæ¶æ§è¡èªå®ä¹é»è¾ã
|
| | | // åæ°ï¼æ ã
|
| | | // è¿åå¼ï¼æ ã
|
| | | onInit() {},
|
| | |
|
| | | // æ¹æ³ç®çï¼é¡µé¢åå§å宿忧è¡èªå®ä¹é»è¾ã
|
| | | // åæ°ï¼æ ã
|
| | | // è¿åå¼ï¼æ ã
|
| | | onInited() {},
|
| | |
|
| | | // æ¹æ³ç®çï¼æ¥è¯¢åå¤çæ¥è¯¢æ¡ä»¶ã
|
| | | // åæ°ï¼param æ¥è¯¢åæ°å¯¹è±¡ã
|
| | | // è¿åå¼ï¼true ç»§ç»æ¥è¯¢ï¼false ç»æ¢æ¥è¯¢ã
|
| | | searchBefore(param) {
|
| | | return true;
|
| | | },
|
| | |
|
| | | // æ¹æ³ç®çï¼æ¥è¯¢åå¤çè¿åç»æã
|
| | | // åæ°ï¼result å端è¿åæ°æ®ã
|
| | | // è¿åå¼ï¼true ç»§ç»æ¸²æï¼false ç»æ¢åç»å¤çã
|
| | | searchAfter(result) {
|
| | | return true;
|
| | | },
|
| | |
|
| | | // æ¹æ³ç®çï¼æ°å¢åæ ¡éªæè¡¥å
æäº¤å段ã
|
| | | // åæ°ï¼formData 表åæäº¤å¯¹è±¡ã
|
| | | // è¿åå¼ï¼true ç»§ç»æäº¤ï¼false ç»æ¢æäº¤ã
|
| | | addBefore(formData) {
|
| | | return true;
|
| | | },
|
| | |
|
| | | // æ¹æ³ç®çï¼ç¼è¾åæ ¡éªæè¡¥å
æäº¤å段ã
|
| | | // åæ°ï¼formData 表åæäº¤å¯¹è±¡ã
|
| | | // è¿åå¼ï¼true ç»§ç»æäº¤ï¼false ç»æ¢æäº¤ã
|
| | | updateBefore(formData) {
|
| | | return true;
|
| | | },
|
| | |
|
| | | // æ¹æ³ç®çï¼ç¹å»è¡æ¶æ©å±å¤çã
|
| | | // åæ°ï¼row è¡æ°æ®ï¼column åé
ç½®ï¼event åå§äºä»¶ã
|
| | | // è¿åå¼ï¼æ ã
|
| | | rowClick({ row, column, event }) {},
|
| | |
|
| | | // æ¹æ³ç®çï¼ç¼è¾å¼¹çªæå¼åæ§è¡æ©å±é»è¾ã
|
| | | // åæ°ï¼row å½åè¡æ°æ®ã
|
| | | // è¿åå¼ï¼æ ã
|
| | | modelOpenAfter(row) {},
|
| | | },
|
| | | };
|
| | |
|
| | | export default extension;
|
| | |
| | | let viewgird = [ |
| | | { |
| | | path: '/Sys_Log', |
| | | name: 'sys_Log', |
| | | component: () => import('@/views/system/Sys_Log.vue') |
| | | path: "/Sys_Log", |
| | | name: "sys_Log", |
| | | component: () => import("@/views/system/Sys_Log.vue"), |
| | | }, |
| | | { |
| | | path: '/Sys_User', |
| | | name: 'Sys_User', |
| | | component: () => import('@/views/system/Sys_User.vue') |
| | | path: "/Sys_User", |
| | | name: "Sys_User", |
| | | component: () => import("@/views/system/Sys_User.vue"), |
| | | }, |
| | | { |
| | | path: '/permission', |
| | | name: 'permission', |
| | | component: () => import('@/views/system/Permission.vue') |
| | | path: "/permission", |
| | | name: "permission", |
| | | component: () => import("@/views/system/Permission.vue"), |
| | | }, |
| | | { |
| | | path: '/Sys_Dictionary', |
| | | name: 'Sys_Dictionary', |
| | | component: () => import('@/views/system/Sys_Dictionary.vue') |
| | | path: "/Sys_Dictionary", |
| | | name: "Sys_Dictionary", |
| | | component: () => import("@/views/system/Sys_Dictionary.vue"), |
| | | }, |
| | | { |
| | | path: '/Sys_Role', |
| | | name: 'Sys_Role', |
| | | component: () => import('@/views/system/Sys_Role.vue') |
| | | path: "/Sys_Role", |
| | | name: "Sys_Role", |
| | | component: () => import("@/views/system/Sys_Role.vue"), |
| | | }, |
| | | { |
| | | path: '/Sys_Role1', |
| | | name: 'Sys_Role1', |
| | | component: () => import('@/views/system/Sys_Role1.vue') |
| | | path: "/Sys_Role1", |
| | | name: "Sys_Role1", |
| | | component: () => import("@/views/system/Sys_Role1.vue"), |
| | | }, |
| | | { |
| | | path: '/Sys_DictionaryList', |
| | | name: 'Sys_DictionaryList', |
| | | component: () => import('@/views/system/Sys_DictionaryList.vue') |
| | | path: "/Sys_DictionaryList", |
| | | name: "Sys_DictionaryList", |
| | | component: () => import("@/views/system/Sys_DictionaryList.vue"), |
| | | }, |
| | | { |
| | | path: '/Sys_Tenant', |
| | | name: 'Sys_Tenant', |
| | | component: () => import('@/views/system/Sys_Tenant.vue') |
| | | path: "/Sys_Tenant", |
| | | name: "Sys_Tenant", |
| | | component: () => import("@/views/system/Sys_Tenant.vue"), |
| | | }, |
| | | { |
| | | path: '/deviceInfo', |
| | | name: 'deviceInfo', |
| | | component: () => import('@/views/quartzJob/deviceInfo.vue') |
| | | path: "/deviceInfo", |
| | | name: "deviceInfo", |
| | | component: () => import("@/views/quartzJob/deviceInfo.vue"), |
| | | }, |
| | | { |
| | | path: '/deviceProtocol', |
| | | name: 'deviceProtocol', |
| | | component: () => import('@/views/quartzJob/deviceProtocol.vue') |
| | | path: "/deviceProtocol", |
| | | name: "deviceProtocol", |
| | | component: () => import("@/views/quartzJob/deviceProtocol.vue"), |
| | | }, |
| | | { |
| | | path: '/deviceProtocolDetail', |
| | | name: 'deviceProtocolDetail', |
| | | component: () => import('@/views/quartzJob/deviceProtocolDetail.vue') |
| | | path: "/deviceProtocolDetail", |
| | | name: "deviceProtocolDetail", |
| | | component: () => import("@/views/quartzJob/deviceProtocolDetail.vue"), |
| | | }, |
| | | { |
| | | path: '/dispatchInfo', |
| | | name: 'dispatchInfo', |
| | | component: () => import('@/views/quartzJob/dispatchInfo.vue') |
| | | path: "/dispatchInfo", |
| | | name: "dispatchInfo", |
| | | component: () => import("@/views/quartzJob/dispatchInfo.vue"), |
| | | }, |
| | | { |
| | | path: '/scheduler', |
| | | name: 'scheduler', |
| | | component: () => import('@/views/quartzJob/scheduler.vue') |
| | | },{ |
| | | path: '/robotTask', |
| | | name: 'robotTask', |
| | | component: () => import('@/views/taskinfo/robotTask.vue') |
| | | path: "/scheduler", |
| | | name: "scheduler", |
| | | component: () => import("@/views/quartzJob/scheduler.vue"), |
| | | }, |
| | | { |
| | | path: '/robotState', |
| | | name: 'robotState', |
| | | component: () => import('@/views/taskinfo/robotState.vue') |
| | | path: "/robotTask", |
| | | name: "robotTask", |
| | | component: () => import("@/views/taskinfo/robotTask.vue"), |
| | | }, |
| | | { |
| | | path: '/task', |
| | | name: 'task', |
| | | component: () => import('@/views/taskinfo/task.vue') |
| | | },{ |
| | | path: '/agvTask', |
| | | name: 'agvTask', |
| | | component: () => import('@/views/taskinfo/agvTask.vue') |
| | | path: "/robotTaskHty", |
| | | name: "robotTaskHty", |
| | | component: () => import("@/views/taskinfo/robotTaskHty.vue"), |
| | | }, |
| | | { |
| | | path: '/taskHty', |
| | | name: 'taskHty', |
| | | component: () => import('@/views/taskinfo/taskHty.vue') |
| | | path: "/robotState", |
| | | name: "robotState", |
| | | component: () => import("@/views/taskinfo/robotState.vue"), |
| | | }, |
| | | { |
| | | path: '/router', |
| | | name: 'router', |
| | | component: () => import('@/views/basicinfo/router.vue') |
| | | } |
| | | path: "/task", |
| | | name: "task", |
| | | component: () => import("@/views/taskinfo/task.vue"), |
| | | }, |
| | | { |
| | | path: "/agvTask", |
| | | name: "agvTask", |
| | | component: () => import("@/views/taskinfo/agvTask.vue"), |
| | | }, |
| | | { |
| | | path: "/taskHty", |
| | | name: "taskHty", |
| | | component: () => import("@/views/taskinfo/taskHty.vue"), |
| | | }, |
| | | { |
| | | path: "/router", |
| | | name: "router", |
| | | component: () => import("@/views/basicinfo/router.vue"), |
| | | }, |
| | | ]; |
| | | |
| | | export default viewgird; |
| | |
| | | export default defineComponent({ |
| | | setup() { |
| | | const table = ref({ |
| | | key: "Id", |
| | | key: "id", |
| | | footer: "Foots", |
| | | cnName: "æºæ¢°æç¶æç®¡ç", |
| | | name: "robotState", |
| | | url: "/robotState/", |
| | | sortName: "IPAddress", |
| | | url: "/RobotState/", |
| | | sortName: "CreateDate", |
| | | }); |
| | | |
| | | // ç¼è¾è¡¨ååæ®µ |
| | | const editFormFields = ref({ |
| | | IPAddress: "", |
| | | Version: "", |
| | | IsEventSubscribed: false, |
| | | RobotRunMode: "", |
| | | RobotControlMode: "", |
| | | RobotArmObject: "", |
| | | Homed: "", |
| | | CurrentAction: "", |
| | | OperStatus: "", |
| | | RobotTaskTotalNum: 0, |
| | | IsSplitPallet: false, |
| | | IsGroupPallet: false, |
| | | IsInFakeBatteryMode: false, |
| | | CurrentBatchIndex: 1, |
| | | ChangePalletPhase: 0, |
| | | IsScanNG: false, |
| | | BatteryArrived: false, |
| | | id: "", |
| | | ipAddress: "", |
| | | version: "", |
| | | isEventSubscribed: false, |
| | | robotRunMode: "", |
| | | robotControlMode: "", |
| | | robotArmObject: "", |
| | | homed: "", |
| | | currentAction: "", |
| | | operStatus: "", |
| | | robotTaskTotalNum: 0, |
| | | isSplitPallet: false, |
| | | isGroupPallet: false, |
| | | isInFakeBatteryMode: false, |
| | | currentBatchIndex: 1, |
| | | changePalletPhase: 0, |
| | | isScanNG: false, |
| | | batteryArrived: false, |
| | | }); |
| | | |
| | | // ç¼è¾è¡¨åé
ç½® |
| | | const editFormOptions = ref([ |
| | | [ |
| | | { title: "IPå°å", field: "ipAddress", type: "string", readonly: true }, |
| | | { title: "çæ¬å·", field: "version", type: "int", readonly: true }, |
| | | ], |
| | | // [ |
| | | // { title: "IPå°å", field: "ipAddress", type: "string", readonly: true }, |
| | | // { title: "çæ¬å·", field: "version", type: "int", readonly: true }, |
| | | // ], |
| | | [ |
| | | { |
| | | title: "è¿è¡æ¨¡å¼", |
| | |
| | | { key: 2, value: "èªå¨æ¨¡å¼" }, |
| | | ], |
| | | }, |
| | | // { |
| | | // title: "æ§å¶æ¨¡å¼", |
| | | // field: "robotControlMode", |
| | | // type: "select", |
| | | // data: [ |
| | | // { key: 1, value: "客æ·ç«¯æ§å¶" }, |
| | | // { key: 2, value: "å
¶ä»" }, |
| | | // ], |
| | | // }, |
| | | // { |
| | | // title: "æèç¶æ", |
| | | // field: "robotArmObject", |
| | | // type: "select", |
| | | // data: [ |
| | | // { key: 0, value: "空é²" }, |
| | | // { key: 1, value: "æç©æ" }, |
| | | // ], |
| | | // }, |
| | | { |
| | | title: "æ§å¶æ¨¡å¼", |
| | | field: "robotControlMode", |
| | | type: "select", |
| | | title: "åé¶ç¶æ", field: "homed", type: "select", |
| | | data: [ |
| | | { key: 1, value: "客æ·ç«¯æ§å¶" }, |
| | | { key: 2, value: "å
¶ä»" }, |
| | | ], |
| | | { key: "Homed", value: "å·²ç»åé¶" }, |
| | | { key: "Homing", value: "æ£å¨åé¶" }, |
| | | ] |
| | | }, |
| | | { |
| | | title: "æèç¶æ", |
| | | field: "robotArmObject", |
| | | type: "select", |
| | | title: "å½åå¨ä½", field: "currentAction", type: "select", |
| | | data: [ |
| | | { key: 0, value: "空é²" }, |
| | | { key: 1, value: "æç©æ" }, |
| | | ], |
| | | { key: "Picking", value: "æ£å¨åè´§" }, |
| | | { key: "Putting", value: "æ£å¨æ¾è´§" }, |
| | | { key: "AllPickFinished", value: "å
¨é¨åè´§å®æ" }, |
| | | { key: "AllPutFinished", value: "å
¨é¨æ¾è´§å®æ" }, |
| | | { key: "PickFinished", value: "åè´§å®æ" }, |
| | | { key: "PutFinished", value: "æ¾è´§å®æ" }, |
| | | ] |
| | | }, |
| | | ], |
| | | [ |
| | | { title: "åé¶ç¶æ", field: "homed", type: "string" }, |
| | | { title: "å½åå¨ä½", field: "currentAction", type: "string" }, |
| | | { title: "è¿è¡ç¶æ", field: "operStatus", type: "string" }, |
| | | // ], |
| | | // [ |
| | | |
| | | // { title: "è¿è¡ç¶æ", field: "operStatus", type: "string" }, |
| | | ], |
| | | [ |
| | | { title: "任塿»æ°", field: "robotTaskTotalNum", type: "int" }, |
| | |
| | | dataKey: "isTrue", |
| | | data: [], |
| | | }, |
| | | { |
| | | title: "æ¶æ¯å·²è®¢é
", |
| | | field: "isEventSubscribed", |
| | | type: "select", |
| | | dataKey: "isTrue", |
| | | data: [], |
| | | }, |
| | | // { |
| | | // title: "æ¶æ¯å·²è®¢é
", |
| | | // field: "isEventSubscribed", |
| | | // type: "select", |
| | | // dataKey: "isTrue", |
| | | // data: [], |
| | | // }, |
| | | ], |
| | | ]); |
| | | |
| | | // æç´¢è¡¨ååæ®µ |
| | | const searchFormFields = ref({ |
| | | IPAddress: "", |
| | | CurrentAction: "", |
| | | OperStatus: "", |
| | | ipAddress: "", |
| | | currentAction: "", |
| | | operStatus: "", |
| | | }); |
| | | |
| | | // æç´¢è¡¨åé
ç½® |
| | | const searchFormOptions = ref([ |
| | | [ |
| | | { title: "IPå°å", field: "ipAddress", type: "string" }, |
| | | { title: "IPå°å", field: "ipAddress", type: "like" }, |
| | | { title: "å½åå¨ä½", field: "currentAction", type: "string" }, |
| | | { title: "è¿è¡ç¶æ", field: "operStatus", type: "string" }, |
| | | { |
| | | title: "è¿è¡ç¶æ", field: "operStatus", type: "select", |
| | | data: [ |
| | | { key: "Picking", value: "æ£å¨åè´§" }, |
| | | { key: "Putting", value: "æ£å¨æ¾è´§" }, |
| | | { key: "AllPickFinished", value: "å
¨é¨åè´§å®æ" }, |
| | | { key: "AllPutFinished", value: "å
¨é¨æ¾è´§å®æ" }, |
| | | { key: "PickFinished", value: "åè´§å®æ" }, |
| | | { key: "PutFinished", value: "æ¾è´§å®æ" }, |
| | | ] |
| | | }, |
| | | ], |
| | | ]); |
| | | |
| | | // åå®ä¹ |
| | | const columns = ref([ |
| | | { field: "ipAddress", title: "IPå°å", type: "string", width: 140, align: "left" }, |
| | | { field: "id", title: "Id", type: "int", width: 90, hidden: true, readonly: true, require: true, align: "left" }, |
| | | { field: "ipAddress", title: "IPå°å", type: "string", width: 160, align: "left" }, |
| | | { field: "version", title: "çæ¬", type: "int", width: 80, align: "left" }, |
| | | { field: "robotRunMode", title: "è¿è¡æ¨¡å¼", type: "int", width: 100, bind: { key: "robotRunMode", data: [{ key: 1, value: "æå¨æ¨¡å¼" }, { key: 2, value: "èªå¨æ¨¡å¼" }] }, align: "center" }, |
| | | { field: "robotControlMode", title: "æ§å¶æ¨¡å¼", type: "int", width: 100, bind: { key: "robotControlMode", data: [{ key: 1, value: "客æ·ç«¯æ§å¶" }, { key: 2, value: "å
¶ä»" }] }, align: "center" }, |
| | | { field: "robotArmObject", title: "æèç¶æ", type: "int", width: 90, bind: { key: "robotArmObject", data: [{ key: 0, value: "空é²" }, { key: 1, value: "æç©æ" }] }, align: "center" }, |
| | | // { field: "robotControlMode", title: "æ§å¶æ¨¡å¼", type: "int", width: 100, bind: { key: "robotControlMode", data: [{ key: 1, value: "客æ·ç«¯æ§å¶" }, { key: 2, value: "å
¶ä»" }] }, align: "center" }, |
| | | // { field: "robotArmObject", title: "æèç¶æ", type: "int", width: 90, bind: { key: "robotArmObject", data: [{ key: 0, value: "空é²" }, { key: 1, value: "æç©æ" }] }, align: "center" }, |
| | | { field: "homed", title: "åé¶ç¶æ", type: "string", width: 100, align: "center", bind: { key: "homed", data: [{ key: "Homed", value: "åé¶" }, { key: "Homing", value: "åé¶ä¸" }] }, }, |
| | | { field: "currentAction", title: "å½åå¨ä½", type: "string", width: 100, align: "center", bind: { key: "currentAction", data: [{ key: "Picking", value: "æ£å¨åè´§" }, { key: "Putting", value: "æ£å¨æ¾è´§" }, { key: "AllPickFinished", value: "å
¨é¨åè´§å®æ" }, { key: "AllPutFinished", value: "å
¨é¨æ¾è´§å®æ" }, { key: "PickFinished", value: "åè´§å®æ" }, { key: "PutFinished", value: "æ¾è´§å®æ" }] }, }, |
| | | { field: "operStatus", title: "è¿è¡ç¶æ", type: "string", width: 100, align: "center", hidden: true }, |
| | | // { field: "operStatus", title: "è¿è¡ç¶æ", type: "string", width: 100, align: "center", hidden: true }, |
| | | { field: "robotTaskTotalNum", title: "任塿»æ°", type: "int", width: 90, align: "center" }, |
| | | { field: "isSplitPallet", title: "æç", type: "byte", width: 60, align: "center", bind: { key: "isTrue", data: [] }, }, |
| | | { field: "isGroupPallet", title: "ç»ç", type: "byte", width: 60, align: "center" , bind: { key: "isTrue", data: [] }, }, |
| | | { field: "isInFakeBatteryMode", title: "åçµè¯", type: "byte", width: 70, align: "center" , bind: { key: "isTrue", data: [] }, }, |
| | | { field: "isGroupPallet", title: "ç»ç", type: "byte", width: 60, align: "center", bind: { key: "isTrue", data: [] }, }, |
| | | { field: "isInFakeBatteryMode", title: "åçµè¯", type: "byte", width: 70, align: "center", bind: { key: "isTrue", data: [] }, }, |
| | | { field: "currentBatchIndex", title: "æ¹æ¬¡", type: "int", width: 60, align: "center" }, |
| | | { field: "changePalletPhase", title: "æ¢çé¶æ®µ", type: "int", width: 80, align: "center" }, |
| | | { field: "isScanNG", title: "æ«ç NG", type: "byte", width: 80, align: "center" , bind: { key: "isTrue", data: [] }, }, |
| | | { field: "batteryArrived", title: "çµè¯å°ä½", type: "byte", width: 80, align: "center" , bind: { key: "isTrue", data: [] }, }, |
| | | { field: "isEventSubscribed", title: "已订é
", type: "byte", width: 70, align: "center", bind: { key: "isTrue", data: [] }, }, |
| | | { field: "isScanNG", title: "æ«ç NG", type: "byte", width: 80, align: "center", bind: { key: "isTrue", data: [] }, }, |
| | | { field: "batteryArrived", title: "çµè¯å°ä½", type: "byte", width: 80, align: "center", bind: { key: "isTrue", data: [] }, }, |
| | | // { field: "isEventSubscribed", title: "已订é
", type: "byte", width: 70, align: "center", bind: { key: "isTrue", data: [] }, }, |
| | | ]); |
| | | |
| | | const detail = ref({ |
| | |
| | | field: "robotRoadway", |
| | | title: "å··é", |
| | | type: "string", |
| | | width: 100, |
| | | width: 120, |
| | | align: "left", |
| | | }, |
| | | { |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <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/taskinfo/robotTaskHty.jsx";
|
| | | import { ref, defineComponent } from "vue";
|
| | |
|
| | | export default defineComponent({
|
| | | setup() {
|
| | | const table = ref({
|
| | | key: "robotTaskId", // 主é®å段å
|
| | | footer: "Foots",
|
| | | cnName: "æºå¨äººåå²ä»»å¡", // 䏿åç§°
|
| | | name: "robotTaskHty", // 表å
|
| | | url: "/RobotTask_Hty/", // APIè·¯å¾
|
| | | sortName: "insertTime", // é»è®¤æåºåæ®µï¼æç§»å
¥æ¶é´æåºï¼
|
| | | });
|
| | |
|
| | | // ç¼è¾è¡¨ååæ®µï¼åå²è¡¨é常åªè¯»ï¼ä½ä¿çç»æï¼
|
| | | const editFormFields = ref({});
|
| | |
|
| | | // ç¼è¾è¡¨åé
ç½®ï¼åå²è¡¨é常åªè¯»ï¼
|
| | | const editFormOptions = ref([]);
|
| | |
|
| | | // æç´¢è¡¨ååæ®µ
|
| | | const searchFormFields = ref({
|
| | | robotTaskNum: "",
|
| | | robotRoadway: "",
|
| | | robotTaskType: "",
|
| | | robotTaskState: "",
|
| | | robotSourceAddress: "",
|
| | | robotTargetAddress: "",
|
| | | operateType: "",
|
| | | insertTime: "",
|
| | | creater: "",
|
| | | createDate: "",
|
| | | });
|
| | |
|
| | | // æç´¢è¡¨åé
ç½®ï¼ä¸è¡å¸å±ï¼
|
| | | const searchFormOptions = ref([
|
| | | [
|
| | | { title: "ä»»å¡ç¼å·", field: "robotTaskNum", type: "int" },
|
| | | { title: "å··é", field: "robotRoadway", type: "like" },
|
| | | {
|
| | | title: "ä»»å¡ç±»å",
|
| | | field: "robotTaskType",
|
| | | type: "selectList",
|
| | | dataKey: "taskType",
|
| | | data: [],
|
| | | },
|
| | | {
|
| | | title: "ä»»å¡ç¶æ",
|
| | | field: "robotTaskState",
|
| | | type: "selectList",
|
| | | dataKey: "taskState",
|
| | | data: [],
|
| | | },
|
| | | ],
|
| | | [
|
| | | { title: "æ¥æºå°å", field: "robotSourceAddress", type: "like" },
|
| | | { title: "ç®æ å°å", field: "robotTargetAddress", type: "like" },
|
| | | { title: "æä½ç±»å", field: "operateType", type: "like" },
|
| | | { title: "ç§»å
¥å岿¶é´", field: "insertTime", type: "datetime" },
|
| | | ],
|
| | | [
|
| | | { title: "æ¥æºçº¿ä»£ç ", field: "robotSourceAddressLineCode", type: "like" },
|
| | | { title: "ç®æ 线代ç ", field: "robotTargetAddressLineCode", type: "like" },
|
| | | { title: "å建人", field: "creater", type: "like" },
|
| | | { title: "å建æ¶é´", field: "createDate", type: "datetime" },
|
| | | ],
|
| | | ]);
|
| | |
|
| | | // åé
ç½®
|
| | | const columns = ref([
|
| | | {
|
| | | field: "robotTaskId",
|
| | | title: "åå²ID",
|
| | | type: "int",
|
| | | width: 90,
|
| | | hidden: true, // éèåå²è¡¨ä¸»é®
|
| | | readonly: true,
|
| | | require: true,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "sourceId",
|
| | | title: "ä»»å¡å·",
|
| | | type: "int",
|
| | | width: 100,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "robotTaskNum",
|
| | | title: "ä»»å¡ç¼å·",
|
| | | type: "int",
|
| | | width: 100,
|
| | | align: "left",
|
| | | sortable: true,
|
| | | },
|
| | | {
|
| | | field: "robotRoadway",
|
| | | title: "å··é",
|
| | | type: "string",
|
| | | width: 120,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "robotTaskType",
|
| | | title: "ä»»å¡ç±»å",
|
| | | type: "int",
|
| | | width: 100,
|
| | | align: "left",
|
| | | bind: { key: "taskType", data: [] },
|
| | | },
|
| | | {
|
| | | field: "robotTaskState",
|
| | | title: "ä»»å¡ç¶æ",
|
| | | type: "int",
|
| | | width: 120,
|
| | | align: "left",
|
| | | bind: { key: "taskState", data: [] },
|
| | | },
|
| | | {
|
| | | field: "robotTaskTotalNum",
|
| | | title: "任塿»æ°",
|
| | | type: "int",
|
| | | width: 90,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "robotSourceAddress",
|
| | | title: "æ¥æºå°å",
|
| | | type: "string",
|
| | | width: 120,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "robotTargetAddress",
|
| | | title: "ç®æ å°å",
|
| | | type: "string",
|
| | | width: 120,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "robotSourceAddressLineCode",
|
| | | title: "æ¥æºçº¿ä½å°å",
|
| | | type: "string",
|
| | | width: 130,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "robotTargetAddressLineCode",
|
| | | title: "ç®æ 线ä½å°å",
|
| | | type: "string",
|
| | | width: 130,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "robotSourceAddressPalletCode",
|
| | | title: "æ¥æºæç",
|
| | | type: "string",
|
| | | width: 130,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "robotTargetAddressPalletCode",
|
| | | title: "ç®æ æç",
|
| | | type: "string",
|
| | | width: 130,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "robotExceptionMessage",
|
| | | title: "å¼å¸¸ä¿¡æ¯",
|
| | | type: "string",
|
| | | width: 200,
|
| | | align: "left",
|
| | | overflow: "ellipsis",
|
| | | tooltip: true, // é¼ æ æ¬åæ¾ç¤ºå®æ´å
容
|
| | | },
|
| | | {
|
| | | field: "robotGrade",
|
| | | title: "ä¼å
级",
|
| | | type: "int",
|
| | | width: 80,
|
| | | align: "left",
|
| | | bind: {
|
| | | key: "robotGrade",
|
| | | data: [
|
| | | { id: 1, name: "ä½" },
|
| | | { id: 2, name: "æ®é" },
|
| | | { id: 3, name: "é«" },
|
| | | { id: 4, name: "ç´§æ¥" },
|
| | | ],
|
| | | },
|
| | | },
|
| | | {
|
| | | field: "operateType",
|
| | | title: "æä½ç±»å",
|
| | | type: "string",
|
| | | width: 120,
|
| | | align: "left",
|
| | | sortable: true,
|
| | | },
|
| | | {
|
| | | field: "insertTime",
|
| | | title: "ç§»å
¥å岿¶é´",
|
| | | type: "datetime",
|
| | | width: 170,
|
| | | align: "left",
|
| | | sortable: true,
|
| | | },
|
| | | {
|
| | | field: "robotDispatchertime",
|
| | | title: "è°åº¦æ¶é´",
|
| | | type: "datetime",
|
| | | width: 160,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "robotRemark",
|
| | | title: "夿³¨",
|
| | | type: "string",
|
| | | width: 150,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "creater",
|
| | | title: "å建人",
|
| | | type: "string",
|
| | | width: 100,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "createDate",
|
| | | title: "å建æ¶é´",
|
| | | type: "datetime",
|
| | | width: 160,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "modifier",
|
| | | title: "ä¿®æ¹äºº",
|
| | | type: "string",
|
| | | width: 100,
|
| | | align: "left",
|
| | | },
|
| | | {
|
| | | field: "modifyDate",
|
| | | title: "ä¿®æ¹æ¶é´",
|
| | | type: "datetime",
|
| | | width: 160,
|
| | | align: "left",
|
| | | },
|
| | | ]);
|
| | |
|
| | | // 详æ
å¼¹çªé
ç½®
|
| | | const detail = ref({
|
| | | cnName: "æºå¨äººåå²ä»»å¡è¯¦æ
",
|
| | | table: "robotTaskHty",
|
| | | key: "robotTaskId",
|
| | | sortName: "insertTime",
|
| | | columns: columns.value.filter(col => !col.hidden), // 使ç¨ééèåæ®µ
|
| | | });
|
| | |
|
| | | return {
|
| | | table,
|
| | | extend,
|
| | | editFormFields,
|
| | | editFormOptions,
|
| | | searchFormFields,
|
| | | searchFormOptions,
|
| | | columns,
|
| | | detail,
|
| | | };
|
| | | },
|
| | | });
|
| | | </script> |
| | |
| | | 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>转æ¢åçæ¬å°DateTime对象</returns> |
| | | /// <remarks>å¦æåæ°ä¸ºnullï¼åè¿åé»è®¤èµ·å§æ¥æ</remarks> |
| | | 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; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°å¯¹è±¡åºåå为JSONå符串 |
| | | /// </summary> |
| | | /// <param name="obj">è¦åºååç对象</param> |
| | | /// <param name="formatDate">æ¥ææ ¼å¼å设置ï¼é»è®¤ä¸º"yyyy-MM-dd HH:mm:ss"æ ¼å¼</param> |
| | | /// <returns>åºåååçJSONå符串ï¼å¦æå¯¹è±¡ä¸ºnullåè¿ånull</returns> |
| | | 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); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°JSONå符串ååºåå为æå®ç±»åç对象 |
| | | /// </summary> |
| | | /// <typeparam name="T">ç®æ 对象类å</typeparam> |
| | | /// <param name="json">è¦ååºååçJSONå符串</param> |
| | | /// <returns>ååºåååç对象å®ä¾ï¼å¦æè¾å
¥ä¸ºç©ºåè¿åé»è®¤å¼</returns> |
| | | /// <remarks> |
| | | /// å½è¾å
¥ä¸º"{}"æ¶ä¼èªå¨è½¬æ¢ä¸º"[]"å¤ç |
| | | /// </remarks> |
| | | public static T DeserializeObject<T>(this string json) |
| | | { |
| | | if (string.IsNullOrEmpty(json)) |
| | | { |
| | | return default(T); |
| | | } |
| | | if (json == "{}") |
| | | { |
| | | json = "[]"; |
| | | } |
| | | return JsonConvert.DeserializeObject<T>(json); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°å符串çé¦åæ¯è½¬æ¢ä¸ºå°å |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦å¤ççå符串</param> |
| | | /// <returns>é¦åæ¯å°åçå符串ï¼è¥è¾å
¥ä¸ºç©ºåè¿å空å符串</returns> |
| | | 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; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°å符串çé¦åæ¯è½¬æ¢ä¸ºå¤§å |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦å¤ççå符串</param> |
| | | /// <returns>é¦åæ¯å¤§åçå符串ï¼è¥è¾å
¥ä¸ºç©ºåè¿å空å符串</returns> |
| | | 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>转æ¢åçæ´åå¼ï¼è½¬æ¢å¤±è´¥è¿å0</returns> |
| | | /// <remarks> |
| | | /// æ¯æå¤çnullå¼ãDBNull.Valueåæä¸¾ç±»å |
| | | /// </remarks> |
| | | public static int ObjToInt(this object thisValue) |
| | | { |
| | | int reval = 0; |
| | | if (thisValue == null) return 0; |
| | | if (thisValue is Enum && thisValue != DBNull.Value && Enum.TryParse(thisValue.GetType(), thisValue.ToString(), out var val)) |
| | | { |
| | | return Convert.ToInt32(val.ChangeType(typeof(int))); |
| | | } |
| | | if (thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval)) |
| | | { |
| | | return reval; |
| | | } |
| | | |
| | | return reval; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°åç²¾åº¦æµ®ç¹æ°è½¬æ¢ä¸º32ä½æç¬¦å·æ´æ° |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦è½¬æ¢çåç²¾åº¦æµ®ç¹æ°</param> |
| | | /// <returns>转æ¢åç32ä½æç¬¦å·æ´æ°</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; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºé¿æ´å(long) |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param> |
| | | /// <returns>转æ¢åçé¿æ´åå¼ï¼è½¬æ¢å¤±è´¥æä¸ºnullæ¶è¿å0</returns> |
| | | /// <remarks> |
| | | /// å¤çDBNull.Valueæ
åµï¼å¹¶å°è¯å°å¯¹è±¡è½¬æ¢ä¸ºlongç±»å |
| | | /// </remarks> |
| | | 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> |
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºéé¢(doubleç±»å)ãè¥è½¬æ¢å¤±è´¥åè¿å0ã |
| | | /// </summary> |
| | | /// <param name="thisValue">å¾
转æ¢ç对象</param> |
| | | /// <returns>转æ¢åçéé¢å¼ï¼å¤±è´¥è¿å0</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> |
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºéé¢(double)ç±»åï¼è½¬æ¢å¤±è´¥æ¶è¿åæå®çéè¯¯å¼ |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param> |
| | | /// <param name="errorValue">转æ¢å¤±è´¥æ¶è¿åçé»è®¤å¼</param> |
| | | /// <returns>è½¬æ¢æåçdouble弿æå®çé误å¼</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> |
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºå符串ï¼è¥å¯¹è±¡ä¸ºnullåè¿å空å符串 |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param> |
| | | /// <returns>å»é¤ååç©ºæ ¼çåç¬¦ä¸²ç»æ</returns> |
| | | public static string ObjToString(this object thisValue) |
| | | { |
| | | if (thisValue != null) return thisValue.ToString().Trim(); |
| | | return ""; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤æå¯¹è±¡æ¯å¦ä¸ä¸ºç©ºænullå¼ |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦å¤æç对象</param> |
| | | /// <returns>å½å¯¹è±¡ä¸ä¸ºç©ºä¸ä¸çäº"undefined"æ"null"å符串æ¶è¿åtrueï¼å¦åè¿åfalse</returns> |
| | | public static bool IsNotEmptyOrNull(this object thisValue) |
| | | { |
| | | return ObjToString(thisValue) != "" && ObjToString(thisValue) != "undefined" && ObjToString(thisValue) != "null"; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºå符串ï¼å¦æå¯¹è±¡ä¸ºnullåè¿åæå®çéè¯¯å¼ |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param> |
| | | /// <param name="errorValue">å½å¯¹è±¡ä¸ºnullæ¶è¿åçå¼</param> |
| | | /// <returns>对象çå符串表示ææå®çé误å¼</returns> |
| | | public static string ObjToString(this object thisValue, string errorValue) |
| | | { |
| | | if (thisValue != null) return thisValue.ToString().Trim(); |
| | | return errorValue; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤æå¯¹è±¡æ¯å¦ä¸ºnullãDBNullæç©ºå符串 |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦æ£æ¥ç对象</param> |
| | | /// <returns>å¦æå¯¹è±¡ä¸ºnullãDBNullæç©ºå符串åè¿åtrueï¼å¦åè¿åfalse</returns> |
| | | public static bool IsNullOrEmpty(this object thisValue) => thisValue == null || thisValue == DBNull.Value || string.IsNullOrWhiteSpace(thisValue.ToString()); |
| | | |
| | | /// <summary> |
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºDecimalç±»å |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param> |
| | | /// <returns>转æ¢åçDecimalå¼ï¼è½¬æ¢å¤±è´¥è¿å0</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> |
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºDecimalç±»åï¼è¥è½¬æ¢å¤±è´¥åè¿åæå®çé»è®¤å¼ |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param> |
| | | /// <param name="errorValue">转æ¢å¤±è´¥æ¶è¿åçé»è®¤å¼</param> |
| | | /// <returns>è½¬æ¢æåçDecimal弿æå®çé»è®¤å¼</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> |
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºDateTimeç±»å |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param> |
| | | /// <returns>转æ¢åçDateTimeå¼ï¼è½¬æ¢å¤±è´¥è¿åDateTime.MinValue</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> |
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºDateTimeç±»åï¼è½¬æ¢å¤±è´¥æ¶è¿åæå®çé»è®¤å¼ |
| | | /// </summary> |
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param> |
| | | /// <param name="errorValue">转æ¢å¤±è´¥æ¶è¿åçé»è®¤å¼</param> |
| | | /// <returns>è½¬æ¢æåçDateTime弿æå®çé»è®¤å¼</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>转æ¢åçå¸å°å¼ï¼è½¬æ¢å¤±è´¥æ¶è¿åfalse</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> |
| | | /// å°DateTime转æ¢ä¸ºUnixæ¶é´æ³ï¼ç§çº§ï¼ |
| | | /// </summary> |
| | | /// <param name="thisValue">éè¦è½¬æ¢çDateTime对象</param> |
| | | /// <returns>è¿å表示Unixæ¶é´æ³çå符串</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(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºæå®ç±»å |
| | | /// </summary> |
| | | /// <param name="value">è¦è½¬æ¢ç对象</param> |
| | | /// <param name="type">ç®æ ç±»å</param> |
| | | /// <returns>转æ¢åç对象</returns> |
| | | /// <remarks> |
| | | /// æ¯æå¤çnullå¼ãæä¸¾ç±»åãæ³åç±»åãGuidãVersionçç¹æ®ç±»åç转æ¢ã |
| | | /// å¦æè½¬æ¢å¤±è´¥æç±»åä¸å¹é
ï¼å°è¿ååå§å¼ææåºå¼å¸¸ã |
| | | /// </remarks> |
| | | 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); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°å¯¹è±¡å¼è½¬æ¢ä¸ºæå®ç±»åçæ³åå表ã |
| | | /// </summary> |
| | | /// <param name="value">å¾
转æ¢ç对象å¼</param> |
| | | /// <param name="type">ç®æ å表å
ç´ ç±»å</param> |
| | | /// <returns>转æ¢åçæ³åå表对象ï¼è¥è¾å
¥ä¸ºnullåè¿åé»è®¤å¼</returns> |
| | | /// <remarks> |
| | | /// æ¯æå¤ç以æ¬å·å
裹çåç¬¦ä¸²æ ¼å¼ï¼å¦"(1,2,3)"æ"("a","b")"ï¼ï¼ |
| | | /// èªå¨å»é¤åé符并å°å
ç´ è½¬æ¢ä¸ºç®æ ç±»ååæ·»å å°å表ã |
| | | /// </remarks> |
| | | 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; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°å¯¹è±¡åºåå为JSONå符串 |
| | | /// </summary> |
| | | /// <param name="value">è¦åºååç对象</param> |
| | | /// <returns>对象çJSONå符串表示</returns> |
| | | public static string ToJson(this object value) |
| | | { |
| | | return JsonConvert.SerializeObject(value); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤æå¯¹è±¡æ¯å¦å¯ä»¥è½¬æ¢ä¸ºæ´æ° |
| | | /// </summary> |
| | | /// <param name="obj">è¦å¤æç对象</param> |
| | | /// <returns>妿å¯ä»¥è½¬æ¢ä¸ºæ´æ°è¿åtrueï¼å¦åè¿åfalse</returns> |
| | | public static bool IsInt(this object obj) |
| | | { |
| | | if (obj == null) |
| | | return false; |
| | | bool reslut = Int32.TryParse(obj.ToString(), out int _number); |
| | | return reslut; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤æå¯¹è±¡æ¯å¦ä¸ºæææ¥ææ ¼å¼ |
| | | /// </summary> |
| | | /// <param name="str">å¾
æ£æµç对象</param> |
| | | /// <returns>trueè¡¨ç¤ºæ¯æææ¥æï¼falseå䏿¯</returns> |
| | | /// <remarks>æ¤æ¹æ³æ¯æ©å±æ¹æ³ï¼éè¿è°ç¨IsDate(out _)å®ç°</remarks> |
| | | public static bool IsDate(this object str) |
| | | { |
| | | return str.IsDate(out _); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤æå¯¹è±¡æ¯å¦å¯ä»¥è½¬æ¢ä¸ºææçæ¥ææ¶é´ |
| | | /// </summary> |
| | | /// <param name="str">è¦å¤æç对象</param> |
| | | /// <param name="dateTime">è¾åºè½¬æ¢åçæ¥ææ¶é´å¼</param> |
| | | /// <returns>å¦æè½¬æ¢æåè¿åtrueï¼å¦åè¿åfalse</returns> |
| | | 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">æ ¼å¼åç¬¦ä¸²ï¼æªä½¿ç¨ï¼</param> |
| | | /// <returns>妿å符串å¯ä»¥è½¬æ¢ä¸ºæ°ååè¿åtrueï¼å¦åè¿åfalse</returns> |
| | | /// <remarks> |
| | | /// ä½¿ç¨æ£å表达å¼éªè¯å符串æ¯å¦ä¸ºæ°åæ ¼å¼ï¼æ¯ææ£è´å·åå°æ°ç¹ |
| | | /// </remarks> |
| | | public static bool IsNumber(this string str, string formatString) |
| | | { |
| | | if (string.IsNullOrEmpty(str)) return false; |
| | | |
| | | return Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 夿å符串æ¯å¦ä¸ºææçGuidæ ¼å¼ |
| | | /// </summary> |
| | | /// <param name="guid">è¦éªè¯çå符串</param> |
| | | /// <returns>妿åç¬¦ä¸²æ¯ææçGuidæ ¼å¼åè¿åtrueï¼å¦åè¿åfalse</returns> |
| | | public static bool IsGuid(this string guid) |
| | | { |
| | | Guid newId; |
| | | return guid.GetGuid(out newId); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°å符串转æ¢ä¸ºGuidç±»å |
| | | /// </summary> |
| | | /// <param name="guid">è¦è½¬æ¢çå符串</param> |
| | | /// <param name="outId">è¾åºè½¬æ¢åçGuid</param> |
| | | /// <returns>è½¬æ¢æåè¿åtrueï¼å¦åè¿åfalse</returns> |
| | | public static bool GetGuid(this string guid, out Guid outId) |
| | | { |
| | | Guid emptyId = Guid.Empty; |
| | | return Guid.TryParse(guid, out outId); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°å符串类åçæ¡ä»¶è½¬æ¢ä¸ºå¯¹åºçLinq表达å¼ç±»å |
| | | /// </summary> |
| | | /// <param name="stringType">表示æ¡ä»¶çå符串</param> |
| | | /// <returns>对åºçLinq表达å¼ç±»åæä¸¾å¼</returns> |
| | | /// <remarks> |
| | | /// è¯¥æ¹æ³ç¨äºå°åç«¯ä¼ éçæ¡ä»¶å符串æ å°ä¸ºå端Linqæ¥è¯¢ä½¿ç¨ç表达å¼ç±»åï¼ |
| | | /// æ¯æå
å«ã大äºçäºãå°äºçäºã大äºãå°äºã模ç³å¹é
çå¸¸è§æ¡ä»¶ç±»åï¼ |
| | | /// é»è®¤è¿åçäº(Equal)ç±»å |
| | | /// </remarks> |
| | | public static LinqExpressionType GetLinqCondition(this string stringType) |
| | | { |
| | | LinqExpressionType linqExpression; |
| | | switch (stringType) |
| | | { |
| | | case HtmlElementType.Contains: |
| | | case HtmlElementType.selectlist: |
| | | case nameof(HtmlElementType.Contains): |
| | | linqExpression = LinqExpressionType.In; |
| | | break; |
| | | case HtmlElementType.ThanOrEqual: |
| | | case nameof(HtmlElementType.ThanOrEqual): |
| | | case HtmlElementType.thanorequal: |
| | | linqExpression = LinqExpressionType.ThanOrEqual; |
| | | break; |
| | | case HtmlElementType.LessOrEqual: |
| | | case nameof(HtmlElementType.LessOrEqual): |
| | | case HtmlElementType.lessorequal: |
| | | linqExpression = LinqExpressionType.LessThanOrEqual; |
| | | break; |
| | | case HtmlElementType.GT: |
| | | case nameof(HtmlElementType.GT): |
| | | linqExpression = LinqExpressionType.GreaterThan; |
| | | break; |
| | | case HtmlElementType.lt: |
| | | linqExpression = LinqExpressionType.LessThan; |
| | | break; |
| | | case HtmlElementType.like: |
| | | linqExpression = LinqExpressionType.Contains; |
| | | 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>转æ¢åçæ¬å°DateTime对象</returns>
|
| | | /// <remarks>å¦æåæ°ä¸ºnullï¼åè¿åé»è®¤èµ·å§æ¥æ</remarks>
|
| | | 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;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å°å¯¹è±¡åºåå为JSONå符串
|
| | | /// </summary>
|
| | | /// <param name="obj">è¦åºååç对象</param>
|
| | | /// <param name="formatDate">æ¥ææ ¼å¼å设置ï¼é»è®¤ä¸º"yyyy-MM-dd HH:mm:ss"æ ¼å¼</param>
|
| | | /// <returns>åºåååçJSONå符串ï¼å¦æå¯¹è±¡ä¸ºnullåè¿ånull</returns>
|
| | | 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);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å°JSONå符串ååºåå为æå®ç±»åç对象
|
| | | /// </summary>
|
| | | /// <typeparam name="T">ç®æ 对象类å</typeparam>
|
| | | /// <param name="json">è¦ååºååçJSONå符串</param>
|
| | | /// <returns>ååºåååç对象å®ä¾ï¼å¦æè¾å
¥ä¸ºç©ºåè¿åé»è®¤å¼</returns>
|
| | | /// <remarks>
|
| | | /// å½è¾å
¥ä¸º"{}"æ¶ä¼èªå¨è½¬æ¢ä¸º"[]"å¤ç
|
| | | /// </remarks>
|
| | | public static T DeserializeObject<T>(this string json)
|
| | | {
|
| | | if (string.IsNullOrEmpty(json))
|
| | | {
|
| | | return default(T);
|
| | | }
|
| | | if (json == "{}")
|
| | | {
|
| | | json = "[]";
|
| | | }
|
| | | return JsonConvert.DeserializeObject<T>(json);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å°å符串çé¦åæ¯è½¬æ¢ä¸ºå°å
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦å¤ççå符串</param>
|
| | | /// <returns>é¦åæ¯å°åçå符串ï¼è¥è¾å
¥ä¸ºç©ºåè¿å空å符串</returns>
|
| | | 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;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å°å符串çé¦åæ¯è½¬æ¢ä¸ºå¤§å
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦å¤ççå符串</param>
|
| | | /// <returns>é¦åæ¯å¤§åçå符串ï¼è¥è¾å
¥ä¸ºç©ºåè¿å空å符串</returns>
|
| | | 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>转æ¢åçæ´åå¼ï¼è½¬æ¢å¤±è´¥è¿å0</returns>
|
| | | /// <remarks>
|
| | | /// æ¯æå¤çnullå¼ãDBNull.Valueåæä¸¾ç±»å
|
| | | /// </remarks>
|
| | | public static int ObjToInt(this object thisValue)
|
| | | {
|
| | | int reval = 0;
|
| | | if (thisValue == null) return 0;
|
| | | if (thisValue is Enum && thisValue != DBNull.Value && Enum.TryParse(thisValue.GetType(), thisValue.ToString(), out var val))
|
| | | {
|
| | | return Convert.ToInt32(val.ChangeType(typeof(int)));
|
| | | }
|
| | | if (thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval))
|
| | | {
|
| | | return reval;
|
| | | }
|
| | |
|
| | | return reval;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å°åç²¾åº¦æµ®ç¹æ°è½¬æ¢ä¸º32ä½æç¬¦å·æ´æ°
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦è½¬æ¢çåç²¾åº¦æµ®ç¹æ°</param>
|
| | | /// <returns>转æ¢åç32ä½æç¬¦å·æ´æ°</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;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºé¿æ´å(long)
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param>
|
| | | /// <returns>转æ¢åçé¿æ´åå¼ï¼è½¬æ¢å¤±è´¥æä¸ºnullæ¶è¿å0</returns>
|
| | | /// <remarks>
|
| | | /// å¤çDBNull.Valueæ
åµï¼å¹¶å°è¯å°å¯¹è±¡è½¬æ¢ä¸ºlongç±»å
|
| | | /// </remarks>
|
| | | 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>
|
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºéé¢(doubleç±»å)ãè¥è½¬æ¢å¤±è´¥åè¿å0ã
|
| | | /// </summary>
|
| | | /// <param name="thisValue">å¾
转æ¢ç对象</param>
|
| | | /// <returns>转æ¢åçéé¢å¼ï¼å¤±è´¥è¿å0</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>
|
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºéé¢(double)ç±»åï¼è½¬æ¢å¤±è´¥æ¶è¿åæå®çé误å¼
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param>
|
| | | /// <param name="errorValue">转æ¢å¤±è´¥æ¶è¿åçé»è®¤å¼</param>
|
| | | /// <returns>è½¬æ¢æåçdouble弿æå®çé误å¼</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>
|
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºå符串ï¼è¥å¯¹è±¡ä¸ºnullåè¿å空å符串
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param>
|
| | | /// <returns>å»é¤ååç©ºæ ¼çåç¬¦ä¸²ç»æ</returns>
|
| | | public static string ObjToString(this object thisValue)
|
| | | {
|
| | | if (thisValue != null) return thisValue.ToString().Trim();
|
| | | return "";
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å¤æå¯¹è±¡æ¯å¦ä¸ä¸ºç©ºænullå¼
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦å¤æç对象</param>
|
| | | /// <returns>å½å¯¹è±¡ä¸ä¸ºç©ºä¸ä¸çäº"undefined"æ"null"å符串æ¶è¿åtrueï¼å¦åè¿åfalse</returns>
|
| | | public static bool IsNotEmptyOrNull(this object thisValue)
|
| | | {
|
| | | return ObjToString(thisValue) != "" && ObjToString(thisValue) != "undefined" && ObjToString(thisValue) != "null";
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºå符串ï¼å¦æå¯¹è±¡ä¸ºnullåè¿åæå®çé误å¼
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param>
|
| | | /// <param name="errorValue">å½å¯¹è±¡ä¸ºnullæ¶è¿åçå¼</param>
|
| | | /// <returns>对象çå符串表示ææå®çé误å¼</returns>
|
| | | public static string ObjToString(this object thisValue, string errorValue)
|
| | | {
|
| | | if (thisValue != null) return thisValue.ToString().Trim();
|
| | | return errorValue;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å¤æå¯¹è±¡æ¯å¦ä¸ºnullãDBNullæç©ºå符串
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦æ£æ¥ç对象</param>
|
| | | /// <returns>å¦æå¯¹è±¡ä¸ºnullãDBNullæç©ºå符串åè¿åtrueï¼å¦åè¿åfalse</returns>
|
| | | public static bool IsNullOrEmpty(this object thisValue) => thisValue == null || thisValue == DBNull.Value || string.IsNullOrWhiteSpace(thisValue.ToString());
|
| | |
|
| | | /// <summary>
|
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºDecimalç±»å
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param>
|
| | | /// <returns>转æ¢åçDecimalå¼ï¼è½¬æ¢å¤±è´¥è¿å0</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>
|
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºDecimalç±»åï¼è¥è½¬æ¢å¤±è´¥åè¿åæå®çé»è®¤å¼
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param>
|
| | | /// <param name="errorValue">转æ¢å¤±è´¥æ¶è¿åçé»è®¤å¼</param>
|
| | | /// <returns>è½¬æ¢æåçDecimal弿æå®çé»è®¤å¼</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>
|
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºDateTimeç±»å
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param>
|
| | | /// <returns>转æ¢åçDateTimeå¼ï¼è½¬æ¢å¤±è´¥è¿åDateTime.MinValue</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>
|
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºDateTimeç±»åï¼è½¬æ¢å¤±è´¥æ¶è¿åæå®çé»è®¤å¼
|
| | | /// </summary>
|
| | | /// <param name="thisValue">è¦è½¬æ¢ç对象</param>
|
| | | /// <param name="errorValue">转æ¢å¤±è´¥æ¶è¿åçé»è®¤å¼</param>
|
| | | /// <returns>è½¬æ¢æåçDateTime弿æå®çé»è®¤å¼</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>转æ¢åçå¸å°å¼ï¼è½¬æ¢å¤±è´¥æ¶è¿åfalse</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>
|
| | | /// å°DateTime转æ¢ä¸ºUnixæ¶é´æ³ï¼ç§çº§ï¼
|
| | | /// </summary>
|
| | | /// <param name="thisValue">éè¦è½¬æ¢çDateTime对象</param>
|
| | | /// <returns>è¿å表示Unixæ¶é´æ³çå符串</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();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å°å¯¹è±¡è½¬æ¢ä¸ºæå®ç±»å
|
| | | /// </summary>
|
| | | /// <param name="value">è¦è½¬æ¢ç对象</param>
|
| | | /// <param name="type">ç®æ ç±»å</param>
|
| | | /// <returns>转æ¢åç对象</returns>
|
| | | /// <remarks>
|
| | | /// æ¯æå¤çnullå¼ãæä¸¾ç±»åãæ³åç±»åãGuidãVersionçç¹æ®ç±»åç转æ¢ã
|
| | | /// å¦æè½¬æ¢å¤±è´¥æç±»åä¸å¹é
ï¼å°è¿ååå§å¼ææåºå¼å¸¸ã
|
| | | /// </remarks>
|
| | | 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);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å°å¯¹è±¡å¼è½¬æ¢ä¸ºæå®ç±»åçæ³åå表ã
|
| | | /// </summary>
|
| | | /// <param name="value">å¾
转æ¢ç对象å¼</param>
|
| | | /// <param name="type">ç®æ å表å
ç´ ç±»å</param>
|
| | | /// <returns>转æ¢åçæ³åå表对象ï¼è¥è¾å
¥ä¸ºnullåè¿åé»è®¤å¼</returns>
|
| | | /// <remarks>
|
| | | /// æ¯æå¤ç以æ¬å·å
裹çåç¬¦ä¸²æ ¼å¼ï¼å¦"(1,2,3)"æ"("a","b")"ï¼ï¼
|
| | | /// èªå¨å»é¤åé符并å°å
ç´ è½¬æ¢ä¸ºç®æ ç±»ååæ·»å å°å表ã
|
| | | /// </remarks>
|
| | | 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;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å°å¯¹è±¡åºåå为JSONå符串
|
| | | /// </summary>
|
| | | /// <param name="value">è¦åºååç对象</param>
|
| | | /// <returns>对象çJSONå符串表示</returns>
|
| | | public static string ToJson(this object value)
|
| | | {
|
| | | return JsonConvert.SerializeObject(value);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å¤æå¯¹è±¡æ¯å¦å¯ä»¥è½¬æ¢ä¸ºæ´æ°
|
| | | /// </summary>
|
| | | /// <param name="obj">è¦å¤æç对象</param>
|
| | | /// <returns>妿å¯ä»¥è½¬æ¢ä¸ºæ´æ°è¿åtrueï¼å¦åè¿åfalse</returns>
|
| | | public static bool IsInt(this object obj)
|
| | | {
|
| | | if (obj == null)
|
| | | return false;
|
| | | bool reslut = Int32.TryParse(obj.ToString(), out int _number);
|
| | | return reslut;
|
| | |
|
| | | }
|
| | | |
| | | /// <summary>
|
| | | /// å¤æå¯¹è±¡æ¯å¦ä¸ºæææ¥ææ ¼å¼
|
| | | /// </summary>
|
| | | /// <param name="str">å¾
æ£æµç对象</param>
|
| | | /// <returns>trueè¡¨ç¤ºæ¯æææ¥æï¼falseå䏿¯</returns>
|
| | | /// <remarks>æ¤æ¹æ³æ¯æ©å±æ¹æ³ï¼éè¿è°ç¨IsDate(out _)å®ç°</remarks>
|
| | | public static bool IsDate(this object str)
|
| | | {
|
| | | return str.IsDate(out _);
|
| | | }
|
| | | |
| | | /// <summary>
|
| | | /// å¤æå¯¹è±¡æ¯å¦å¯ä»¥è½¬æ¢ä¸ºææçæ¥ææ¶é´
|
| | | /// </summary>
|
| | | /// <param name="str">è¦å¤æç对象</param>
|
| | | /// <param name="dateTime">è¾åºè½¬æ¢åçæ¥ææ¶é´å¼</param>
|
| | | /// <returns>å¦æè½¬æ¢æåè¿åtrueï¼å¦åè¿åfalse</returns>
|
| | | 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">æ ¼å¼åç¬¦ä¸²ï¼æªä½¿ç¨ï¼</param>
|
| | | /// <returns>妿å符串å¯ä»¥è½¬æ¢ä¸ºæ°ååè¿åtrueï¼å¦åè¿åfalse</returns>
|
| | | /// <remarks>
|
| | | /// ä½¿ç¨æ£å表达å¼éªè¯å符串æ¯å¦ä¸ºæ°åæ ¼å¼ï¼æ¯ææ£è´å·åå°æ°ç¹
|
| | | /// </remarks>
|
| | | public static bool IsNumber(this string str, string formatString)
|
| | | {
|
| | | if (string.IsNullOrEmpty(str)) return false;
|
| | |
|
| | | return Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$");
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 夿å符串æ¯å¦ä¸ºææçGuidæ ¼å¼
|
| | | /// </summary>
|
| | | /// <param name="guid">è¦éªè¯çå符串</param>
|
| | | /// <returns>妿åç¬¦ä¸²æ¯ææçGuidæ ¼å¼åè¿åtrueï¼å¦åè¿åfalse</returns>
|
| | | public static bool IsGuid(this string guid)
|
| | | {
|
| | | Guid newId;
|
| | | return guid.GetGuid(out newId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å°å符串转æ¢ä¸ºGuidç±»å
|
| | | /// </summary>
|
| | | /// <param name="guid">è¦è½¬æ¢çå符串</param>
|
| | | /// <param name="outId">è¾åºè½¬æ¢åçGuid</param>
|
| | | /// <returns>è½¬æ¢æåè¿åtrueï¼å¦åè¿åfalse</returns>
|
| | | public static bool GetGuid(this string guid, out Guid outId)
|
| | | {
|
| | | Guid emptyId = Guid.Empty;
|
| | | return Guid.TryParse(guid, out outId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å°å符串类åçæ¡ä»¶è½¬æ¢ä¸ºå¯¹åºçLinq表达å¼ç±»å
|
| | | /// </summary>
|
| | | /// <param name="stringType">表示æ¡ä»¶çå符串</param>
|
| | | /// <returns>对åºçLinq表达å¼ç±»åæä¸¾å¼</returns>
|
| | | /// <remarks>
|
| | | /// è¯¥æ¹æ³ç¨äºå°åç«¯ä¼ éçæ¡ä»¶å符串æ å°ä¸ºå端Linqæ¥è¯¢ä½¿ç¨ç表达å¼ç±»åï¼
|
| | | /// æ¯æå
å«ã大äºçäºãå°äºçäºã大äºãå°äºã模ç³å¹é
çå¸¸è§æ¡ä»¶ç±»åï¼
|
| | | /// é»è®¤è¿åçäº(Equal)ç±»å
|
| | | /// </remarks>
|
| | | public static LinqExpressionType GetLinqCondition(this string stringType)
|
| | | {
|
| | | LinqExpressionType linqExpression;
|
| | | switch (stringType)
|
| | | {
|
| | | case HtmlElementType.Contains:
|
| | | case HtmlElementType.selectlist:
|
| | | case nameof(HtmlElementType.Contains):
|
| | | linqExpression = LinqExpressionType.In;
|
| | | break;
|
| | | case HtmlElementType.notequal: |
| | | linqExpression = LinqExpressionType.NotEqual; |
| | | break; |
| | | case HtmlElementType.notequal: |
| | | linqExpression = LinqExpressionType.NotEqual; |
| | | break; |
| | | default: |
| | | linqExpression = LinqExpressionType.Equal; |
| | | break; |
| | | } |
| | | return linqExpression; |
| | | } |
| | | } |
| | | } |
| | | case HtmlElementType.ThanOrEqual:
|
| | | case nameof(HtmlElementType.ThanOrEqual):
|
| | | case HtmlElementType.thanorequal:
|
| | | linqExpression = LinqExpressionType.ThanOrEqual;
|
| | | break;
|
| | | case HtmlElementType.LessOrEqual:
|
| | | case nameof(HtmlElementType.LessOrEqual):
|
| | | case HtmlElementType.lessorequal:
|
| | | linqExpression = LinqExpressionType.LessThanOrEqual;
|
| | | break;
|
| | | case HtmlElementType.GT:
|
| | | case nameof(HtmlElementType.GT):
|
| | | linqExpression = LinqExpressionType.GreaterThan;
|
| | | break;
|
| | | case HtmlElementType.lt:
|
| | | linqExpression = LinqExpressionType.LessThan;
|
| | | break;
|
| | | case HtmlElementType.like:
|
| | | linqExpression = LinqExpressionType.Contains;
|
| | | break;
|
| | | case HtmlElementType.notequal:
|
| | | linqExpression = LinqExpressionType.NotEqual;
|
| | | break;
|
| | | default:
|
| | | linqExpression = LinqExpressionType.Equal;
|
| | | break;
|
| | | }
|
| | | return linqExpression;
|
| | | }
|
| | | }
|
| | | }
|
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Linq;
|
| | | using System.Text;
|
| | | using System.Threading.Tasks;
|
| | | using WIDESEAWCS_Core.BaseRepository;
|
| | | using WIDESEAWCS_Model.Models;
|
| | |
|
| | | namespace WIDESEAWCS_IRobotTaskInfoRepository
|
| | | {
|
| | | public interface IRobotTask_HtyRepository : IRepository<Dt_RobotTask_Hty>
|
| | | {
|
| | |
|
| | | }
|
| | | } |
| | |
| | | /// </summary> |
| | | public List<int> TaskRobotTypes { get; } |
| | | |
| | | public bool DeleteRobotTask(int id); |
| | | |
| | | public Dt_RobotTask? QueryRobotCraneTask(string deviceCode); |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Linq;
|
| | | using System.Text;
|
| | | using System.Threading.Tasks;
|
| | | using WIDESEAWCS_Core.BaseServices;
|
| | | using WIDESEAWCS_Model.Models;
|
| | |
|
| | | namespace WIDESEAWCS_ITaskInfoService
|
| | | {
|
| | | public interface IRobotTask_HtyService : IService<Dt_RobotTask_Hty>
|
| | | {
|
| | | }
|
| | | }
|
| | |
| | | /// æºæ¢°æ IP å°åï¼å¯ä¸ç´¢å¼ |
| | | /// </summary> |
| | | [SugarColumn(Length = 50, ColumnDescription = "æºæ¢°æIPå°å")] |
| | | public string IPAddress { get; set; } = string.Empty; |
| | | public string IpAddress { get; set; } |
| | | |
| | | /// <summary> |
| | | /// çæ¬å·ï¼ç¨äºä¹è§å¹¶åæ§å¶ |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using SqlSugar;
|
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Linq;
|
| | | using System.Text;
|
| | | using System.Threading.Tasks;
|
| | | using Magicodes.ExporterAndImporter.Core;
|
| | | using WIDESEAWCS_Core.DB.Models;
|
| | |
|
| | | namespace WIDESEAWCS_Model.Models
|
| | | {
|
| | | /// <summary>
|
| | | /// æºå¨äººåå²ä»»å¡è¡¨å®ä½
|
| | | /// </summary>
|
| | | [SugarTable(nameof(Dt_RobotTask_Hty), "æºå¨äººåå²ä»»å¡ä¿¡æ¯")]
|
| | | public class Dt_RobotTask_Hty : Dt_RobotTask, IBaseHistoryEntity
|
| | | {
|
| | | /// <summary>
|
| | | /// å表主é®
|
| | | /// </summary>
|
| | | [ImporterHeader(Name = "å表主é®")]
|
| | | [ExporterHeader(DisplayName = "å表主é®")]
|
| | | [SugarColumn(IsNullable = false, DefaultValue = "0", ColumnDescription = "å表主é®")]
|
| | | public int SourceId { get; set; }
|
| | |
|
| | | /// <summary>
|
| | | /// æä½ç±»å
|
| | | /// </summary>
|
| | | [ImporterHeader(Name = "æä½ç±»å")]
|
| | | [ExporterHeader(DisplayName = "æä½ç±»å")]
|
| | | [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "æä½ç±»å")]
|
| | | public string OperateType { get; set; }
|
| | |
|
| | | /// <summary>
|
| | | /// ç§»å
¥å岿¶é´
|
| | | /// </summary>
|
| | | [ImporterHeader(Name = "ç§»å
¥å岿¶é´")]
|
| | | [ExporterHeader(DisplayName = "ç§»å
¥å岿¶é´")]
|
| | | [SugarColumn(IsNullable = false, ColumnDescription = "ç§»å
¥å岿¶é´")]
|
| | | public DateTime InsertTime { get; set; }
|
| | | }
|
| | | } |
| | |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Microsoft.AspNetCore.Authorization; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseController; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_ISystemServices; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | |
| | | namespace WIDESEAWCS_Server.Controllers.Task |
| | | { |
| | | [Route("api/robotTask")] |
| | | [Route("api/RobotTask")] |
| | | [ApiController] |
| | | public class RobotTaskController : ApiBaseController<IRobotTaskService, Dt_RobotTask> |
| | | { |
| | | public RobotTaskController(IRobotTaskService service) : base(service) |
| | | { |
| | | |
| | | }
|
| | | [HttpGet, HttpPost, Route("DeleteRobotTask"), AllowAnonymous] |
| | | public WebResponseContent DeleteRobotTask(int id) |
| | | { |
| | | if (Service.DeleteRobotTask(id)){
|
| | | return WebResponseContent.Instance.OK();
|
| | | } |
| | | return WebResponseContent.Instance.Error(); |
| | | } |
| | | |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using Microsoft.AspNetCore.Mvc;
|
| | | using WIDESEAWCS_Core.BaseController;
|
| | | using WIDESEAWCS_ITaskInfoService;
|
| | | using WIDESEAWCS_Model.Models;
|
| | |
|
| | | namespace WIDESEAWCS_Server.Controllers.Task
|
| | | {
|
| | | namespace WIDESEAWCS_WCSServer.Controllers.Task
|
| | | {
|
| | | [Route("api/RobotTask_Hty")]
|
| | | [ApiController]
|
| | | public class RobotTask_HtyController : ApiBaseController<IRobotTask_HtyService, Dt_RobotTask_Hty>
|
| | | {
|
| | | private readonly IHttpContextAccessor _httpContextAccessor;
|
| | |
|
| | | public RobotTask_HtyController(
|
| | | IRobotTask_HtyService service,
|
| | | IHttpContextAccessor httpContextAccessor) : base(service)
|
| | | {
|
| | | _httpContextAccessor = httpContextAccessor;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | public Dt_RobotState? GetByIp(string ipAddress) |
| | | { |
| | | return Db.Queryable<Dt_RobotState>() |
| | | .Where(x => x.IPAddress == ipAddress) |
| | | .Where(x => x.IpAddress == ipAddress) |
| | | .First(); |
| | | } |
| | | |
| | |
| | | |
| | | var newState = new Dt_RobotState |
| | | { |
| | | IPAddress = ipAddress, |
| | | IpAddress = ipAddress, |
| | | Version = DateTime.UtcNow.Ticks, |
| | | RobotCraneJson = JsonConvert.SerializeObject(robotCrane), |
| | | CreateDate = DateTime.Now, |
| | |
| | | |
| | | // ä¹è§éï¼WHERE IPAddress = @ip AND Version = @expectedVersionï¼çæ¬å¹é
ææ´æ° |
| | | var affectedRows = Db.Updateable<Dt_RobotState>(newState) |
| | | .Where(x => x.IPAddress == ipAddress) |
| | | .Where(x => x.IpAddress == ipAddress) |
| | | .ExecuteCommand(); |
| | | |
| | | return affectedRows > 0; |
| | |
| | | { |
| | | var state = new RobotSocketState |
| | | { |
| | | IPAddress = entity.IPAddress, |
| | | IPAddress = entity.IpAddress, |
| | | Version = entity.Version, |
| | | IsEventSubscribed = entity.IsEventSubscribed, |
| | | RobotRunMode = entity.RobotRunMode, |
| | |
| | | { |
| | | var entity = new Dt_RobotState |
| | | { |
| | | IPAddress = state.IPAddress, |
| | | IpAddress = state.IPAddress, |
| | | IsEventSubscribed = state.IsEventSubscribed, |
| | | RobotRunMode = state.RobotRunMode, |
| | | RobotControlMode = state.RobotControlMode, |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Linq;
|
| | | using System.Text;
|
| | | using System.Threading.Tasks;
|
| | | using WIDESEAWCS_Core.BaseRepository;
|
| | | using WIDESEAWCS_IRobotTaskInfoRepository;
|
| | | using WIDESEAWCS_Model.Models;
|
| | |
|
| | | namespace WIDESEAWCS_RobotTaskInfoRepository
|
| | | {
|
| | | public class RobotTask_HtyRepository : RepositoryBase<Dt_RobotTask_Hty>, IRobotTask_HtyRepository
|
| | | {
|
| | | public RobotTask_HtyRepository(IUnitOfWorkManage unitOfWorkManage) : base(unitOfWorkManage)
|
| | | {
|
| | | }
|
| | | }
|
| | | } |
| | |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.Utilities; |
| | | using WIDESEAWCS_DTO.Stock; |
| | |
| | | _httpClientHelper = httpClientHelper; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _logger = logger; |
| | | }
|
| | | public override WebResponseContent DeleteData(object[] keys)
|
| | | {
|
| | | List<int> taskKeys = new List<int>();
|
| | | for (int i = 0; i < keys.Length; i++)
|
| | | {
|
| | | taskKeys.Add(Convert.ToInt32(keys[i]));
|
| | | }
|
| | | List<Dt_RobotTask> tasks = BaseDal.QueryData(x => taskKeys.Contains(x.RobotTaskId));
|
| | | BaseDal.DeleteAndMoveIntoHty(tasks, OperateTypeEnum.人工å é¤);
|
| | | return WebResponseContent.Instance.OK($"æåå é¤{tasks.Count}æ¡æ°æ®");
|
| | |
|
| | | }
|
| | | public bool DeleteRobotTask(int id) |
| | | { |
| | | Dt_RobotTask task = BaseDal.QueryFirst(x => x.RobotTaskId == id); |
| | | return BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.èªå¨å®æ); |
| | | } |
| | | |
| | | public WebResponseContent ReceiveWMSTask([NotNull] WMSTaskDTO taskDTO, StockDTO stockDTO) |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using MapsterMapper;
|
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Linq;
|
| | | using System.Text;
|
| | | using System.Threading.Tasks;
|
| | | using WIDESEAWCS_Core.BaseServices;
|
| | | using WIDESEAWCS_IRobotTaskInfoRepository;
|
| | | using WIDESEAWCS_ITaskInfoService;
|
| | | using WIDESEAWCS_Model.Models;
|
| | | using WIDESEAWCS_QuartzJob.Service;
|
| | |
|
| | | namespace WIDESEAWCS_TaskInfoService
|
| | | {
|
| | | public class RobotTask_HtyService : ServiceBase<Dt_RobotTask_Hty, IRobotTask_HtyRepository>, IRobotTask_HtyService
|
| | | {
|
| | | private readonly IRouterService _routerService;
|
| | | private readonly IMapper _mapper;
|
| | |
|
| | | public RobotTask_HtyService(
|
| | | IRobotTask_HtyRepository BaseDal,
|
| | | IRouterService routerService,
|
| | | IMapper mapper) : base(BaseDal)
|
| | | {
|
| | | _routerService = routerService;
|
| | | _mapper = mapper;
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | /// <summary> |
| | | /// æ¥å¿è®°å½å¨ |
| | | /// </summary> |
| | | private readonly ILogger _logger; |
| | | private readonly ILogger _logger;
|
| | | |
| | | /// <summary> |
| | | /// æé 彿° |
| | |
| | | /// <returns>å 餿¯å¦æå</returns> |
| | | public bool? DeleteTask(int ID) |
| | | { |
| | | return _robotTaskService.Repository.DeleteDataById(ID); |
| | | return _robotTaskService.DeleteRobotTask(ID); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | <div v-if="selectedLocation.details && selectedLocation.details.length > 0" class="detail-table"> |
| | | <h4>åºåæç»</h4> |
| | | <el-table :data="selectedLocation.details" border size="small" max-height="400"> |
| | | <el-table-column prop="materielName" label="ç©æåç§°" min-width="140" show-overflow-tooltip /> |
| | | <el-table-column prop="serialNumber" label="çµè¯æ¡ç " min-width="160" show-overflow-tooltip /> |
| | | <el-table-column prop="materielName" label="ç©æåç§°" min-width="90" show-overflow-tooltip /> |
| | | <el-table-column prop="serialNumber" label="çµè¯æ¡ç " min-width="180" show-overflow-tooltip /> |
| | | <el-table-column prop="inboundOrderRowNo" label="ééå·" min-width="100" show-overflow-tooltip /> |
| | | </el-table> |
| | | </div> |
| | |
| | | selectedLocation.value = null |
| | | |
| | | // æ¸
空ç鿡件 |
| | | filterStockStatus.value = null |
| | | filterMaterielCode.value = null |
| | | filterBatchNo.value = null |
| | | filterStockStatus.value = null |
| | | filterMaterielCode.value = null |
| | | filterBatchNo.value = null |
| | | const res = await proxy.http.get(`/api/StockInfo/Get3DLayout?warehouseId=${warehouseId}`) |
| | | if (res.status && res.data) { |
| | | const data = res.data |
| | |
| | | selectedLocation.value = null |
| | | |
| | | // æ¸
空ææç鿡件 |
| | | filterStockStatus.value = null |
| | | filterMaterielCode.value = null |
| | | filterBatchNo.value = null |
| | | // filterStockStatus.value = null |
| | | // filterMaterielCode.value = null |
| | | // filterBatchNo.value = null |
| | | |
| | | // æ¸
空çéé项å表 |
| | | materielCodeList.value = [] |
| | | batchNoList.value = [] |
| | | // // æ¸
空çéé项å表 |
| | | // materielCodeList.value = [] |
| | | // batchNoList.value = [] |
| | | |
| | | // å è½½æ°ä»åºæ°æ® |
| | | await loadWarehouseData(warehouseId) |
| | |
| | | } |
| | | |
| | | .detail-content { |
| | | padding: 20px; |
| | | padding: 10px; |
| | | } |
| | | |
| | | .detail-table { |
| | |
| | | <template> |
| | | <view-grid |
| | | ref="grid" |
| | | :columns="columns" |
| | | :detail="detail" |
| | | :editFormFields="editFormFields" |
| | | :editFormOptions="editFormOptions" |
| | | :searchFormFields="searchFormFields" |
| | | :searchFormOptions="searchFormOptions" |
| | | :table="table" |
| | | :tableExpand="tableExpand" |
| | | :extend="extend" |
| | | > |
| | | <view-grid ref="grid" :columns="columns" :detail="detail" :editFormFields="editFormFields" |
| | | :editFormOptions="editFormOptions" :searchFormFields="searchFormFields" :searchFormOptions="searchFormOptions" |
| | | :table="table" :tableExpand="tableExpand" :extend="extend"> |
| | | </view-grid> |
| | | </template> |
| | | |
| | |
| | | palletCode: "æçç¼å·", |
| | | stockStatus: "åºåç¶æ", |
| | | locationCode: "è´§ä½ç¼å·", |
| | | outboundDate: "åºåºæ¶é´", |
| | | warehouse: "ä»åº", |
| | | creator: "å建人", |
| | | createDate: "å建æ¶é´", |
| | |
| | | sortName: "id", |
| | | }); |
| | | |
| | | const editFormFields = ref({ |
| | | const editFormFields = ref({ |
| | | palletCode: "", |
| | | palletType: 0, |
| | | warehouseId: 0, |
| | |
| | | const editFormOptions = ref([ |
| | | [ |
| | | { field: "palletCode", title: TEXT.palletCode, type: "string" }, |
| | | { field: "stockStatus", title: TEXT.stockStatus, type: "select", dataKey: "stockStatusEmun", data: []}, |
| | | { field: "stockStatus", title: TEXT.stockStatus, type: "select", dataKey: "stockStatusEmun", data: [] }, |
| | | { field: "locationCode", title: TEXT.locationCode, type: "string" }, |
| | | ], |
| | | ]); |
| | |
| | | field: "palletCode", |
| | | title: TEXT.palletCode, |
| | | type: "string", |
| | | width: 120, |
| | | width: 150, |
| | | align: "left", |
| | | }, |
| | | { |
| | |
| | | bind: { key: "mesUploadStatusEnum", data: [] }, |
| | | }, |
| | | { |
| | | field: "outboundDate", |
| | | title: TEXT.outboundDate, |
| | | type: "string", |
| | | width: 150, |
| | | align: "left", |
| | | }, |
| | | { |
| | | field: "locationCode", |
| | | title: TEXT.locationCode, |
| | | type: "string", |
| | | width: 150, |
| | | width: 120, |
| | | align: "left", |
| | | }, |
| | | { |
| | |
| | | using NetTaste; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | using System.Web; |
| | | using WIDESEA_Core.Const; |
| | | using WIDESEA_Core.Enums; |
| | | |
| | | namespace WIDESEA_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 is Enum && thisValue != DBNull.Value && Enum.TryParse(thisValue.GetType(), thisValue.ToString(), out var val)) |
| | | { |
| | | return Convert.ToInt32(val.ChangeType(typeof(int))); |
| | | } |
| | | 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 IsNumeric(this object value) |
| | | { |
| | | if (value == null) |
| | | return false; |
| | | bool reslut = decimal.TryParse(value.ToString(), out decimal _number); |
| | | return reslut; |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 转æ¢ä¸ºçæ´å qy 2024-7-15 |
| | | /// </summary> |
| | | /// <param name="data">æ°æ®</param> |
| | | public static short ToShort(this object data) |
| | | { |
| | | if (data == null) |
| | | return 0; |
| | | short result; |
| | | var success = short.TryParse(data.ToString(), out result); |
| | | if (success) |
| | | return result; |
| | | try |
| | | { |
| | | return Convert.ToInt16(data); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 转æ¢ä¸ºé«ç²¾åº¦æµ®ç¹æ°,å¹¶ææå®çå°æ°ä½4è5å
¥ qy 2024-7-15 |
| | | /// </summary> |
| | | /// <param name="data">æ°æ®</param> |
| | | /// <param name="digits">å°æ°ä½æ°</param> |
| | | public static decimal ToDecimal(this object data, int digits) |
| | | { |
| | | return Math.Round(ObjToDecimal(data), digits); |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// æä¸¾è½¬List qy 2024-7-15 |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <returns></returns> |
| | | public static List<object> GetEnumList<T>() |
| | | { |
| | | List<object> list = new List<object>(); |
| | | var t = typeof(T); |
| | | foreach (var item in Enum.GetValues(typeof(T))) |
| | | { |
| | | FieldInfo f = t.GetField(Enum.GetName(typeof(T), item)); |
| | | var r = (System.ComponentModel.DescriptionAttribute[])f.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false); |
| | | list.Add(new { ID = item, value = Enum.GetName(typeof(T), item), name = r[0].Description }); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éªè¯å¨æç±»åå
ç´ æ¯å¦ä¸ºç©º qy 2024-7-15 |
| | | /// </summary> |
| | | /// <param name="obj"></param> |
| | | /// <returns></returns> |
| | | public static bool CheckDynamic(object obj) |
| | | { |
| | | return (obj != null && Convert.ToString(obj) != "") ? true : false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¨æç±»åå
ç´ è½¬å符串并解ç qy 2024-7-15 |
| | | /// </summary> |
| | | /// <param name="obj"></param> |
| | | /// <returns></returns> |
| | | public static string DynamicToString(object obj) |
| | | { |
| | | return CheckDynamic(obj) ? HttpUtility.UrlDecode(Convert.ToString(obj).Trim()) : ""; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// DataTable转为json qy 2024-7-15 |
| | | /// </summary> |
| | | /// <param name="parObjRefDataTable">DataTable</param> |
| | | /// <returns>jsonæ°æ®</returns> |
| | | public static string ToJson(this DataTable parObjRefDataTable) |
| | | { |
| | | List<object> objArrList = new List<object>(); |
| | | |
| | | foreach (DataRow objDataRow in parObjRefDataTable.Rows) |
| | | { |
| | | Dictionary<string, object> objResult = new Dictionary<string, object>(); |
| | | |
| | | foreach (DataColumn objDataColumn in parObjRefDataTable.Columns) |
| | | objResult.Add(objDataColumn.ColumnName, objDataRow[objDataColumn].ToString()); |
| | | |
| | | objArrList.Add(objResult); |
| | | } |
| | | |
| | | return ToJson(objArrList); |
| | | } |
| | | /// <summary> |
| | | /// Json转List qy 2024-7-15 |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="parJson"></param> |
| | | /// <returns></returns> |
| | | public static List<T> JsonToList<T>(this string parJson) |
| | | { |
| | | if (string.IsNullOrWhiteSpace(parJson)) |
| | | { |
| | | return new List<T>(); |
| | | } |
| | | else |
| | | { |
| | | return JsonConvert.DeserializeObject<List<T>>(parJson); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥æè½¬ä¸ºunixå¼ |
| | | /// </summary> |
| | | /// <param name="dt"></param> |
| | | /// <param name="utc">T:æUTCæ¶é´è®¡ç®(é»è®¤);F:ææ¬å°æ¶é´è®¡ç®</param> |
| | | /// <returns></returns> |
| | | /// <summary> |
| | | /// æ¥æè½¬ä¸ºunixå¼ |
| | | /// </summary> |
| | | /// <param name="dt">æ¥ææ¶é´</param> |
| | | /// <param name="utc">T:æUTCæ¶é´è®¡ç®(é»è®¤);F:ææ¬å°æ¶é´è®¡ç®</param> |
| | | /// <returns></returns> |
| | | public static double ToUnix(this DateTime dt, bool utc = true) |
| | | { |
| | | double intResult = 0; |
| | | System.DateTime startTime = TimeZoneInfo.ConvertTime(new System.DateTime(1970, 1, 1), TimeZoneInfo.Utc, TimeZoneInfo.Local); |
| | | intResult = (dt - startTime).TotalSeconds; |
| | | intResult = Math.Round(intResult, 0); |
| | | return intResult; |
| | | } |
| | | |
| | | #region 夿æ¯å¦ä¸ºå符串 qy 2024-7-15 |
| | | /// <summary> |
| | | /// 夿å符串æ¯å¦ä¸ºåæ³çjsonå符串 qy 2024-7-15 |
| | | /// </summary> |
| | | /// <param name="json"></param> |
| | | /// <returns></returns> |
| | | public static bool IsJson(string json) |
| | | { |
| | | int errIndex; |
| | | return IsJson(json, out errIndex); |
| | | } |
| | | public static bool IsJson(string json, out int errIndex) |
| | | { |
| | | errIndex = 0; |
| | | if (IsJsonStart(ref json)) |
| | | { |
| | | CharState cs = new CharState(); |
| | | char c; |
| | | for (int i = 0; i < json.Length; i++) |
| | | { |
| | | c = json[i]; |
| | | if (SetCharState(c, ref cs) && cs.childrenStart)//设置å
³é®ç¬¦å·ç¶æã |
| | | { |
| | | string item = json.Substring(i); |
| | | int err; |
| | | int length = GetValueLength(item, true, out err); |
| | | cs.childrenStart = false; |
| | | if (err > 0) |
| | | { |
| | | errIndex = i + err; |
| | | return false; |
| | | } |
| | | i = i + length - 1; |
| | | } |
| | | if (cs.isError) |
| | | { |
| | | errIndex = i; |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return !cs.arrayStart && !cs.jsonStart; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private static bool IsJsonStart(ref string json) |
| | | { |
| | | if (!string.IsNullOrEmpty(json)) |
| | | { |
| | | json = json.Trim('\r', '\n', ' '); |
| | | if (json.Length > 1) |
| | | { |
| | | char s = json[0]; |
| | | char e = json[json.Length - 1]; |
| | | return (s == '{' && e == '}') || (s == '[' && e == ']'); |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åå¼çé¿åº¦ï¼å½Jsonå¼åµå¥ä»¥"{"æ"["å¼å¤´æ¶ï¼ qy 2024-7-15 |
| | | /// </summary> |
| | | private static int GetValueLength(string json, bool breakOnErr, out int errIndex) |
| | | { |
| | | errIndex = 0; |
| | | int len = 0; |
| | | if (!string.IsNullOrEmpty(json)) |
| | | { |
| | | CharState cs = new CharState(); |
| | | char c; |
| | | for (int i = 0; i < json.Length; i++) |
| | | { |
| | | c = json[i]; |
| | | if (!SetCharState(c, ref cs))//设置å
³é®ç¬¦å·ç¶æã |
| | | { |
| | | if (!cs.jsonStart && !cs.arrayStart)//jsonç»æï¼å䏿¯æ°ç»ï¼åéåºã |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | else if (cs.childrenStart)//æ£å¸¸å符ï¼å¼ç¶æä¸ã |
| | | { |
| | | int length = GetValueLength(json.Substring(i), breakOnErr, out errIndex);//éå½åå¼ï¼è¿åä¸ä¸ªé¿åº¦ããã |
| | | cs.childrenStart = false; |
| | | cs.valueStart = 0; |
| | | //cs.state = 0; |
| | | i = i + length - 1; |
| | | } |
| | | if (breakOnErr && cs.isError) |
| | | { |
| | | errIndex = i; |
| | | return i; |
| | | } |
| | | if (!cs.jsonStart && !cs.arrayStart)//è®°å½å½åç»æä½ç½®ã |
| | | { |
| | | len = i + 1;//é¿åº¦æ¯ç´¢å¼+1 |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | return len; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åç¬¦ç¶æ qy 2024-7-15 |
| | | /// </summary> |
| | | private class CharState |
| | | { |
| | | internal bool jsonStart = false;//以 "{"å¼å§äº... |
| | | internal bool setDicValue = false;// å¯ä»¥è®¾ç½®åå
¸å¼äºã |
| | | internal bool escapeChar = false;//以"\"转ä¹ç¬¦å·å¼å§äº |
| | | /// <summary> |
| | | /// æ°ç»å¼å§ãä»
第ä¸å¼å¤´æç®ãï¼å¼åµå¥ç以ãchildrenStartãæ¥æ è¯ã |
| | | /// </summary> |
| | | internal bool arrayStart = false;//以"[" 符å·å¼å§äº |
| | | internal bool childrenStart = false;//å级åµå¥å¼å§äºã |
| | | /// <summary> |
| | | /// ã0 åå§ç¶æï¼æ éå°â,âéå·ãï¼ã1 éå°âï¼âåå·ã |
| | | /// </summary> |
| | | internal int state = 0; |
| | | |
| | | /// <summary> |
| | | /// ã-1 åå¼ç»æãã0 æªå¼å§ãã1 æ å¼å·å¼å§ãã2 åå¼å·å¼å§ãã3 åå¼å·å¼å§ã |
| | | /// </summary> |
| | | internal int keyStart = 0; |
| | | /// <summary> |
| | | /// ã-1 åå¼ç»æãã0 æªå¼å§ãã1 æ å¼å·å¼å§ãã2 åå¼å·å¼å§ãã3 åå¼å·å¼å§ã |
| | | /// </summary> |
| | | internal int valueStart = 0; |
| | | internal bool isError = false;//æ¯å¦è¯æ³é误ã |
| | | |
| | | internal void CheckIsError(char c)//åªå½æä¸çº§å¤çï¼å 为GetLengthä¼éå½å°æ¯ä¸ä¸ªå项å¤çï¼ |
| | | { |
| | | if (keyStart > 1 || valueStart > 1) |
| | | { |
| | | return; |
| | | } |
| | | //ç¤ºä¾ ["aa",{"bbbb":123,"fff","ddd"}] |
| | | switch (c) |
| | | { |
| | | case '{'://[{ "[{A}]":[{"[{B}]":3,"m":"C"}]}] |
| | | isError = jsonStart && state == 0;//éå¤å¼å§é误 忶䏿¯å¼å¤çã |
| | | break; |
| | | case '}': |
| | | isError = !jsonStart || (keyStart != 0 && state == 0);//éå¤ç»æé误 æè
æåç»æ{"aa"}ãæ£å¸¸çæ{} |
| | | break; |
| | | case '[': |
| | | isError = arrayStart && state == 0;//éå¤å¼å§é误 |
| | | break; |
| | | case ']': |
| | | isError = !arrayStart || jsonStart;//éå¤å¼å§é误 æè
Json æªç»æ |
| | | break; |
| | | case '"': |
| | | case '\'': |
| | | isError = !(jsonStart || arrayStart); //json ææ°ç»å¼å§ã |
| | | if (!isError) |
| | | { |
| | | //éå¤å¼å§ [""",{"" "}] |
| | | isError = (state == 0 && keyStart == -1) || (state == 1 && valueStart == -1); |
| | | } |
| | | if (!isError && arrayStart && !jsonStart && c == '\'')//['aa',{}] |
| | | { |
| | | isError = true; |
| | | } |
| | | break; |
| | | case ':': |
| | | isError = !jsonStart || state == 1;//éå¤åºç°ã |
| | | break; |
| | | case ',': |
| | | isError = !(jsonStart || arrayStart); //json ææ°ç»å¼å§ã |
| | | if (!isError) |
| | | { |
| | | if (jsonStart) |
| | | { |
| | | isError = state == 0 || (state == 1 && valueStart > 1);//éå¤åºç°ã |
| | | } |
| | | else if (arrayStart)//["aa,] [,] [{},{}] |
| | | { |
| | | isError = keyStart == 0 && !setDicValue; |
| | | } |
| | | } |
| | | break; |
| | | case ' ': |
| | | case '\r': |
| | | case '\n'://[ "a",\r\n{} ] |
| | | case '\0': |
| | | case '\t': |
| | | break; |
| | | default: //å¼å¼å¤´ãã |
| | | isError = (!jsonStart && !arrayStart) || (state == 0 && keyStart == -1) || (valueStart == -1 && state == 1);// |
| | | break; |
| | | } |
| | | //if (isError) |
| | | //{ |
| | | |
| | | //} |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 设置åç¬¦ç¶æ(è¿åtrueå为å
³é®è¯ï¼è¿åfalseåå½ä¸ºæ®éå符å¤çï¼ qy 2024-7-15 |
| | | /// </summary> |
| | | private static bool SetCharState(char c, ref CharState cs) |
| | | { |
| | | cs.CheckIsError(c); |
| | | switch (c) |
| | | { |
| | | case '{'://[{ "[{A}]":[{"[{B}]":3,"m":"C"}]}] |
| | | #region 大æ¬å· |
| | | if (cs.keyStart <= 0 && cs.valueStart <= 0) |
| | | { |
| | | cs.keyStart = 0; |
| | | cs.valueStart = 0; |
| | | if (cs.jsonStart && cs.state == 1) |
| | | { |
| | | cs.childrenStart = true; |
| | | } |
| | | else |
| | | { |
| | | cs.state = 0; |
| | | } |
| | | cs.jsonStart = true;//å¼å§ã |
| | | return true; |
| | | } |
| | | #endregion |
| | | break; |
| | | case '}': |
| | | #region 大æ¬å·ç»æ |
| | | if (cs.keyStart <= 0 && cs.valueStart < 2 && cs.jsonStart) |
| | | { |
| | | cs.jsonStart = false;//æ£å¸¸ç»æã |
| | | cs.state = 0; |
| | | cs.keyStart = 0; |
| | | cs.valueStart = 0; |
| | | cs.setDicValue = true; |
| | | return true; |
| | | } |
| | | // cs.isError = !cs.jsonStart && cs.state == 0; |
| | | #endregion |
| | | break; |
| | | case '[': |
| | | #region 䏿¬å·å¼å§ |
| | | if (!cs.jsonStart) |
| | | { |
| | | cs.arrayStart = true; |
| | | return true; |
| | | } |
| | | else if (cs.jsonStart && cs.state == 1) |
| | | { |
| | | cs.childrenStart = true; |
| | | return true; |
| | | } |
| | | #endregion |
| | | break; |
| | | case ']': |
| | | #region 䏿¬å·ç»æ |
| | | if (cs.arrayStart && !cs.jsonStart && cs.keyStart <= 2 && cs.valueStart <= 0)//[{},333]//è¿æ ·ç»æã |
| | | { |
| | | cs.keyStart = 0; |
| | | cs.valueStart = 0; |
| | | cs.arrayStart = false; |
| | | return true; |
| | | } |
| | | #endregion |
| | | break; |
| | | case '"': |
| | | case '\'': |
| | | #region å¼å· |
| | | if (cs.jsonStart || cs.arrayStart) |
| | | { |
| | | if (cs.state == 0)//keyé¶æ®µ,æå¯è½æ¯æ°ç»["aa",{}] |
| | | { |
| | | if (cs.keyStart <= 0) |
| | | { |
| | | cs.keyStart = (c == '"' ? 3 : 2); |
| | | return true; |
| | | } |
| | | else if ((cs.keyStart == 2 && c == '\'') || (cs.keyStart == 3 && c == '"')) |
| | | { |
| | | if (!cs.escapeChar) |
| | | { |
| | | cs.keyStart = -1; |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | cs.escapeChar = false; |
| | | } |
| | | } |
| | | } |
| | | else if (cs.state == 1 && cs.jsonStart)//å¼é¶æ®µå¿
é¡»æ¯Jsonå¼å§äºã |
| | | { |
| | | if (cs.valueStart <= 0) |
| | | { |
| | | cs.valueStart = (c == '"' ? 3 : 2); |
| | | return true; |
| | | } |
| | | else if ((cs.valueStart == 2 && c == '\'') || (cs.valueStart == 3 && c == '"')) |
| | | { |
| | | if (!cs.escapeChar) |
| | | { |
| | | cs.valueStart = -1; |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | cs.escapeChar = false; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | #endregion |
| | | break; |
| | | case ':': |
| | | #region åå· |
| | | if (cs.jsonStart && cs.keyStart < 2 && cs.valueStart < 2 && cs.state == 0) |
| | | { |
| | | if (cs.keyStart == 1) |
| | | { |
| | | cs.keyStart = -1; |
| | | } |
| | | cs.state = 1; |
| | | return true; |
| | | } |
| | | // cs.isError = !cs.jsonStart || (cs.keyStart < 2 && cs.valueStart < 2 && cs.state == 1); |
| | | #endregion |
| | | break; |
| | | case ',': |
| | | #region éå· //["aa",{aa:12,}] |
| | | |
| | | if (cs.jsonStart) |
| | | { |
| | | if (cs.keyStart < 2 && cs.valueStart < 2 && cs.state == 1) |
| | | { |
| | | cs.state = 0; |
| | | cs.keyStart = 0; |
| | | cs.valueStart = 0; |
| | | //if (cs.valueStart == 1) |
| | | //{ |
| | | // cs.valueStart = 0; |
| | | //} |
| | | cs.setDicValue = true; |
| | | return true; |
| | | } |
| | | } |
| | | else if (cs.arrayStart && cs.keyStart <= 2) |
| | | { |
| | | cs.keyStart = 0; |
| | | //if (cs.keyStart == 1) |
| | | //{ |
| | | // cs.keyStart = -1; |
| | | //} |
| | | return true; |
| | | } |
| | | #endregion |
| | | break; |
| | | case ' ': |
| | | case '\r': |
| | | case '\n'://[ "a",\r\n{} ] |
| | | case '\0': |
| | | case '\t': |
| | | if (cs.keyStart <= 0 && cs.valueStart <= 0) //cs.jsonStart && |
| | | { |
| | | return true;//è·³è¿ç©ºæ ¼ã |
| | | } |
| | | break; |
| | | default: //å¼å¼å¤´ãã |
| | | if (c == '\\') //转ä¹ç¬¦å· |
| | | { |
| | | if (cs.escapeChar) |
| | | { |
| | | cs.escapeChar = false; |
| | | } |
| | | else |
| | | { |
| | | cs.escapeChar = true; |
| | | return true; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | cs.escapeChar = false; |
| | | } |
| | | if (cs.jsonStart || cs.arrayStart) // Json ææ°ç»å¼å§äºã |
| | | { |
| | | if (cs.keyStart <= 0 && cs.state == 0) |
| | | { |
| | | cs.keyStart = 1;//æ å¼å·ç |
| | | } |
| | | else if (cs.valueStart <= 0 && cs.state == 1 && cs.jsonStart)//åªæJsonå¼å§ææå¼ã |
| | | { |
| | | cs.valueStart = 1;//æ å¼å·ç |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | 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; |
| | | using NetTaste;
|
| | | using Newtonsoft.Json;
|
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Data;
|
| | | using System.Linq;
|
| | | using System.Reflection;
|
| | | using System.Text;
|
| | | using System.Text.RegularExpressions;
|
| | | using System.Threading.Tasks;
|
| | | using System.Web;
|
| | | using WIDESEA_Core.Const;
|
| | | using WIDESEA_Core.Enums;
|
| | |
|
| | | namespace WIDESEA_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 is Enum && thisValue != DBNull.Value && Enum.TryParse(thisValue.GetType(), thisValue.ToString(), out var val))
|
| | | {
|
| | | return Convert.ToInt32(val.ChangeType(typeof(int)));
|
| | | }
|
| | | 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 IsNumeric(this object value)
|
| | | {
|
| | | if (value == null)
|
| | | return false;
|
| | | bool reslut = decimal.TryParse(value.ToString(), out decimal _number);
|
| | | return reslut;
|
| | | }
|
| | |
|
| | | 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);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 转æ¢ä¸ºçæ´å qy 2024-7-15
|
| | | /// </summary>
|
| | | /// <param name="data">æ°æ®</param>
|
| | | public static short ToShort(this object data)
|
| | | {
|
| | | if (data == null)
|
| | | return 0;
|
| | | short result;
|
| | | var success = short.TryParse(data.ToString(), out result);
|
| | | if (success)
|
| | | return result;
|
| | | try
|
| | | {
|
| | | return Convert.ToInt16(data);
|
| | | }
|
| | | catch (Exception)
|
| | | {
|
| | | return 0;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 转æ¢ä¸ºé«ç²¾åº¦æµ®ç¹æ°,å¹¶ææå®çå°æ°ä½4è5å
¥ qy 2024-7-15
|
| | | /// </summary>
|
| | | /// <param name="data">æ°æ®</param>
|
| | | /// <param name="digits">å°æ°ä½æ°</param>
|
| | | public static decimal ToDecimal(this object data, int digits)
|
| | | {
|
| | | return Math.Round(ObjToDecimal(data), digits);
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// æä¸¾è½¬List qy 2024-7-15
|
| | | /// </summary>
|
| | | /// <typeparam name="T"></typeparam>
|
| | | /// <returns></returns>
|
| | | public static List<object> GetEnumList<T>()
|
| | | {
|
| | | List<object> list = new List<object>();
|
| | | var t = typeof(T);
|
| | | foreach (var item in Enum.GetValues(typeof(T)))
|
| | | {
|
| | | FieldInfo f = t.GetField(Enum.GetName(typeof(T), item));
|
| | | var r = (System.ComponentModel.DescriptionAttribute[])f.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
|
| | | list.Add(new { ID = item, value = Enum.GetName(typeof(T), item), name = r[0].Description });
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | /// <summary> |
| | | /// éªè¯å¨æç±»åå
ç´ æ¯å¦ä¸ºç©º qy 2024-7-15
|
| | | /// </summary>
|
| | | /// <param name="obj"></param>
|
| | | /// <returns></returns>
|
| | | public static bool CheckDynamic(object obj)
|
| | | {
|
| | | return (obj != null && Convert.ToString(obj) != "") ? true : false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// å¨æç±»åå
ç´ è½¬å符串并解ç qy 2024-7-15
|
| | | /// </summary>
|
| | | /// <param name="obj"></param>
|
| | | /// <returns></returns>
|
| | | public static string DynamicToString(object obj)
|
| | | {
|
| | | return CheckDynamic(obj) ? HttpUtility.UrlDecode(Convert.ToString(obj).Trim()) : "";
|
| | | }
|
| | |
|
| | | /// <summary> |
| | | /// DataTable转为json qy 2024-7-15
|
| | | /// </summary> |
| | | /// <param name="parObjRefDataTable">DataTable</param> |
| | | /// <returns>jsonæ°æ®</returns> |
| | | public static string ToJson(this DataTable parObjRefDataTable)
|
| | | {
|
| | | List<object> objArrList = new List<object>();
|
| | |
|
| | | foreach (DataRow objDataRow in parObjRefDataTable.Rows)
|
| | | {
|
| | | Dictionary<string, object> objResult = new Dictionary<string, object>();
|
| | |
|
| | | foreach (DataColumn objDataColumn in parObjRefDataTable.Columns)
|
| | | objResult.Add(objDataColumn.ColumnName, objDataRow[objDataColumn].ToString());
|
| | |
|
| | | objArrList.Add(objResult);
|
| | | }
|
| | |
|
| | | return ToJson(objArrList);
|
| | | }
|
| | | /// <summary>
|
| | | /// Json转List qy 2024-7-15
|
| | | /// </summary>
|
| | | /// <typeparam name="T"></typeparam>
|
| | | /// <param name="parJson"></param>
|
| | | /// <returns></returns>
|
| | | public static List<T> JsonToList<T>(this string parJson)
|
| | | {
|
| | | if (string.IsNullOrWhiteSpace(parJson))
|
| | | {
|
| | | return new List<T>();
|
| | | }
|
| | | else
|
| | | {
|
| | | return JsonConvert.DeserializeObject<List<T>>(parJson);
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// æ¥æè½¬ä¸ºunixå¼
|
| | | /// </summary>
|
| | | /// <param name="dt"></param>
|
| | | /// <param name="utc">T:æUTCæ¶é´è®¡ç®(é»è®¤);F:ææ¬å°æ¶é´è®¡ç®</param>
|
| | | /// <returns></returns>
|
| | | /// <summary>
|
| | | /// æ¥æè½¬ä¸ºunixå¼
|
| | | /// </summary>
|
| | | /// <param name="dt">æ¥ææ¶é´</param>
|
| | | /// <param name="utc">T:æUTCæ¶é´è®¡ç®(é»è®¤);F:ææ¬å°æ¶é´è®¡ç®</param>
|
| | | /// <returns></returns>
|
| | | public static double ToUnix(this DateTime dt, bool utc = true)
|
| | | {
|
| | | double intResult = 0;
|
| | | System.DateTime startTime = TimeZoneInfo.ConvertTime(new System.DateTime(1970, 1, 1), TimeZoneInfo.Utc, TimeZoneInfo.Local);
|
| | | intResult = (dt - startTime).TotalSeconds;
|
| | | intResult = Math.Round(intResult, 0);
|
| | | return intResult;
|
| | | }
|
| | |
|
| | | #region 夿æ¯å¦ä¸ºå符串 qy 2024-7-15
|
| | | /// <summary>
|
| | | /// 夿å符串æ¯å¦ä¸ºåæ³çjsonå符串 qy 2024-7-15
|
| | | /// </summary>
|
| | | /// <param name="json"></param>
|
| | | /// <returns></returns>
|
| | | public static bool IsJson(string json)
|
| | | {
|
| | | int errIndex;
|
| | | return IsJson(json, out errIndex);
|
| | | }
|
| | | public static bool IsJson(string json, out int errIndex)
|
| | | {
|
| | | errIndex = 0;
|
| | | if (IsJsonStart(ref json))
|
| | | {
|
| | | CharState cs = new CharState();
|
| | | char c;
|
| | | for (int i = 0; i < json.Length; i++)
|
| | | {
|
| | | c = json[i];
|
| | | if (SetCharState(c, ref cs) && cs.childrenStart)//设置å
³é®ç¬¦å·ç¶æã
|
| | | {
|
| | | string item = json.Substring(i);
|
| | | int err;
|
| | | int length = GetValueLength(item, true, out err);
|
| | | cs.childrenStart = false;
|
| | | if (err > 0)
|
| | | {
|
| | | errIndex = i + err;
|
| | | return false;
|
| | | }
|
| | | i = i + length - 1;
|
| | | }
|
| | | if (cs.isError)
|
| | | {
|
| | | errIndex = i;
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | return !cs.arrayStart && !cs.jsonStart;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | private static bool IsJsonStart(ref string json)
|
| | | {
|
| | | if (!string.IsNullOrEmpty(json))
|
| | | {
|
| | | json = json.Trim('\r', '\n', ' ');
|
| | | if (json.Length > 1)
|
| | | {
|
| | | char s = json[0];
|
| | | char e = json[json.Length - 1];
|
| | | return (s == '{' && e == '}') || (s == '[' && e == ']');
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// è·åå¼çé¿åº¦ï¼å½Jsonå¼åµå¥ä»¥"{"æ"["å¼å¤´æ¶ï¼ qy 2024-7-15
|
| | | /// </summary>
|
| | | private static int GetValueLength(string json, bool breakOnErr, out int errIndex)
|
| | | {
|
| | | errIndex = 0;
|
| | | int len = 0;
|
| | | if (!string.IsNullOrEmpty(json))
|
| | | {
|
| | | CharState cs = new CharState();
|
| | | char c;
|
| | | for (int i = 0; i < json.Length; i++)
|
| | | {
|
| | | c = json[i];
|
| | | if (!SetCharState(c, ref cs))//设置å
³é®ç¬¦å·ç¶æã
|
| | | {
|
| | | if (!cs.jsonStart && !cs.arrayStart)//jsonç»æï¼å䏿¯æ°ç»ï¼åéåºã
|
| | | {
|
| | | break;
|
| | | }
|
| | | }
|
| | | else if (cs.childrenStart)//æ£å¸¸å符ï¼å¼ç¶æä¸ã
|
| | | {
|
| | | int length = GetValueLength(json.Substring(i), breakOnErr, out errIndex);//éå½åå¼ï¼è¿åä¸ä¸ªé¿åº¦ããã
|
| | | cs.childrenStart = false;
|
| | | cs.valueStart = 0;
|
| | | //cs.state = 0;
|
| | | i = i + length - 1;
|
| | | }
|
| | | if (breakOnErr && cs.isError)
|
| | | {
|
| | | errIndex = i;
|
| | | return i;
|
| | | }
|
| | | if (!cs.jsonStart && !cs.arrayStart)//è®°å½å½åç»æä½ç½®ã
|
| | | {
|
| | | len = i + 1;//é¿åº¦æ¯ç´¢å¼+1
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | return len;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// åç¬¦ç¶æ qy 2024-7-15
|
| | | /// </summary>
|
| | | private class CharState
|
| | | {
|
| | | internal bool jsonStart = false;//以 "{"å¼å§äº...
|
| | | internal bool setDicValue = false;// å¯ä»¥è®¾ç½®åå
¸å¼äºã
|
| | | internal bool escapeChar = false;//以"\"转ä¹ç¬¦å·å¼å§äº
|
| | | /// <summary>
|
| | | /// æ°ç»å¼å§ãä»
第ä¸å¼å¤´æç®ãï¼å¼åµå¥ç以ãchildrenStartãæ¥æ è¯ã
|
| | | /// </summary>
|
| | | internal bool arrayStart = false;//以"[" 符å·å¼å§äº
|
| | | internal bool childrenStart = false;//å级åµå¥å¼å§äºã
|
| | | /// <summary>
|
| | | /// ã0 åå§ç¶æï¼æ éå°â,âéå·ãï¼ã1 éå°âï¼âåå·ã
|
| | | /// </summary>
|
| | | internal int state = 0;
|
| | |
|
| | | /// <summary>
|
| | | /// ã-1 åå¼ç»æãã0 æªå¼å§ãã1 æ å¼å·å¼å§ãã2 åå¼å·å¼å§ãã3 åå¼å·å¼å§ã
|
| | | /// </summary>
|
| | | internal int keyStart = 0;
|
| | | /// <summary>
|
| | | /// ã-1 åå¼ç»æãã0 æªå¼å§ãã1 æ å¼å·å¼å§ãã2 åå¼å·å¼å§ãã3 åå¼å·å¼å§ã
|
| | | /// </summary>
|
| | | internal int valueStart = 0;
|
| | | internal bool isError = false;//æ¯å¦è¯æ³é误ã
|
| | |
|
| | | internal void CheckIsError(char c)//åªå½æä¸çº§å¤çï¼å 为GetLengthä¼éå½å°æ¯ä¸ä¸ªå项å¤çï¼
|
| | | {
|
| | | if (keyStart > 1 || valueStart > 1)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //ç¤ºä¾ ["aa",{"bbbb":123,"fff","ddd"}] |
| | | switch (c)
|
| | | {
|
| | | case '{'://[{ "[{A}]":[{"[{B}]":3,"m":"C"}]}]
|
| | | isError = jsonStart && state == 0;//éå¤å¼å§é误 忶䏿¯å¼å¤çã
|
| | | break;
|
| | | case '}':
|
| | | isError = !jsonStart || (keyStart != 0 && state == 0);//éå¤ç»æé误 æè
æåç»æ{"aa"}ãæ£å¸¸çæ{}
|
| | | break;
|
| | | case '[':
|
| | | isError = arrayStart && state == 0;//éå¤å¼å§é误
|
| | | break;
|
| | | case ']':
|
| | | isError = !arrayStart || jsonStart;//éå¤å¼å§é误 æè
Json æªç»æ
|
| | | break;
|
| | | case '"':
|
| | | case '\'':
|
| | | isError = !(jsonStart || arrayStart); //json ææ°ç»å¼å§ã
|
| | | if (!isError)
|
| | | {
|
| | | //éå¤å¼å§ [""",{"" "}]
|
| | | isError = (state == 0 && keyStart == -1) || (state == 1 && valueStart == -1);
|
| | | }
|
| | | if (!isError && arrayStart && !jsonStart && c == '\'')//['aa',{}]
|
| | | {
|
| | | isError = true;
|
| | | }
|
| | | break;
|
| | | case ':':
|
| | | isError = !jsonStart || state == 1;//éå¤åºç°ã
|
| | | break;
|
| | | case ',':
|
| | | isError = !(jsonStart || arrayStart); //json ææ°ç»å¼å§ã
|
| | | if (!isError)
|
| | | {
|
| | | if (jsonStart)
|
| | | {
|
| | | isError = state == 0 || (state == 1 && valueStart > 1);//éå¤åºç°ã
|
| | | }
|
| | | else if (arrayStart)//["aa,] [,] [{},{}]
|
| | | {
|
| | | isError = keyStart == 0 && !setDicValue;
|
| | | }
|
| | | }
|
| | | break;
|
| | | case ' ':
|
| | | case '\r':
|
| | | case '\n'://[ "a",\r\n{} ]
|
| | | case '\0':
|
| | | case '\t':
|
| | | break;
|
| | | default: //å¼å¼å¤´ãã
|
| | | isError = (!jsonStart && !arrayStart) || (state == 0 && keyStart == -1) || (valueStart == -1 && state == 1);//
|
| | | break;
|
| | | }
|
| | | //if (isError)
|
| | | //{
|
| | |
|
| | | //}
|
| | | }
|
| | | }
|
| | | /// <summary>
|
| | | /// 设置åç¬¦ç¶æ(è¿åtrueå为å
³é®è¯ï¼è¿åfalseåå½ä¸ºæ®éå符å¤çï¼ qy 2024-7-15
|
| | | /// </summary>
|
| | | private static bool SetCharState(char c, ref CharState cs)
|
| | | {
|
| | | cs.CheckIsError(c);
|
| | | switch (c)
|
| | | {
|
| | | case '{'://[{ "[{A}]":[{"[{B}]":3,"m":"C"}]}]
|
| | | #region 大æ¬å·
|
| | | if (cs.keyStart <= 0 && cs.valueStart <= 0)
|
| | | {
|
| | | cs.keyStart = 0;
|
| | | cs.valueStart = 0;
|
| | | if (cs.jsonStart && cs.state == 1)
|
| | | {
|
| | | cs.childrenStart = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | cs.state = 0;
|
| | | }
|
| | | cs.jsonStart = true;//å¼å§ã
|
| | | return true;
|
| | | }
|
| | | #endregion
|
| | | break;
|
| | | case '}':
|
| | | #region 大æ¬å·ç»æ
|
| | | if (cs.keyStart <= 0 && cs.valueStart < 2 && cs.jsonStart)
|
| | | {
|
| | | cs.jsonStart = false;//æ£å¸¸ç»æã
|
| | | cs.state = 0;
|
| | | cs.keyStart = 0;
|
| | | cs.valueStart = 0;
|
| | | cs.setDicValue = true;
|
| | | return true;
|
| | | }
|
| | | // cs.isError = !cs.jsonStart && cs.state == 0;
|
| | | #endregion
|
| | | break;
|
| | | case '[':
|
| | | #region 䏿¬å·å¼å§
|
| | | if (!cs.jsonStart)
|
| | | {
|
| | | cs.arrayStart = true;
|
| | | return true;
|
| | | }
|
| | | else if (cs.jsonStart && cs.state == 1)
|
| | | {
|
| | | cs.childrenStart = true;
|
| | | return true;
|
| | | }
|
| | | #endregion
|
| | | break;
|
| | | case ']':
|
| | | #region 䏿¬å·ç»æ
|
| | | if (cs.arrayStart && !cs.jsonStart && cs.keyStart <= 2 && cs.valueStart <= 0)//[{},333]//è¿æ ·ç»æã
|
| | | {
|
| | | cs.keyStart = 0;
|
| | | cs.valueStart = 0;
|
| | | cs.arrayStart = false;
|
| | | return true;
|
| | | }
|
| | | #endregion
|
| | | break;
|
| | | case '"':
|
| | | case '\'':
|
| | | #region å¼å·
|
| | | if (cs.jsonStart || cs.arrayStart)
|
| | | {
|
| | | if (cs.state == 0)//keyé¶æ®µ,æå¯è½æ¯æ°ç»["aa",{}]
|
| | | {
|
| | | if (cs.keyStart <= 0)
|
| | | {
|
| | | cs.keyStart = (c == '"' ? 3 : 2);
|
| | | return true;
|
| | | }
|
| | | else if ((cs.keyStart == 2 && c == '\'') || (cs.keyStart == 3 && c == '"'))
|
| | | {
|
| | | if (!cs.escapeChar)
|
| | | {
|
| | | cs.keyStart = -1;
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | cs.escapeChar = false;
|
| | | }
|
| | | }
|
| | | }
|
| | | else if (cs.state == 1 && cs.jsonStart)//å¼é¶æ®µå¿
é¡»æ¯Jsonå¼å§äºã
|
| | | {
|
| | | if (cs.valueStart <= 0)
|
| | | {
|
| | | cs.valueStart = (c == '"' ? 3 : 2);
|
| | | return true;
|
| | | }
|
| | | else if ((cs.valueStart == 2 && c == '\'') || (cs.valueStart == 3 && c == '"'))
|
| | | {
|
| | | if (!cs.escapeChar)
|
| | | {
|
| | | cs.valueStart = -1;
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | cs.escapeChar = false;
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | #endregion
|
| | | break;
|
| | | case ':':
|
| | | #region åå·
|
| | | if (cs.jsonStart && cs.keyStart < 2 && cs.valueStart < 2 && cs.state == 0)
|
| | | {
|
| | | if (cs.keyStart == 1)
|
| | | {
|
| | | cs.keyStart = -1;
|
| | | }
|
| | | cs.state = 1;
|
| | | return true;
|
| | | }
|
| | | // cs.isError = !cs.jsonStart || (cs.keyStart < 2 && cs.valueStart < 2 && cs.state == 1);
|
| | | #endregion
|
| | | break;
|
| | | case ',':
|
| | | #region éå· //["aa",{aa:12,}]
|
| | |
|
| | | if (cs.jsonStart)
|
| | | {
|
| | | if (cs.keyStart < 2 && cs.valueStart < 2 && cs.state == 1)
|
| | | {
|
| | | cs.state = 0;
|
| | | cs.keyStart = 0;
|
| | | cs.valueStart = 0;
|
| | | //if (cs.valueStart == 1)
|
| | | //{
|
| | | // cs.valueStart = 0;
|
| | | //}
|
| | | cs.setDicValue = true;
|
| | | return true;
|
| | | }
|
| | | }
|
| | | else if (cs.arrayStart && cs.keyStart <= 2)
|
| | | {
|
| | | cs.keyStart = 0;
|
| | | //if (cs.keyStart == 1)
|
| | | //{
|
| | | // cs.keyStart = -1;
|
| | | //}
|
| | | return true;
|
| | | }
|
| | | #endregion
|
| | | break;
|
| | | case ' ':
|
| | | case '\r':
|
| | | case '\n'://[ "a",\r\n{} ]
|
| | | case '\0':
|
| | | case '\t':
|
| | | if (cs.keyStart <= 0 && cs.valueStart <= 0) //cs.jsonStart && |
| | | {
|
| | | return true;//è·³è¿ç©ºæ ¼ã
|
| | | }
|
| | | break;
|
| | | default: //å¼å¼å¤´ãã
|
| | | if (c == '\\') //转ä¹ç¬¦å·
|
| | | {
|
| | | if (cs.escapeChar)
|
| | | {
|
| | | cs.escapeChar = false;
|
| | | }
|
| | | else
|
| | | {
|
| | | cs.escapeChar = true;
|
| | | return true;
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | cs.escapeChar = false;
|
| | | }
|
| | | if (cs.jsonStart || cs.arrayStart) // Json ææ°ç»å¼å§äºã
|
| | | {
|
| | | if (cs.keyStart <= 0 && cs.state == 0)
|
| | | {
|
| | | cs.keyStart = 1;//æ å¼å·ç
|
| | | }
|
| | | else if (cs.valueStart <= 0 && cs.state == 1 && cs.jsonStart)//åªæJsonå¼å§ææå¼ã
|
| | | {
|
| | | cs.valueStart = 1;//æ å¼å·ç
|
| | | }
|
| | | }
|
| | | break;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | 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;
|
| | | case HtmlElementType.thanorequal:
|
| | | linqExpression = LinqExpressionType.ThanOrEqual;
|
| | | break;
|
| | | case HtmlElementType.lessorequal:
|
| | | linqExpression = LinqExpressionType.LessThanOrEqual;
|
| | | break; |
| | | break;
|
| | | case HtmlElementType.notequal:
|
| | | linqExpression = LinqExpressionType.NotEqual;
|
| | | break; |
| | | default: |
| | | linqExpression = LinqExpressionType.Equal; |
| | | break; |
| | | } |
| | | return linqExpression; |
| | | } |
| | | } |
| | | } |
| | | break;
|
| | | default:
|
| | | linqExpression = LinqExpressionType.Equal;
|
| | | break;
|
| | | }
|
| | | return linqExpression;
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | // 空æç乿åºåè®°å½ï¼åªæ¯ä¸å
å«æç» |
| | | item.PalletCode = stockInfo.PalletCode; |
| | | item.StockStatus = stockInfo.StockStatus; // ç´æ¥ä½¿ç¨å端åºåç¶æ |
| | | |
| | | |
| | | // åªæå½Detailsä¸ä¸ºnullä¸ææ°æ®æ¶æå¤çåºåæç» |
| | | if (stockInfo.Details != null && stockInfo.Details.Any()) |
| | | { |
| | | item.StockQuantity = stockInfo.Details.Sum(d => d.StockQuantity); |
| | | |
| | | item.OutboundDate = stockInfo.OutboundDate; |
| | | // è·å第ä¸ä¸ªæç»çç©æä¿¡æ¯ï¼å¦æåå¨ï¼ |
| | | var firstDetail = stockInfo.Details.FirstOrDefault(); |
| | | if (firstDetail != null) |
| | |
| | | Id = d.Id, |
| | | MaterielCode = d.MaterielCode, |
| | | MaterielName = d.MaterielName, |
| | | SerialNumber = d.SerialNumber, |
| | | BatchNo = d.BatchNo, |
| | | StockQuantity = d.StockQuantity, |
| | | Unit = d.Unit, |