diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift new file mode 100644 index 0000000..a52e1e5 --- /dev/null +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -0,0 +1,45 @@ +// +// InspectionLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var startTime: String = "" // 开始时间 + @objc dynamic var endTime: String = "" // 结束时间 + @objc dynamic var date: String = "" // 日期 + @objc dynamic var startLng: Double = 0.0 // 开始经度 + @objc dynamic var startLat: Double = 0.0 // 开始纬度 + @objc dynamic var endLng: Double = 0.0 // 结束经度 + @objc dynamic var endLat: Double = 0.0 // 结束维度 + @objc dynamic var routes: String = "" // 路线Json + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(inspectionId: String = "", name: String = "", startTime: String = "", + endTime: String = "", date: String = "", startLng: Double, startLat: Double, + endLng: Double, endLat: Double, routes: String = "") { + self.init() + self.inspectionId = inspectionId + self.name = name + self.startTime = startTime + self.endTime = endTime + self.date = date + self.startLng = startLng + self.startLat = startLat + self.endLng = endLng + self.endLat = endLat + self.routes = routes + } +} diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift new file mode 100644 index 0000000..a52e1e5 --- /dev/null +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -0,0 +1,45 @@ +// +// InspectionLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var startTime: String = "" // 开始时间 + @objc dynamic var endTime: String = "" // 结束时间 + @objc dynamic var date: String = "" // 日期 + @objc dynamic var startLng: Double = 0.0 // 开始经度 + @objc dynamic var startLat: Double = 0.0 // 开始纬度 + @objc dynamic var endLng: Double = 0.0 // 结束经度 + @objc dynamic var endLat: Double = 0.0 // 结束维度 + @objc dynamic var routes: String = "" // 路线Json + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(inspectionId: String = "", name: String = "", startTime: String = "", + endTime: String = "", date: String = "", startLng: Double, startLat: Double, + endLng: Double, endLat: Double, routes: String = "") { + self.init() + self.inspectionId = inspectionId + self.name = name + self.startTime = startTime + self.endTime = endTime + self.date = date + self.startLng = startLng + self.startLat = startLat + self.endLng = endLng + self.endLat = endLat + self.routes = routes + } +} diff --git a/LaserMethane/Protocol/RealmInitializer.swift b/LaserMethane/Protocol/RealmInitializer.swift new file mode 100644 index 0000000..7631888 --- /dev/null +++ b/LaserMethane/Protocol/RealmInitializer.swift @@ -0,0 +1,45 @@ +// +// Initializer.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +protocol RealmInitializer { + func perform() +} + +final class InspectionMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.inspectionConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} + +final class EventTaskMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.eventTaskConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift new file mode 100644 index 0000000..a52e1e5 --- /dev/null +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -0,0 +1,45 @@ +// +// InspectionLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var startTime: String = "" // 开始时间 + @objc dynamic var endTime: String = "" // 结束时间 + @objc dynamic var date: String = "" // 日期 + @objc dynamic var startLng: Double = 0.0 // 开始经度 + @objc dynamic var startLat: Double = 0.0 // 开始纬度 + @objc dynamic var endLng: Double = 0.0 // 结束经度 + @objc dynamic var endLat: Double = 0.0 // 结束维度 + @objc dynamic var routes: String = "" // 路线Json + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(inspectionId: String = "", name: String = "", startTime: String = "", + endTime: String = "", date: String = "", startLng: Double, startLat: Double, + endLng: Double, endLat: Double, routes: String = "") { + self.init() + self.inspectionId = inspectionId + self.name = name + self.startTime = startTime + self.endTime = endTime + self.date = date + self.startLng = startLng + self.startLat = startLat + self.endLng = endLng + self.endLat = endLat + self.routes = routes + } +} diff --git a/LaserMethane/Protocol/RealmInitializer.swift b/LaserMethane/Protocol/RealmInitializer.swift new file mode 100644 index 0000000..7631888 --- /dev/null +++ b/LaserMethane/Protocol/RealmInitializer.swift @@ -0,0 +1,45 @@ +// +// Initializer.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +protocol RealmInitializer { + func perform() +} + +final class InspectionMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.inspectionConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} + +final class EventTaskMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.eventTaskConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} diff --git a/LaserMethane/Util/Constant.swift b/LaserMethane/Util/Constant.swift index a50b95f..cd568e8 100644 --- a/LaserMethane/Util/Constant.swift +++ b/LaserMethane/Util/Constant.swift @@ -15,6 +15,7 @@ let OPEN_TRANSFER_COMMAND: [UInt8] = [0x02, 0x0D, 0x0A] // 开启数据发送命令 let DEVICE_DATA_VIEW_WIDTH = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View宽 let DEVICE_DATA_VIEW_HEIGHT = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View高 +let SCHEMA_VERSION = UInt64(0) // Realm数据库版本 public enum Constant: String { // 用户相关的key值 diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift new file mode 100644 index 0000000..a52e1e5 --- /dev/null +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -0,0 +1,45 @@ +// +// InspectionLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var startTime: String = "" // 开始时间 + @objc dynamic var endTime: String = "" // 结束时间 + @objc dynamic var date: String = "" // 日期 + @objc dynamic var startLng: Double = 0.0 // 开始经度 + @objc dynamic var startLat: Double = 0.0 // 开始纬度 + @objc dynamic var endLng: Double = 0.0 // 结束经度 + @objc dynamic var endLat: Double = 0.0 // 结束维度 + @objc dynamic var routes: String = "" // 路线Json + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(inspectionId: String = "", name: String = "", startTime: String = "", + endTime: String = "", date: String = "", startLng: Double, startLat: Double, + endLng: Double, endLat: Double, routes: String = "") { + self.init() + self.inspectionId = inspectionId + self.name = name + self.startTime = startTime + self.endTime = endTime + self.date = date + self.startLng = startLng + self.startLat = startLat + self.endLng = endLng + self.endLat = endLat + self.routes = routes + } +} diff --git a/LaserMethane/Protocol/RealmInitializer.swift b/LaserMethane/Protocol/RealmInitializer.swift new file mode 100644 index 0000000..7631888 --- /dev/null +++ b/LaserMethane/Protocol/RealmInitializer.swift @@ -0,0 +1,45 @@ +// +// Initializer.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +protocol RealmInitializer { + func perform() +} + +final class InspectionMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.inspectionConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} + +final class EventTaskMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.eventTaskConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} diff --git a/LaserMethane/Util/Constant.swift b/LaserMethane/Util/Constant.swift index a50b95f..cd568e8 100644 --- a/LaserMethane/Util/Constant.swift +++ b/LaserMethane/Util/Constant.swift @@ -15,6 +15,7 @@ let OPEN_TRANSFER_COMMAND: [UInt8] = [0x02, 0x0D, 0x0A] // 开启数据发送命令 let DEVICE_DATA_VIEW_WIDTH = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View宽 let DEVICE_DATA_VIEW_HEIGHT = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View高 +let SCHEMA_VERSION = UInt64(0) // Realm数据库版本 public enum Constant: String { // 用户相关的key值 diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift new file mode 100644 index 0000000..a716369 --- /dev/null +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -0,0 +1,76 @@ +// +// EventTaskRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskRealmManager { + public static let shared = EventTaskRealmManager() + + let realm: Realm = { + let migration = EventTaskMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存事件记录到本地 + * */ + func addEventTask(model: NewEventTaskModel) { + let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let results = queryTaskEventById(id: model.taskId) + if results.count == 0 { + try! realm.write { + realm.add(eventObject) + } + } + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspection(inspectionId: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + } + + /** + * 查询所有事件数据 + */ + func queryAllTaskEvent() -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEvent(createTime: String, name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + } + + /** + * 条件查询巡检数据-根据事件标签查询 + */ + func queryTaskEventByName(name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEventById(id: String) -> Results { + realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + } + + func isAddSuccess(taskId: String) -> Bool { + let results = queryTaskEventById(id: taskId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift new file mode 100644 index 0000000..a52e1e5 --- /dev/null +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -0,0 +1,45 @@ +// +// InspectionLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var startTime: String = "" // 开始时间 + @objc dynamic var endTime: String = "" // 结束时间 + @objc dynamic var date: String = "" // 日期 + @objc dynamic var startLng: Double = 0.0 // 开始经度 + @objc dynamic var startLat: Double = 0.0 // 开始纬度 + @objc dynamic var endLng: Double = 0.0 // 结束经度 + @objc dynamic var endLat: Double = 0.0 // 结束维度 + @objc dynamic var routes: String = "" // 路线Json + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(inspectionId: String = "", name: String = "", startTime: String = "", + endTime: String = "", date: String = "", startLng: Double, startLat: Double, + endLng: Double, endLat: Double, routes: String = "") { + self.init() + self.inspectionId = inspectionId + self.name = name + self.startTime = startTime + self.endTime = endTime + self.date = date + self.startLng = startLng + self.startLat = startLat + self.endLng = endLng + self.endLat = endLat + self.routes = routes + } +} diff --git a/LaserMethane/Protocol/RealmInitializer.swift b/LaserMethane/Protocol/RealmInitializer.swift new file mode 100644 index 0000000..7631888 --- /dev/null +++ b/LaserMethane/Protocol/RealmInitializer.swift @@ -0,0 +1,45 @@ +// +// Initializer.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +protocol RealmInitializer { + func perform() +} + +final class InspectionMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.inspectionConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} + +final class EventTaskMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.eventTaskConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} diff --git a/LaserMethane/Util/Constant.swift b/LaserMethane/Util/Constant.swift index a50b95f..cd568e8 100644 --- a/LaserMethane/Util/Constant.swift +++ b/LaserMethane/Util/Constant.swift @@ -15,6 +15,7 @@ let OPEN_TRANSFER_COMMAND: [UInt8] = [0x02, 0x0D, 0x0A] // 开启数据发送命令 let DEVICE_DATA_VIEW_WIDTH = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View宽 let DEVICE_DATA_VIEW_HEIGHT = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View高 +let SCHEMA_VERSION = UInt64(0) // Realm数据库版本 public enum Constant: String { // 用户相关的key值 diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift new file mode 100644 index 0000000..a716369 --- /dev/null +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -0,0 +1,76 @@ +// +// EventTaskRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskRealmManager { + public static let shared = EventTaskRealmManager() + + let realm: Realm = { + let migration = EventTaskMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存事件记录到本地 + * */ + func addEventTask(model: NewEventTaskModel) { + let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let results = queryTaskEventById(id: model.taskId) + if results.count == 0 { + try! realm.write { + realm.add(eventObject) + } + } + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspection(inspectionId: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + } + + /** + * 查询所有事件数据 + */ + func queryAllTaskEvent() -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEvent(createTime: String, name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + } + + /** + * 条件查询巡检数据-根据事件标签查询 + */ + func queryTaskEventByName(name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEventById(id: String) -> Results { + realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + } + + func isAddSuccess(taskId: String) -> Bool { + let results = queryTaskEventById(id: taskId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift new file mode 100644 index 0000000..a484463 --- /dev/null +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -0,0 +1,72 @@ +// +// InspectionRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionRealmManager { + public static let shared = InspectionRealmManager() + + let realm: Realm = { + let migration = InspectionMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存巡检记录到本地 + * */ + func addInspection(newModel: NewInspectionModel) { + let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) + let results = queryInspectionById(id: newModel.id) + if results.count == 0 { + try! realm.write { + realm.add(insObject) + } + } + } + + /** + * 查询所有巡检数据 + */ + func queryAllInspection() -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspectionById(id: String) -> Results { + realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspection(startTime: String, endTime: String, name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + } + + /** + * 条件查询巡检数据-根据巡检标签查询 + */ + func queryInspectionByName(name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + } + + /** + * 判断是否插入成功 + */ + func isAddSuccess(inspectionId: String) -> Bool { + let results = queryInspectionById(id: inspectionId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift new file mode 100644 index 0000000..a52e1e5 --- /dev/null +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -0,0 +1,45 @@ +// +// InspectionLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var startTime: String = "" // 开始时间 + @objc dynamic var endTime: String = "" // 结束时间 + @objc dynamic var date: String = "" // 日期 + @objc dynamic var startLng: Double = 0.0 // 开始经度 + @objc dynamic var startLat: Double = 0.0 // 开始纬度 + @objc dynamic var endLng: Double = 0.0 // 结束经度 + @objc dynamic var endLat: Double = 0.0 // 结束维度 + @objc dynamic var routes: String = "" // 路线Json + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(inspectionId: String = "", name: String = "", startTime: String = "", + endTime: String = "", date: String = "", startLng: Double, startLat: Double, + endLng: Double, endLat: Double, routes: String = "") { + self.init() + self.inspectionId = inspectionId + self.name = name + self.startTime = startTime + self.endTime = endTime + self.date = date + self.startLng = startLng + self.startLat = startLat + self.endLng = endLng + self.endLat = endLat + self.routes = routes + } +} diff --git a/LaserMethane/Protocol/RealmInitializer.swift b/LaserMethane/Protocol/RealmInitializer.swift new file mode 100644 index 0000000..7631888 --- /dev/null +++ b/LaserMethane/Protocol/RealmInitializer.swift @@ -0,0 +1,45 @@ +// +// Initializer.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +protocol RealmInitializer { + func perform() +} + +final class InspectionMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.inspectionConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} + +final class EventTaskMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.eventTaskConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} diff --git a/LaserMethane/Util/Constant.swift b/LaserMethane/Util/Constant.swift index a50b95f..cd568e8 100644 --- a/LaserMethane/Util/Constant.swift +++ b/LaserMethane/Util/Constant.swift @@ -15,6 +15,7 @@ let OPEN_TRANSFER_COMMAND: [UInt8] = [0x02, 0x0D, 0x0A] // 开启数据发送命令 let DEVICE_DATA_VIEW_WIDTH = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View宽 let DEVICE_DATA_VIEW_HEIGHT = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View高 +let SCHEMA_VERSION = UInt64(0) // Realm数据库版本 public enum Constant: String { // 用户相关的key值 diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift new file mode 100644 index 0000000..a716369 --- /dev/null +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -0,0 +1,76 @@ +// +// EventTaskRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskRealmManager { + public static let shared = EventTaskRealmManager() + + let realm: Realm = { + let migration = EventTaskMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存事件记录到本地 + * */ + func addEventTask(model: NewEventTaskModel) { + let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let results = queryTaskEventById(id: model.taskId) + if results.count == 0 { + try! realm.write { + realm.add(eventObject) + } + } + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspection(inspectionId: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + } + + /** + * 查询所有事件数据 + */ + func queryAllTaskEvent() -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEvent(createTime: String, name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + } + + /** + * 条件查询巡检数据-根据事件标签查询 + */ + func queryTaskEventByName(name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEventById(id: String) -> Results { + realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + } + + func isAddSuccess(taskId: String) -> Bool { + let results = queryTaskEventById(id: taskId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift new file mode 100644 index 0000000..a484463 --- /dev/null +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -0,0 +1,72 @@ +// +// InspectionRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionRealmManager { + public static let shared = InspectionRealmManager() + + let realm: Realm = { + let migration = InspectionMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存巡检记录到本地 + * */ + func addInspection(newModel: NewInspectionModel) { + let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) + let results = queryInspectionById(id: newModel.id) + if results.count == 0 { + try! realm.write { + realm.add(insObject) + } + } + } + + /** + * 查询所有巡检数据 + */ + func queryAllInspection() -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspectionById(id: String) -> Results { + realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspection(startTime: String, endTime: String, name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + } + + /** + * 条件查询巡检数据-根据巡检标签查询 + */ + func queryInspectionByName(name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + } + + /** + * 判断是否插入成功 + */ + func isAddSuccess(inspectionId: String) -> Bool { + let results = queryInspectionById(id: inspectionId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/RealmConfiguration.swift b/LaserMethane/Util/RealmConfiguration.swift new file mode 100644 index 0000000..54d8b83 --- /dev/null +++ b/LaserMethane/Util/RealmConfiguration.swift @@ -0,0 +1,25 @@ +// +// RealmConfiguration.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +struct RealmConfiguration { + static func inspectionConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("inspection.realm") + return Realm.Configuration(fileURL: url) + } + + static func eventTaskConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("eventTask.realm") + return Realm.Configuration(fileURL: url) + } +} diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift new file mode 100644 index 0000000..a52e1e5 --- /dev/null +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -0,0 +1,45 @@ +// +// InspectionLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var startTime: String = "" // 开始时间 + @objc dynamic var endTime: String = "" // 结束时间 + @objc dynamic var date: String = "" // 日期 + @objc dynamic var startLng: Double = 0.0 // 开始经度 + @objc dynamic var startLat: Double = 0.0 // 开始纬度 + @objc dynamic var endLng: Double = 0.0 // 结束经度 + @objc dynamic var endLat: Double = 0.0 // 结束维度 + @objc dynamic var routes: String = "" // 路线Json + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(inspectionId: String = "", name: String = "", startTime: String = "", + endTime: String = "", date: String = "", startLng: Double, startLat: Double, + endLng: Double, endLat: Double, routes: String = "") { + self.init() + self.inspectionId = inspectionId + self.name = name + self.startTime = startTime + self.endTime = endTime + self.date = date + self.startLng = startLng + self.startLat = startLat + self.endLng = endLng + self.endLat = endLat + self.routes = routes + } +} diff --git a/LaserMethane/Protocol/RealmInitializer.swift b/LaserMethane/Protocol/RealmInitializer.swift new file mode 100644 index 0000000..7631888 --- /dev/null +++ b/LaserMethane/Protocol/RealmInitializer.swift @@ -0,0 +1,45 @@ +// +// Initializer.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +protocol RealmInitializer { + func perform() +} + +final class InspectionMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.inspectionConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} + +final class EventTaskMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.eventTaskConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} diff --git a/LaserMethane/Util/Constant.swift b/LaserMethane/Util/Constant.swift index a50b95f..cd568e8 100644 --- a/LaserMethane/Util/Constant.swift +++ b/LaserMethane/Util/Constant.swift @@ -15,6 +15,7 @@ let OPEN_TRANSFER_COMMAND: [UInt8] = [0x02, 0x0D, 0x0A] // 开启数据发送命令 let DEVICE_DATA_VIEW_WIDTH = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View宽 let DEVICE_DATA_VIEW_HEIGHT = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View高 +let SCHEMA_VERSION = UInt64(0) // Realm数据库版本 public enum Constant: String { // 用户相关的key值 diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift new file mode 100644 index 0000000..a716369 --- /dev/null +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -0,0 +1,76 @@ +// +// EventTaskRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskRealmManager { + public static let shared = EventTaskRealmManager() + + let realm: Realm = { + let migration = EventTaskMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存事件记录到本地 + * */ + func addEventTask(model: NewEventTaskModel) { + let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let results = queryTaskEventById(id: model.taskId) + if results.count == 0 { + try! realm.write { + realm.add(eventObject) + } + } + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspection(inspectionId: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + } + + /** + * 查询所有事件数据 + */ + func queryAllTaskEvent() -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEvent(createTime: String, name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + } + + /** + * 条件查询巡检数据-根据事件标签查询 + */ + func queryTaskEventByName(name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEventById(id: String) -> Results { + realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + } + + func isAddSuccess(taskId: String) -> Bool { + let results = queryTaskEventById(id: taskId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift new file mode 100644 index 0000000..a484463 --- /dev/null +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -0,0 +1,72 @@ +// +// InspectionRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionRealmManager { + public static let shared = InspectionRealmManager() + + let realm: Realm = { + let migration = InspectionMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存巡检记录到本地 + * */ + func addInspection(newModel: NewInspectionModel) { + let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) + let results = queryInspectionById(id: newModel.id) + if results.count == 0 { + try! realm.write { + realm.add(insObject) + } + } + } + + /** + * 查询所有巡检数据 + */ + func queryAllInspection() -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspectionById(id: String) -> Results { + realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspection(startTime: String, endTime: String, name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + } + + /** + * 条件查询巡检数据-根据巡检标签查询 + */ + func queryInspectionByName(name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + } + + /** + * 判断是否插入成功 + */ + func isAddSuccess(inspectionId: String) -> Bool { + let results = queryInspectionById(id: inspectionId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/RealmConfiguration.swift b/LaserMethane/Util/RealmConfiguration.swift new file mode 100644 index 0000000..54d8b83 --- /dev/null +++ b/LaserMethane/Util/RealmConfiguration.swift @@ -0,0 +1,25 @@ +// +// RealmConfiguration.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +struct RealmConfiguration { + static func inspectionConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("inspection.realm") + return Realm.Configuration(fileURL: url) + } + + static func eventTaskConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("eventTask.realm") + return Realm.Configuration(fileURL: url) + } +} diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index 4f4617a..7b7b415 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -410,8 +410,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": true, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -420,8 +420,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": false, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -703,10 +703,10 @@ isGeneratingTask = false alarmCount = 0 } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) } case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + view.makeToast("保存失败,网络异常", duration: 2, position: .center) } }) } diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift new file mode 100644 index 0000000..a52e1e5 --- /dev/null +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -0,0 +1,45 @@ +// +// InspectionLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var startTime: String = "" // 开始时间 + @objc dynamic var endTime: String = "" // 结束时间 + @objc dynamic var date: String = "" // 日期 + @objc dynamic var startLng: Double = 0.0 // 开始经度 + @objc dynamic var startLat: Double = 0.0 // 开始纬度 + @objc dynamic var endLng: Double = 0.0 // 结束经度 + @objc dynamic var endLat: Double = 0.0 // 结束维度 + @objc dynamic var routes: String = "" // 路线Json + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(inspectionId: String = "", name: String = "", startTime: String = "", + endTime: String = "", date: String = "", startLng: Double, startLat: Double, + endLng: Double, endLat: Double, routes: String = "") { + self.init() + self.inspectionId = inspectionId + self.name = name + self.startTime = startTime + self.endTime = endTime + self.date = date + self.startLng = startLng + self.startLat = startLat + self.endLng = endLng + self.endLat = endLat + self.routes = routes + } +} diff --git a/LaserMethane/Protocol/RealmInitializer.swift b/LaserMethane/Protocol/RealmInitializer.swift new file mode 100644 index 0000000..7631888 --- /dev/null +++ b/LaserMethane/Protocol/RealmInitializer.swift @@ -0,0 +1,45 @@ +// +// Initializer.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +protocol RealmInitializer { + func perform() +} + +final class InspectionMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.inspectionConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} + +final class EventTaskMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.eventTaskConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} diff --git a/LaserMethane/Util/Constant.swift b/LaserMethane/Util/Constant.swift index a50b95f..cd568e8 100644 --- a/LaserMethane/Util/Constant.swift +++ b/LaserMethane/Util/Constant.swift @@ -15,6 +15,7 @@ let OPEN_TRANSFER_COMMAND: [UInt8] = [0x02, 0x0D, 0x0A] // 开启数据发送命令 let DEVICE_DATA_VIEW_WIDTH = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View宽 let DEVICE_DATA_VIEW_HEIGHT = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View高 +let SCHEMA_VERSION = UInt64(0) // Realm数据库版本 public enum Constant: String { // 用户相关的key值 diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift new file mode 100644 index 0000000..a716369 --- /dev/null +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -0,0 +1,76 @@ +// +// EventTaskRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskRealmManager { + public static let shared = EventTaskRealmManager() + + let realm: Realm = { + let migration = EventTaskMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存事件记录到本地 + * */ + func addEventTask(model: NewEventTaskModel) { + let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let results = queryTaskEventById(id: model.taskId) + if results.count == 0 { + try! realm.write { + realm.add(eventObject) + } + } + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspection(inspectionId: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + } + + /** + * 查询所有事件数据 + */ + func queryAllTaskEvent() -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEvent(createTime: String, name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + } + + /** + * 条件查询巡检数据-根据事件标签查询 + */ + func queryTaskEventByName(name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEventById(id: String) -> Results { + realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + } + + func isAddSuccess(taskId: String) -> Bool { + let results = queryTaskEventById(id: taskId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift new file mode 100644 index 0000000..a484463 --- /dev/null +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -0,0 +1,72 @@ +// +// InspectionRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionRealmManager { + public static let shared = InspectionRealmManager() + + let realm: Realm = { + let migration = InspectionMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存巡检记录到本地 + * */ + func addInspection(newModel: NewInspectionModel) { + let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) + let results = queryInspectionById(id: newModel.id) + if results.count == 0 { + try! realm.write { + realm.add(insObject) + } + } + } + + /** + * 查询所有巡检数据 + */ + func queryAllInspection() -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspectionById(id: String) -> Results { + realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspection(startTime: String, endTime: String, name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + } + + /** + * 条件查询巡检数据-根据巡检标签查询 + */ + func queryInspectionByName(name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + } + + /** + * 判断是否插入成功 + */ + func isAddSuccess(inspectionId: String) -> Bool { + let results = queryInspectionById(id: inspectionId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/RealmConfiguration.swift b/LaserMethane/Util/RealmConfiguration.swift new file mode 100644 index 0000000..54d8b83 --- /dev/null +++ b/LaserMethane/Util/RealmConfiguration.swift @@ -0,0 +1,25 @@ +// +// RealmConfiguration.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +struct RealmConfiguration { + static func inspectionConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("inspection.realm") + return Realm.Configuration(fileURL: url) + } + + static func eventTaskConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("eventTask.realm") + return Realm.Configuration(fileURL: url) + } +} diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index 4f4617a..7b7b415 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -410,8 +410,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": true, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -420,8 +420,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": false, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -703,10 +703,10 @@ isGeneratingTask = false alarmCount = 0 } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) } case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + view.makeToast("保存失败,网络异常", duration: 2, position: .center) } }) } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 5fb076e..305282d 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -20,7 +20,6 @@ private var longitude: Double! private var latitude: Double! - @IBOutlet var rootView: UIView! @IBOutlet var firstView: UIView! @IBOutlet var secondView: UIView! @IBOutlet var thirdView: UIView! @@ -68,7 +67,7 @@ } func setupLayerView() { - rootView.backgroundColor = [238, 238, 238].transferUIColor() + view.backgroundColor = [238, 238, 238].transferUIColor() LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) if isWarning! { @@ -88,7 +87,7 @@ func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let length = string.lengthOfBytes(using: .utf8) - for loopIndex in 0 ..< length { + for loopIndex in 0.. String { @@ -203,26 +202,6 @@ // GMT时间 转字符串,直接是系统当前时间 return dateformatter.string(from: Date()) } -} - -extension NewEventViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate { - func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { - let tackedImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage - uploadImage(image: tackedImage, quality: 0.5) - dismiss(animated: true, completion: nil) - } -} - -extension NewEventViewController: PhotoPickerControllerDelegate { - func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) { - result.getImage(imageHandler: { [self] image, _, _ in - if let image = image { - uploadImage(image: image, quality: 0.75) // 75%压缩比 - } - }, completionHandler: { images in - print("图片数组: \(images)") - }) - } func uploadImage(image: UIImage, quality: CGFloat) { index += 1 @@ -259,6 +238,26 @@ } } +extension NewEventViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate { + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { + let tackedImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage + uploadImage(image: tackedImage, quality: 0.5) + dismiss(animated: true, completion: nil) + } +} + +extension NewEventViewController: PhotoPickerControllerDelegate { + func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) { + result.getImage(imageHandler: { [self] image, _, _ in + if let image = image { + uploadImage(image: image, quality: 0.75) // 75%压缩比 + } + }, completionHandler: { images in + print("图片数组: \(images)") + }) + } +} + extension NewEventViewController: UICollectionViewDataSource { // 每行几个 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { @@ -274,11 +273,11 @@ let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) - .loadDiskFileSynchronously() - .placeholder(UIImage(named: "load_imag_error.png")) - .cacheMemoryOnly() - .fade(duration: 0.25) - .set(to: cell.imageView) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) // 传递点击按钮的位置 cell.delButton.tag = row cell.delButton.addTarget(self, action: #selector(delImageAction), for: .touchUpInside) diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift new file mode 100644 index 0000000..a52e1e5 --- /dev/null +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -0,0 +1,45 @@ +// +// InspectionLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var startTime: String = "" // 开始时间 + @objc dynamic var endTime: String = "" // 结束时间 + @objc dynamic var date: String = "" // 日期 + @objc dynamic var startLng: Double = 0.0 // 开始经度 + @objc dynamic var startLat: Double = 0.0 // 开始纬度 + @objc dynamic var endLng: Double = 0.0 // 结束经度 + @objc dynamic var endLat: Double = 0.0 // 结束维度 + @objc dynamic var routes: String = "" // 路线Json + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(inspectionId: String = "", name: String = "", startTime: String = "", + endTime: String = "", date: String = "", startLng: Double, startLat: Double, + endLng: Double, endLat: Double, routes: String = "") { + self.init() + self.inspectionId = inspectionId + self.name = name + self.startTime = startTime + self.endTime = endTime + self.date = date + self.startLng = startLng + self.startLat = startLat + self.endLng = endLng + self.endLat = endLat + self.routes = routes + } +} diff --git a/LaserMethane/Protocol/RealmInitializer.swift b/LaserMethane/Protocol/RealmInitializer.swift new file mode 100644 index 0000000..7631888 --- /dev/null +++ b/LaserMethane/Protocol/RealmInitializer.swift @@ -0,0 +1,45 @@ +// +// Initializer.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +protocol RealmInitializer { + func perform() +} + +final class InspectionMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.inspectionConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} + +final class EventTaskMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.eventTaskConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} diff --git a/LaserMethane/Util/Constant.swift b/LaserMethane/Util/Constant.swift index a50b95f..cd568e8 100644 --- a/LaserMethane/Util/Constant.swift +++ b/LaserMethane/Util/Constant.swift @@ -15,6 +15,7 @@ let OPEN_TRANSFER_COMMAND: [UInt8] = [0x02, 0x0D, 0x0A] // 开启数据发送命令 let DEVICE_DATA_VIEW_WIDTH = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View宽 let DEVICE_DATA_VIEW_HEIGHT = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View高 +let SCHEMA_VERSION = UInt64(0) // Realm数据库版本 public enum Constant: String { // 用户相关的key值 diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift new file mode 100644 index 0000000..a716369 --- /dev/null +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -0,0 +1,76 @@ +// +// EventTaskRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskRealmManager { + public static let shared = EventTaskRealmManager() + + let realm: Realm = { + let migration = EventTaskMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存事件记录到本地 + * */ + func addEventTask(model: NewEventTaskModel) { + let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let results = queryTaskEventById(id: model.taskId) + if results.count == 0 { + try! realm.write { + realm.add(eventObject) + } + } + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspection(inspectionId: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + } + + /** + * 查询所有事件数据 + */ + func queryAllTaskEvent() -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEvent(createTime: String, name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + } + + /** + * 条件查询巡检数据-根据事件标签查询 + */ + func queryTaskEventByName(name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEventById(id: String) -> Results { + realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + } + + func isAddSuccess(taskId: String) -> Bool { + let results = queryTaskEventById(id: taskId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift new file mode 100644 index 0000000..a484463 --- /dev/null +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -0,0 +1,72 @@ +// +// InspectionRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionRealmManager { + public static let shared = InspectionRealmManager() + + let realm: Realm = { + let migration = InspectionMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存巡检记录到本地 + * */ + func addInspection(newModel: NewInspectionModel) { + let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) + let results = queryInspectionById(id: newModel.id) + if results.count == 0 { + try! realm.write { + realm.add(insObject) + } + } + } + + /** + * 查询所有巡检数据 + */ + func queryAllInspection() -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspectionById(id: String) -> Results { + realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspection(startTime: String, endTime: String, name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + } + + /** + * 条件查询巡检数据-根据巡检标签查询 + */ + func queryInspectionByName(name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + } + + /** + * 判断是否插入成功 + */ + func isAddSuccess(inspectionId: String) -> Bool { + let results = queryInspectionById(id: inspectionId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/RealmConfiguration.swift b/LaserMethane/Util/RealmConfiguration.swift new file mode 100644 index 0000000..54d8b83 --- /dev/null +++ b/LaserMethane/Util/RealmConfiguration.swift @@ -0,0 +1,25 @@ +// +// RealmConfiguration.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +struct RealmConfiguration { + static func inspectionConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("inspection.realm") + return Realm.Configuration(fileURL: url) + } + + static func eventTaskConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("eventTask.realm") + return Realm.Configuration(fileURL: url) + } +} diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index 4f4617a..7b7b415 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -410,8 +410,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": true, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -420,8 +420,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": false, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -703,10 +703,10 @@ isGeneratingTask = false alarmCount = 0 } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) } case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + view.makeToast("保存失败,网络异常", duration: 2, position: .center) } }) } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 5fb076e..305282d 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -20,7 +20,6 @@ private var longitude: Double! private var latitude: Double! - @IBOutlet var rootView: UIView! @IBOutlet var firstView: UIView! @IBOutlet var secondView: UIView! @IBOutlet var thirdView: UIView! @@ -68,7 +67,7 @@ } func setupLayerView() { - rootView.backgroundColor = [238, 238, 238].transferUIColor() + view.backgroundColor = [238, 238, 238].transferUIColor() LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) if isWarning! { @@ -88,7 +87,7 @@ func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let length = string.lengthOfBytes(using: .utf8) - for loopIndex in 0 ..< length { + for loopIndex in 0.. String { @@ -203,26 +202,6 @@ // GMT时间 转字符串,直接是系统当前时间 return dateformatter.string(from: Date()) } -} - -extension NewEventViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate { - func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { - let tackedImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage - uploadImage(image: tackedImage, quality: 0.5) - dismiss(animated: true, completion: nil) - } -} - -extension NewEventViewController: PhotoPickerControllerDelegate { - func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) { - result.getImage(imageHandler: { [self] image, _, _ in - if let image = image { - uploadImage(image: image, quality: 0.75) // 75%压缩比 - } - }, completionHandler: { images in - print("图片数组: \(images)") - }) - } func uploadImage(image: UIImage, quality: CGFloat) { index += 1 @@ -259,6 +238,26 @@ } } +extension NewEventViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate { + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { + let tackedImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage + uploadImage(image: tackedImage, quality: 0.5) + dismiss(animated: true, completion: nil) + } +} + +extension NewEventViewController: PhotoPickerControllerDelegate { + func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) { + result.getImage(imageHandler: { [self] image, _, _ in + if let image = image { + uploadImage(image: image, quality: 0.75) // 75%压缩比 + } + }, completionHandler: { images in + print("图片数组: \(images)") + }) + } +} + extension NewEventViewController: UICollectionViewDataSource { // 每行几个 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { @@ -274,11 +273,11 @@ let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) - .loadDiskFileSynchronously() - .placeholder(UIImage(named: "load_imag_error.png")) - .cacheMemoryOnly() - .fade(duration: 0.25) - .set(to: cell.imageView) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) // 传递点击按钮的位置 cell.delButton.tag = row cell.delButton.addTarget(self, action: #selector(delImageAction), for: .touchUpInside) diff --git a/LaserMethane/ViewController/Map/NewEventViewController.xib b/LaserMethane/ViewController/Map/NewEventViewController.xib index 75be488..7e636d5 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.xib +++ b/LaserMethane/ViewController/Map/NewEventViewController.xib @@ -15,7 +15,6 @@ - @@ -96,7 +95,7 @@ - + @@ -138,7 +137,7 @@ - + diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift new file mode 100644 index 0000000..a52e1e5 --- /dev/null +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -0,0 +1,45 @@ +// +// InspectionLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var startTime: String = "" // 开始时间 + @objc dynamic var endTime: String = "" // 结束时间 + @objc dynamic var date: String = "" // 日期 + @objc dynamic var startLng: Double = 0.0 // 开始经度 + @objc dynamic var startLat: Double = 0.0 // 开始纬度 + @objc dynamic var endLng: Double = 0.0 // 结束经度 + @objc dynamic var endLat: Double = 0.0 // 结束维度 + @objc dynamic var routes: String = "" // 路线Json + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(inspectionId: String = "", name: String = "", startTime: String = "", + endTime: String = "", date: String = "", startLng: Double, startLat: Double, + endLng: Double, endLat: Double, routes: String = "") { + self.init() + self.inspectionId = inspectionId + self.name = name + self.startTime = startTime + self.endTime = endTime + self.date = date + self.startLng = startLng + self.startLat = startLat + self.endLng = endLng + self.endLat = endLat + self.routes = routes + } +} diff --git a/LaserMethane/Protocol/RealmInitializer.swift b/LaserMethane/Protocol/RealmInitializer.swift new file mode 100644 index 0000000..7631888 --- /dev/null +++ b/LaserMethane/Protocol/RealmInitializer.swift @@ -0,0 +1,45 @@ +// +// Initializer.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +protocol RealmInitializer { + func perform() +} + +final class InspectionMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.inspectionConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} + +final class EventTaskMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.eventTaskConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} diff --git a/LaserMethane/Util/Constant.swift b/LaserMethane/Util/Constant.swift index a50b95f..cd568e8 100644 --- a/LaserMethane/Util/Constant.swift +++ b/LaserMethane/Util/Constant.swift @@ -15,6 +15,7 @@ let OPEN_TRANSFER_COMMAND: [UInt8] = [0x02, 0x0D, 0x0A] // 开启数据发送命令 let DEVICE_DATA_VIEW_WIDTH = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View宽 let DEVICE_DATA_VIEW_HEIGHT = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View高 +let SCHEMA_VERSION = UInt64(0) // Realm数据库版本 public enum Constant: String { // 用户相关的key值 diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift new file mode 100644 index 0000000..a716369 --- /dev/null +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -0,0 +1,76 @@ +// +// EventTaskRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskRealmManager { + public static let shared = EventTaskRealmManager() + + let realm: Realm = { + let migration = EventTaskMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存事件记录到本地 + * */ + func addEventTask(model: NewEventTaskModel) { + let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let results = queryTaskEventById(id: model.taskId) + if results.count == 0 { + try! realm.write { + realm.add(eventObject) + } + } + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspection(inspectionId: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + } + + /** + * 查询所有事件数据 + */ + func queryAllTaskEvent() -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEvent(createTime: String, name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + } + + /** + * 条件查询巡检数据-根据事件标签查询 + */ + func queryTaskEventByName(name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEventById(id: String) -> Results { + realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + } + + func isAddSuccess(taskId: String) -> Bool { + let results = queryTaskEventById(id: taskId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift new file mode 100644 index 0000000..a484463 --- /dev/null +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -0,0 +1,72 @@ +// +// InspectionRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionRealmManager { + public static let shared = InspectionRealmManager() + + let realm: Realm = { + let migration = InspectionMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存巡检记录到本地 + * */ + func addInspection(newModel: NewInspectionModel) { + let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) + let results = queryInspectionById(id: newModel.id) + if results.count == 0 { + try! realm.write { + realm.add(insObject) + } + } + } + + /** + * 查询所有巡检数据 + */ + func queryAllInspection() -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspectionById(id: String) -> Results { + realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspection(startTime: String, endTime: String, name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + } + + /** + * 条件查询巡检数据-根据巡检标签查询 + */ + func queryInspectionByName(name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + } + + /** + * 判断是否插入成功 + */ + func isAddSuccess(inspectionId: String) -> Bool { + let results = queryInspectionById(id: inspectionId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/RealmConfiguration.swift b/LaserMethane/Util/RealmConfiguration.swift new file mode 100644 index 0000000..54d8b83 --- /dev/null +++ b/LaserMethane/Util/RealmConfiguration.swift @@ -0,0 +1,25 @@ +// +// RealmConfiguration.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +struct RealmConfiguration { + static func inspectionConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("inspection.realm") + return Realm.Configuration(fileURL: url) + } + + static func eventTaskConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("eventTask.realm") + return Realm.Configuration(fileURL: url) + } +} diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index 4f4617a..7b7b415 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -410,8 +410,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": true, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -420,8 +420,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": false, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -703,10 +703,10 @@ isGeneratingTask = false alarmCount = 0 } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) } case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + view.makeToast("保存失败,网络异常", duration: 2, position: .center) } }) } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 5fb076e..305282d 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -20,7 +20,6 @@ private var longitude: Double! private var latitude: Double! - @IBOutlet var rootView: UIView! @IBOutlet var firstView: UIView! @IBOutlet var secondView: UIView! @IBOutlet var thirdView: UIView! @@ -68,7 +67,7 @@ } func setupLayerView() { - rootView.backgroundColor = [238, 238, 238].transferUIColor() + view.backgroundColor = [238, 238, 238].transferUIColor() LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) if isWarning! { @@ -88,7 +87,7 @@ func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let length = string.lengthOfBytes(using: .utf8) - for loopIndex in 0 ..< length { + for loopIndex in 0.. String { @@ -203,26 +202,6 @@ // GMT时间 转字符串,直接是系统当前时间 return dateformatter.string(from: Date()) } -} - -extension NewEventViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate { - func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { - let tackedImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage - uploadImage(image: tackedImage, quality: 0.5) - dismiss(animated: true, completion: nil) - } -} - -extension NewEventViewController: PhotoPickerControllerDelegate { - func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) { - result.getImage(imageHandler: { [self] image, _, _ in - if let image = image { - uploadImage(image: image, quality: 0.75) // 75%压缩比 - } - }, completionHandler: { images in - print("图片数组: \(images)") - }) - } func uploadImage(image: UIImage, quality: CGFloat) { index += 1 @@ -259,6 +238,26 @@ } } +extension NewEventViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate { + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { + let tackedImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage + uploadImage(image: tackedImage, quality: 0.5) + dismiss(animated: true, completion: nil) + } +} + +extension NewEventViewController: PhotoPickerControllerDelegate { + func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) { + result.getImage(imageHandler: { [self] image, _, _ in + if let image = image { + uploadImage(image: image, quality: 0.75) // 75%压缩比 + } + }, completionHandler: { images in + print("图片数组: \(images)") + }) + } +} + extension NewEventViewController: UICollectionViewDataSource { // 每行几个 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { @@ -274,11 +273,11 @@ let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) - .loadDiskFileSynchronously() - .placeholder(UIImage(named: "load_imag_error.png")) - .cacheMemoryOnly() - .fade(duration: 0.25) - .set(to: cell.imageView) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) // 传递点击按钮的位置 cell.delButton.tag = row cell.delButton.addTarget(self, action: #selector(delImageAction), for: .touchUpInside) diff --git a/LaserMethane/ViewController/Map/NewEventViewController.xib b/LaserMethane/ViewController/Map/NewEventViewController.xib index 75be488..7e636d5 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.xib +++ b/LaserMethane/ViewController/Map/NewEventViewController.xib @@ -15,7 +15,6 @@ - @@ -96,7 +95,7 @@ - + @@ -138,7 +137,7 @@ - + diff --git a/LaserMethane/ViewController/Map/SingModeMapViewController.swift b/LaserMethane/ViewController/Map/SingModeMapViewController.swift index a76316b..c618044 100644 --- a/LaserMethane/ViewController/Map/SingModeMapViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeMapViewController.swift @@ -19,6 +19,8 @@ private let defaults = Defaults.shared private let defaultKey = Key("InspectionCacheModel") private let statusKey = Key("inspectionStatus") + private let inspectionShared = InspectionRealmManager.shared + private let taskShared = EventTaskRealmManager.shared private var mapView: MAMapView! private var topTagView: UIView! @@ -295,14 +297,28 @@ let endLat = keychain[Constant.CurrentLatitude.rawValue]! as String // 提交巡检 let timeInterval: TimeInterval = Date().timeIntervalSince1970 - let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": Double(endLng)!, "endLat": Double(endLat)!, - "routes": model.routes, "user": model.user] - // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] - print("提交参数: \(param)") - //保存本地数据库 + model.endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + model.endLng = Double(endLng)! + model.endLat = Double(endLat)! + // 保存本地数据库 + inspectionShared.addInspection(newModel: model!) + if inspectionShared.isAddSuccess(inspectionId: model.id) { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { [self] _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存失败,已替您缓存到本地", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { [self] _ in + defaults.set(false, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -369,7 +385,7 @@ let lat = keychain[Constant.CurrentLatitude.rawValue]! as String print("新建事件位置信息: [\(lng), \(lat)]") - let newEventViewController = NewEventViewController(nibName: "NewEventViewController", bundle: nil) + let newEventViewController = SingModeNewEventViewController(nibName: "SingModeNewEventViewController", bundle: nil) // 委托代理 valueDelegate = newEventViewController let selectController = UIAlertController(title: "选择事件类型", message: nil, preferredStyle: .alert) @@ -378,8 +394,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": true, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -388,8 +404,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": false, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -656,27 +672,16 @@ let longitude = keychain[Constant.CurrentLongitude.rawValue]! as String let latitude = keychain[Constant.CurrentLatitude.rawValue]! as String // 提交事件 - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": Double(longitude)!, - "lat": Double(latitude)!, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] - print("提交参数: \(param)") -// Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": keychain[Constant.Token.rawValue]!]) -// .responseJSON(completionHandler: { [self] response in -// switch response.result { -// case let .success(value): -// let actionModel = ActionResultModel(respJson: JSON(value)) -// if actionModel.code == 200 { -// view.makeToast("保存成功") -// isGeneratingTask = false -// alarmCount = 0 -// } else { -// AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") -// } -// case .failure: -// AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") -// } -// }) + let taskId = "t".id() + let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: model.id, name: model.name, createTime: model.startTime, type: "报警事件", lng: Double(longitude)!, lat: Double(latitude)!, data: Double(maxValue)!, images: "", description: "自动报警记录", user: "智巡宝") + taskShared.addEventTask(model: eventModel) + if taskShared.isAddSuccess(taskId: taskId) { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } } } diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift new file mode 100644 index 0000000..a52e1e5 --- /dev/null +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -0,0 +1,45 @@ +// +// InspectionLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var startTime: String = "" // 开始时间 + @objc dynamic var endTime: String = "" // 结束时间 + @objc dynamic var date: String = "" // 日期 + @objc dynamic var startLng: Double = 0.0 // 开始经度 + @objc dynamic var startLat: Double = 0.0 // 开始纬度 + @objc dynamic var endLng: Double = 0.0 // 结束经度 + @objc dynamic var endLat: Double = 0.0 // 结束维度 + @objc dynamic var routes: String = "" // 路线Json + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(inspectionId: String = "", name: String = "", startTime: String = "", + endTime: String = "", date: String = "", startLng: Double, startLat: Double, + endLng: Double, endLat: Double, routes: String = "") { + self.init() + self.inspectionId = inspectionId + self.name = name + self.startTime = startTime + self.endTime = endTime + self.date = date + self.startLng = startLng + self.startLat = startLat + self.endLng = endLng + self.endLat = endLat + self.routes = routes + } +} diff --git a/LaserMethane/Protocol/RealmInitializer.swift b/LaserMethane/Protocol/RealmInitializer.swift new file mode 100644 index 0000000..7631888 --- /dev/null +++ b/LaserMethane/Protocol/RealmInitializer.swift @@ -0,0 +1,45 @@ +// +// Initializer.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +protocol RealmInitializer { + func perform() +} + +final class InspectionMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.inspectionConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} + +final class EventTaskMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.eventTaskConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} diff --git a/LaserMethane/Util/Constant.swift b/LaserMethane/Util/Constant.swift index a50b95f..cd568e8 100644 --- a/LaserMethane/Util/Constant.swift +++ b/LaserMethane/Util/Constant.swift @@ -15,6 +15,7 @@ let OPEN_TRANSFER_COMMAND: [UInt8] = [0x02, 0x0D, 0x0A] // 开启数据发送命令 let DEVICE_DATA_VIEW_WIDTH = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View宽 let DEVICE_DATA_VIEW_HEIGHT = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View高 +let SCHEMA_VERSION = UInt64(0) // Realm数据库版本 public enum Constant: String { // 用户相关的key值 diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift new file mode 100644 index 0000000..a716369 --- /dev/null +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -0,0 +1,76 @@ +// +// EventTaskRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskRealmManager { + public static let shared = EventTaskRealmManager() + + let realm: Realm = { + let migration = EventTaskMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存事件记录到本地 + * */ + func addEventTask(model: NewEventTaskModel) { + let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let results = queryTaskEventById(id: model.taskId) + if results.count == 0 { + try! realm.write { + realm.add(eventObject) + } + } + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspection(inspectionId: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + } + + /** + * 查询所有事件数据 + */ + func queryAllTaskEvent() -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEvent(createTime: String, name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + } + + /** + * 条件查询巡检数据-根据事件标签查询 + */ + func queryTaskEventByName(name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEventById(id: String) -> Results { + realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + } + + func isAddSuccess(taskId: String) -> Bool { + let results = queryTaskEventById(id: taskId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift new file mode 100644 index 0000000..a484463 --- /dev/null +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -0,0 +1,72 @@ +// +// InspectionRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionRealmManager { + public static let shared = InspectionRealmManager() + + let realm: Realm = { + let migration = InspectionMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存巡检记录到本地 + * */ + func addInspection(newModel: NewInspectionModel) { + let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) + let results = queryInspectionById(id: newModel.id) + if results.count == 0 { + try! realm.write { + realm.add(insObject) + } + } + } + + /** + * 查询所有巡检数据 + */ + func queryAllInspection() -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspectionById(id: String) -> Results { + realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspection(startTime: String, endTime: String, name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + } + + /** + * 条件查询巡检数据-根据巡检标签查询 + */ + func queryInspectionByName(name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + } + + /** + * 判断是否插入成功 + */ + func isAddSuccess(inspectionId: String) -> Bool { + let results = queryInspectionById(id: inspectionId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/RealmConfiguration.swift b/LaserMethane/Util/RealmConfiguration.swift new file mode 100644 index 0000000..54d8b83 --- /dev/null +++ b/LaserMethane/Util/RealmConfiguration.swift @@ -0,0 +1,25 @@ +// +// RealmConfiguration.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +struct RealmConfiguration { + static func inspectionConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("inspection.realm") + return Realm.Configuration(fileURL: url) + } + + static func eventTaskConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("eventTask.realm") + return Realm.Configuration(fileURL: url) + } +} diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index 4f4617a..7b7b415 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -410,8 +410,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": true, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -420,8 +420,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": false, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -703,10 +703,10 @@ isGeneratingTask = false alarmCount = 0 } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) } case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + view.makeToast("保存失败,网络异常", duration: 2, position: .center) } }) } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 5fb076e..305282d 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -20,7 +20,6 @@ private var longitude: Double! private var latitude: Double! - @IBOutlet var rootView: UIView! @IBOutlet var firstView: UIView! @IBOutlet var secondView: UIView! @IBOutlet var thirdView: UIView! @@ -68,7 +67,7 @@ } func setupLayerView() { - rootView.backgroundColor = [238, 238, 238].transferUIColor() + view.backgroundColor = [238, 238, 238].transferUIColor() LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) if isWarning! { @@ -88,7 +87,7 @@ func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let length = string.lengthOfBytes(using: .utf8) - for loopIndex in 0 ..< length { + for loopIndex in 0.. String { @@ -203,26 +202,6 @@ // GMT时间 转字符串,直接是系统当前时间 return dateformatter.string(from: Date()) } -} - -extension NewEventViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate { - func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { - let tackedImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage - uploadImage(image: tackedImage, quality: 0.5) - dismiss(animated: true, completion: nil) - } -} - -extension NewEventViewController: PhotoPickerControllerDelegate { - func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) { - result.getImage(imageHandler: { [self] image, _, _ in - if let image = image { - uploadImage(image: image, quality: 0.75) // 75%压缩比 - } - }, completionHandler: { images in - print("图片数组: \(images)") - }) - } func uploadImage(image: UIImage, quality: CGFloat) { index += 1 @@ -259,6 +238,26 @@ } } +extension NewEventViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate { + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { + let tackedImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage + uploadImage(image: tackedImage, quality: 0.5) + dismiss(animated: true, completion: nil) + } +} + +extension NewEventViewController: PhotoPickerControllerDelegate { + func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) { + result.getImage(imageHandler: { [self] image, _, _ in + if let image = image { + uploadImage(image: image, quality: 0.75) // 75%压缩比 + } + }, completionHandler: { images in + print("图片数组: \(images)") + }) + } +} + extension NewEventViewController: UICollectionViewDataSource { // 每行几个 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { @@ -274,11 +273,11 @@ let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) - .loadDiskFileSynchronously() - .placeholder(UIImage(named: "load_imag_error.png")) - .cacheMemoryOnly() - .fade(duration: 0.25) - .set(to: cell.imageView) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) // 传递点击按钮的位置 cell.delButton.tag = row cell.delButton.addTarget(self, action: #selector(delImageAction), for: .touchUpInside) diff --git a/LaserMethane/ViewController/Map/NewEventViewController.xib b/LaserMethane/ViewController/Map/NewEventViewController.xib index 75be488..7e636d5 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.xib +++ b/LaserMethane/ViewController/Map/NewEventViewController.xib @@ -15,7 +15,6 @@ - @@ -96,7 +95,7 @@ - + @@ -138,7 +137,7 @@ - + diff --git a/LaserMethane/ViewController/Map/SingModeMapViewController.swift b/LaserMethane/ViewController/Map/SingModeMapViewController.swift index a76316b..c618044 100644 --- a/LaserMethane/ViewController/Map/SingModeMapViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeMapViewController.swift @@ -19,6 +19,8 @@ private let defaults = Defaults.shared private let defaultKey = Key("InspectionCacheModel") private let statusKey = Key("inspectionStatus") + private let inspectionShared = InspectionRealmManager.shared + private let taskShared = EventTaskRealmManager.shared private var mapView: MAMapView! private var topTagView: UIView! @@ -295,14 +297,28 @@ let endLat = keychain[Constant.CurrentLatitude.rawValue]! as String // 提交巡检 let timeInterval: TimeInterval = Date().timeIntervalSince1970 - let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": Double(endLng)!, "endLat": Double(endLat)!, - "routes": model.routes, "user": model.user] - // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] - print("提交参数: \(param)") - //保存本地数据库 + model.endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + model.endLng = Double(endLng)! + model.endLat = Double(endLat)! + // 保存本地数据库 + inspectionShared.addInspection(newModel: model!) + if inspectionShared.isAddSuccess(inspectionId: model.id) { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { [self] _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存失败,已替您缓存到本地", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { [self] _ in + defaults.set(false, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -369,7 +385,7 @@ let lat = keychain[Constant.CurrentLatitude.rawValue]! as String print("新建事件位置信息: [\(lng), \(lat)]") - let newEventViewController = NewEventViewController(nibName: "NewEventViewController", bundle: nil) + let newEventViewController = SingModeNewEventViewController(nibName: "SingModeNewEventViewController", bundle: nil) // 委托代理 valueDelegate = newEventViewController let selectController = UIAlertController(title: "选择事件类型", message: nil, preferredStyle: .alert) @@ -378,8 +394,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": true, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -388,8 +404,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": false, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -656,27 +672,16 @@ let longitude = keychain[Constant.CurrentLongitude.rawValue]! as String let latitude = keychain[Constant.CurrentLatitude.rawValue]! as String // 提交事件 - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": Double(longitude)!, - "lat": Double(latitude)!, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] - print("提交参数: \(param)") -// Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": keychain[Constant.Token.rawValue]!]) -// .responseJSON(completionHandler: { [self] response in -// switch response.result { -// case let .success(value): -// let actionModel = ActionResultModel(respJson: JSON(value)) -// if actionModel.code == 200 { -// view.makeToast("保存成功") -// isGeneratingTask = false -// alarmCount = 0 -// } else { -// AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") -// } -// case .failure: -// AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") -// } -// }) + let taskId = "t".id() + let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: model.id, name: model.name, createTime: model.startTime, type: "报警事件", lng: Double(longitude)!, lat: Double(latitude)!, data: Double(maxValue)!, images: "", description: "自动报警记录", user: "智巡宝") + taskShared.addEventTask(model: eventModel) + if taskShared.isAddSuccess(taskId: taskId) { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } } } diff --git a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift new file mode 100644 index 0000000..c88313b --- /dev/null +++ b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift @@ -0,0 +1,270 @@ +// +// SingModeNewEventViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Alamofire +import HXPHPicker +import KeychainAccess +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeNewEventViewController: UIViewController, TransferValueDelegate, UITextFieldDelegate { + private let taskShared = EventTaskRealmManager.shared + private var isWarning: Bool! + private var inspectionId: String! + private var inspectionName: String! + private var longitude: Double! + private var latitude: Double! + + @IBOutlet var firstView: UIView! + @IBOutlet var secondView: UIView! + @IBOutlet var thirdView: UIView! + + @IBOutlet var eventTimeLabel: UILabel! + @IBOutlet var eventDescField: UITextField! + @IBOutlet var maxValueField: UITextField! + + @IBOutlet var imageCollectionView: UICollectionView! + @IBOutlet var saveEventButton: UIButton! + + private let keychain = Keychain() + private let dateformatter = DateFormatter() + private var imageUrlArray = [URL]() // 完整的图片url + private var imageArray = [String]() // 上传图片成功后服务器返回的图片数组 + private var index: Int = 0 + + private var eventType = "" + private var eventValueData: Double = -1 + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white + // Do any additional setup after loading the view. + setupLayerView() + eventTimeLabel.text = currentTime() + maxValueField.delegate = self + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + imageCollectionView.reloadData() + } + + func setupLayerView() { + view.backgroundColor = [238, 238, 238].transferUIColor() + LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + if isWarning! { + title = "报警事件记录(单机模式)" + secondView.isHidden = false + LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } else { + title = "自定义事件记录(单机模式)" + secondView.isHidden = true + secondView.removeFromSuperview() // 光隐藏没用,需要完全从它父布局移除,不然会占位,类似Android的GONE和VISIABLE + thirdView.snp.makeConstraints { (make) -> Void in + make.top.equalTo(firstView.frame.height + 20) + } + } + saveEventButton.layer.cornerRadius = 8 + } + + func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + let length = string.lengthOfBytes(using: .utf8) + for loopIndex in 0.. 57 { + return false + } + } + let len = (textField.text?.lengthOfBytes(using: .utf8))! - range.length + string.lengthOfBytes(using: .utf8) + if len > 9 { + return false + } + return true + } + + func transfer(controller: UIViewController, dic: NSDictionary) { + isWarning = dic["isWarning"] as? Bool + inspectionId = dic["inspectionId"] as? String + inspectionName = dic["inspectionName"] as? String + longitude = dic["longitude"] as? Double + latitude = dic["latitude"] as? Double + } + + @IBAction func addImageAction(_ sender: Any) { + let actionSheetController = UIAlertController() + actionSheetController.addAction(UIAlertAction(title: "拍照", style: .default, handler: { [self] _ in + takePicture() + })) + actionSheetController.addAction(UIAlertAction(title: "相册", style: .default, handler: { [self] _ in + selectPicture() + })) + actionSheetController.addAction(UIAlertAction(title: "取消", style: .cancel)) + present(actionSheetController, animated: true, completion: nil) + } + + func takePicture() { + if UIImagePickerController.isSourceTypeAvailable(.camera) { + let picker = UIImagePickerController() + picker.sourceType = .camera + picker.delegate = self + picker.cameraDevice = .rear + picker.cameraCaptureMode = .photo + picker.cameraFlashMode = .auto + picker.allowsEditing = false + present(picker, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "抱歉,无法打开照相机") + } + } + + func selectPicture() { + // 设置与微信主题一致的配置 + let config = PhotoTools.getWXPickerConfig() + config.maximumSelectedPhotoCount = 3 + config.selectOptions = [.photo] + config.allowSelectedTogether = false + config.photoList.allowAddCamera = false // 选图不显示相机 + let pickerController = PhotoPickerController(picker: config) + pickerController.pickerDelegate = self + // 是否选中原图 + pickerController.isOriginal = false + present(pickerController, animated: true, completion: nil) + } + + @IBAction func saveEventAction(_ sender: Any) { + let eventDesc = eventDescField.text?.filterString() + if eventDesc == "" { + AlertHub.shared.showWaringAlert(controller: self, message: "事件情况说明还未填写,请检查") + return + } + if isWarning! { + let maxValue = maxValueField.text?.filterString() + if maxValue == "" { + AlertHub.shared.showWaringAlert(controller: self, message: "最大泄露值还未填写,请检查") + return + } + eventType = "报警事件" + eventValueData = Double(maxValue!)! + } else { + eventType = "自定义事件" + } + // 提交事件 + let taskId = "t".id() + let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: inspectionId!, name: inspectionName!, createTime: eventTimeLabel.text!, type: eventType, lng: longitude!, lat: latitude!, data: eventValueData, images: imageArray.reformat(), description: eventDesc!, user: "智巡宝") + taskShared.addEventTask(model: eventModel) + if taskShared.isAddSuccess(taskId: taskId) { + let alertController = UIAlertController(title: "提示", message: "事件记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { [self] _ in + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } + } + + func currentTime() -> String { + dateformatter.dateFormat = "YYYY-MM-dd HH:mm:ss" // 自定义时间格式 + // GMT时间 转字符串,直接是系统当前时间 + return dateformatter.string(from: Date()) + } + + func addImage(image: UIImage) { + index += 1 + dateformatter.dateFormat = "yyyyMMddHHmmss" + let imageName = "IMG_\(dateformatter.string(from: Date()))_\(index).png" + + let imageData = image.pngData() + let url = imageData?.fromLocalImage(imageName: imageName) + imageArray.append(url!.path) + imageUrlArray.append(url!) // 用于本地展示 + imageCollectionView.reloadData() + } +} + +// 拍照 +extension SingModeNewEventViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate { + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { + let tackedImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage + addImage(image: tackedImage) + dismiss(animated: true, completion: nil) + } +} + +// 选图 +extension SingModeNewEventViewController: PhotoPickerControllerDelegate { + func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) { + result.getImage(imageHandler: { [self] image, _, _ in + if let image = image { + addImage(image: image) + } + }, completionHandler: { images in + print("图片数组: \(images)") + }) + } +} + +extension SingModeNewEventViewController: UICollectionViewDataSource { + // 每行几个 + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + // 有几行 + func numberOfSections(in collectionView: UICollectionView) -> Int { + 1 + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + // 传递点击按钮的位置 + cell.delButton.tag = row + cell.delButton.addTarget(self, action: #selector(delImageAction), for: .touchUpInside) + return cell + } + + @objc func delImageAction(sender: UIButton) { + imageArray.remove(at: sender.tag) + imageUrlArray.remove(at: sender.tag) + imageCollectionView.reloadData() + } +} + +extension SingModeNewEventViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + // 查看大图 + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane.xcodeproj/project.pbxproj b/LaserMethane.xcodeproj/project.pbxproj index 564434e..251f06b 100644 --- a/LaserMethane.xcodeproj/project.pbxproj +++ b/LaserMethane.xcodeproj/project.pbxproj @@ -20,6 +20,9 @@ 656C6BDB26D38B1E00762246 /* EventTaskLocalObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */; }; 656C6BDD26D38D0B00762246 /* EventTaskRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */; }; 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */; }; + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */; }; + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */; }; + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */; }; 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */; }; 656EEBC926C4C7C20054E00E /* ImageCollectionViewDelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */; }; 656EEBCF26C529130054E00E /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656EEBCE26C529130054E00E /* Int.swift */; }; @@ -37,6 +40,7 @@ 65BF7C2526AFDDCD000FEC82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2426AFDDCD000FEC82 /* Assets.xcassets */; }; 65BF7C2826AFDDCD000FEC82 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 65BF7C2626AFDDCD000FEC82 /* LaunchScreen.storyboard */; }; 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */; }; + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65C9F2AA26D4E4770078AAA9 /* Data.swift */; }; 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65D95F2B26C653FF00D61ADC /* Array.swift */; }; 65EB076626BCCA6E00F9C0EC /* TransferIdDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */; }; 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */; }; @@ -101,6 +105,9 @@ 656C6BDA26D38B1E00762246 /* EventTaskLocalObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskLocalObject.swift; sourceTree = ""; }; 656C6BDC26D38D0B00762246 /* EventTaskRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskRealmManager.swift; sourceTree = ""; }; 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectionCacheModel.swift; sourceTree = ""; }; + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewEventTaskModel.swift; sourceTree = ""; }; + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingModeNewEventViewController.swift; sourceTree = ""; }; + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingModeNewEventViewController.xib; sourceTree = ""; }; 656EEBC626C4C7C20054E00E /* ImageCollectionViewDelCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewDelCell.swift; sourceTree = ""; }; 656EEBC726C4C7C20054E00E /* ImageCollectionViewDelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ImageCollectionViewDelCell.xib; sourceTree = ""; }; 656EEBCE26C529130054E00E /* Int.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Int.swift; sourceTree = ""; }; @@ -567,6 +574,7 @@ 65BF7C2926AFDDCD000FEC82 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 65BF7DBD26BA25C50097B132 /* Pods_LaserMethane.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_LaserMethane.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65BF7DD426BB8F880097B132 /* InspectDetailModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectDetailModel.swift; sourceTree = ""; }; + 65C9F2AA26D4E4770078AAA9 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 65D95F2B26C653FF00D61ADC /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 65EB076526BCCA6E00F9C0EC /* TransferIdDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferIdDelegate.swift; sourceTree = ""; }; 65EB076B26BCD76F00F9C0EC /* EventTaskViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTaskViewController.swift; sourceTree = ""; }; @@ -634,6 +642,7 @@ 6518222626AFE9EB00FCC275 /* String.swift */, 656EEBCE26C529130054E00E /* Int.swift */, 65D95F2B26C653FF00D61ADC /* Array.swift */, + 65C9F2AA26D4E4770078AAA9 /* Data.swift */, ); path = Extension; sourceTree = ""; @@ -709,6 +718,8 @@ 65221CD126C0CCE40070D21C /* NewEventViewController.xib */, 65BDB88826CD12D400A627D7 /* SingModeMapViewController.swift */, 65BDB88926CD12D400A627D7 /* SingModeMapViewController.xib */, + 656C6BE426D4D4D900762246 /* SingModeNewEventViewController.swift */, + 656C6BE526D4D4D900762246 /* SingModeNewEventViewController.xib */, ); path = Map; sourceTree = ""; @@ -759,6 +770,7 @@ 656670FC26CB44490036EA1E /* NewInspectionModel.swift */, 656670FE26CB52EE0036EA1E /* NewRouteModel.swift */, 656C6BDE26D3A34F00762246 /* InspectionCacheModel.swift */, + 656C6BE226D4D03100762246 /* NewEventTaskModel.swift */, ); path = Model; sourceTree = ""; @@ -1398,6 +1410,7 @@ 65F2E04B26B25E8200179EBD /* EventDetailViewController.xib in Resources */, 65F2DFFB26B0099800179EBD /* GuideViewController.xib in Resources */, 65F2E02626B1326D00179EBD /* CommonTableViewCell.xib in Resources */, + 656C6BE726D4D4D900762246 /* SingModeNewEventViewController.xib in Resources */, 65F2E01226B0E6D700179EBD /* MainMenuViewController.xib in Resources */, 65EB076E26BCD76F00F9C0EC /* EventTaskViewController.xib in Resources */, 65F2E02E26B1341300179EBD /* SwitchTableViewCell.xib in Resources */, @@ -1478,6 +1491,7 @@ 65F2DFFE26B0128C00179EBD /* ActionResultModel.swift in Sources */, 65F2E04A26B25E8200179EBD /* EventDetailViewController.swift in Sources */, 65F2E04026B1724900179EBD /* EventViewController.swift in Sources */, + 656C6BE626D4D4D900762246 /* SingModeNewEventViewController.swift in Sources */, 656670FF26CB52EE0036EA1E /* NewRouteModel.swift in Sources */, 65F2DFFA26B0099800179EBD /* GuideViewController.swift in Sources */, 65F2E03C26B1723700179EBD /* InspectViewController.swift in Sources */, @@ -1485,6 +1499,7 @@ 656C6BDF26D3A34F00762246 /* InspectionCacheModel.swift in Sources */, 6518222726AFE9EB00FCC275 /* String.swift in Sources */, 656EEBC826C4C7C20054E00E /* ImageCollectionViewDelCell.swift in Sources */, + 65C9F2AB26D4E4770078AAA9 /* Data.swift in Sources */, 65F2E02D26B1341300179EBD /* SwitchTableViewCell.swift in Sources */, 65D95F2C26C653FF00D61ADC /* Array.swift in Sources */, 65EB076D26BCD76F00F9C0EC /* EventTaskViewController.swift in Sources */, @@ -1497,6 +1512,7 @@ 65A10D7426CDEC8600F2D76E /* SingModeSettingViewController.swift in Sources */, 65F2E01426B0E8CA00179EBD /* AlertHub.swift in Sources */, 65BF7DD526BB8F880097B132 /* InspectDetailModel.swift in Sources */, + 656C6BE326D4D03100762246 /* NewEventTaskModel.swift in Sources */, 65221CDF26C11D320070D21C /* LoadingHub.swift in Sources */, 65F2E02126B1242200179EBD /* DefaultTableViewCell.swift in Sources */, 65F2E00426B0129100179EBD /* UserInfoModel.swift in Sources */, diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate index 84b051f..b6fd5e5 100644 --- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate +++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate Binary files differ diff --git a/LaserMethane/Extension/Data.swift b/LaserMethane/Extension/Data.swift new file mode 100644 index 0000000..0fd13cd --- /dev/null +++ b/LaserMethane/Extension/Data.swift @@ -0,0 +1,24 @@ +// +// URL.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Foundation + +extension Data { + func fromLocalImage(imageName: String) -> URL { + let fileManager = FileManager.default + let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0] + let url = cacheDirectory.appendingPathComponent(imageName) + let path = url.path + + guard fileManager.fileExists(atPath: path) else { + /// 通过写入图片数据实现 路径url + fileManager.createFile(atPath: path, contents: self, attributes: nil) + return url + } + return url + } +} diff --git a/LaserMethane/Model/NewEventTaskModel.swift b/LaserMethane/Model/NewEventTaskModel.swift new file mode 100644 index 0000000..49db902 --- /dev/null +++ b/LaserMethane/Model/NewEventTaskModel.swift @@ -0,0 +1,37 @@ +// +// NewEventTaskModel.swift +// LaserMethane +// +// 新建事件数据结构模型 +// Created by 203 on 2021/8/24. +// + +import Foundation + +struct NewEventTaskModel { + var taskId: String = "" + var inspectionId: String = "" + var name: String = "" + var createTime: String = "" + var type: String = "" + var lng: Double = 0.0 + var lat: Double = 0.0 + var data: Double = -1 + var images: String = "" + var description: String = "" + var user: String = "" + + init(taskId: String, inspectionId: String, name: String, createTime: String, type: String, lng: Double, lat: Double, data: Double, images: String, description: String, user: String) { + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.type = type + self.lng = lng + self.lat = lat + self.data = data + self.images = images + self.description = description + self.user = user + } +} diff --git a/LaserMethane/Object/EventTaskLocalObject.swift b/LaserMethane/Object/EventTaskLocalObject.swift new file mode 100644 index 0000000..b1aa322 --- /dev/null +++ b/LaserMethane/Object/EventTaskLocalObject.swift @@ -0,0 +1,45 @@ +// +// EventTaskLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var taskId: String = "" // 事件id + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var createTime: String = "" // 事件创建的时间 + @objc dynamic var lng: Double = 0.0 // 事件经度 + @objc dynamic var lat: Double = 0.0 // 事件纬度 + @objc dynamic var type: String = "" // 事件类型——自定义事件 or 报警事件 + @objc dynamic var data: Double = -1 // 事件泄露数值 + @objc dynamic var images: String = "" // 事件图片 + @objc dynamic var desc: String = "" // 事件描述 + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(taskId: String = "", inspectionId: String = "", name: String = "", + createTime: String = "", lng: Double, lat: Double, type: String = "", + data: Double, images: String = "", desc: String = "") { + self.init() + self.taskId = taskId + self.inspectionId = inspectionId + self.name = name + self.createTime = createTime + self.lng = lng + self.lat = lat + self.type = type + self.data = data + self.images = images + self.desc = desc + } +} diff --git a/LaserMethane/Object/InspectionLocalObject.swift b/LaserMethane/Object/InspectionLocalObject.swift new file mode 100644 index 0000000..a52e1e5 --- /dev/null +++ b/LaserMethane/Object/InspectionLocalObject.swift @@ -0,0 +1,45 @@ +// +// InspectionLocalObject.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionLocalObject: Object { + @objc dynamic var id = 0 // 主键 + @objc dynamic var inspectionId: String = "" // 巡检id + @objc dynamic var name: String = "" // 巡检标签 + @objc dynamic var startTime: String = "" // 开始时间 + @objc dynamic var endTime: String = "" // 结束时间 + @objc dynamic var date: String = "" // 日期 + @objc dynamic var startLng: Double = 0.0 // 开始经度 + @objc dynamic var startLat: Double = 0.0 // 开始纬度 + @objc dynamic var endLng: Double = 0.0 // 结束经度 + @objc dynamic var endLat: Double = 0.0 // 结束维度 + @objc dynamic var routes: String = "" // 路线Json + @objc dynamic var user: String = "智巡宝" // 巡检人——单机模式默认为“智巡宝” + + // 主键自增 + override class func primaryKey() -> String? { + "id" + } + + convenience init(inspectionId: String = "", name: String = "", startTime: String = "", + endTime: String = "", date: String = "", startLng: Double, startLat: Double, + endLng: Double, endLat: Double, routes: String = "") { + self.init() + self.inspectionId = inspectionId + self.name = name + self.startTime = startTime + self.endTime = endTime + self.date = date + self.startLng = startLng + self.startLat = startLat + self.endLng = endLng + self.endLat = endLat + self.routes = routes + } +} diff --git a/LaserMethane/Protocol/RealmInitializer.swift b/LaserMethane/Protocol/RealmInitializer.swift new file mode 100644 index 0000000..7631888 --- /dev/null +++ b/LaserMethane/Protocol/RealmInitializer.swift @@ -0,0 +1,45 @@ +// +// Initializer.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +protocol RealmInitializer { + func perform() +} + +final class InspectionMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.inspectionConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} + +final class EventTaskMigrationInitializer: RealmInitializer { + lazy var config: Realm.Configuration = { + RealmConfiguration.eventTaskConfiguration() + }() + + init() { + print(Realm.Configuration.defaultConfiguration.fileURL!) + } + + func perform() { + config.schemaVersion = SCHEMA_VERSION + config.migrationBlock = { _, _ in + } + } +} diff --git a/LaserMethane/Util/Constant.swift b/LaserMethane/Util/Constant.swift index a50b95f..cd568e8 100644 --- a/LaserMethane/Util/Constant.swift +++ b/LaserMethane/Util/Constant.swift @@ -15,6 +15,7 @@ let OPEN_TRANSFER_COMMAND: [UInt8] = [0x02, 0x0D, 0x0A] // 开启数据发送命令 let DEVICE_DATA_VIEW_WIDTH = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View宽 let DEVICE_DATA_VIEW_HEIGHT = (SCREEN_WIDTH - 40) / 3 // 蓝牙设备数据显示View高 +let SCHEMA_VERSION = UInt64(0) // Realm数据库版本 public enum Constant: String { // 用户相关的key值 diff --git a/LaserMethane/Util/EventTaskRealmManager.swift b/LaserMethane/Util/EventTaskRealmManager.swift new file mode 100644 index 0000000..a716369 --- /dev/null +++ b/LaserMethane/Util/EventTaskRealmManager.swift @@ -0,0 +1,76 @@ +// +// EventTaskRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class EventTaskRealmManager { + public static let shared = EventTaskRealmManager() + + let realm: Realm = { + let migration = EventTaskMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存事件记录到本地 + * */ + func addEventTask(model: NewEventTaskModel) { + let eventObject = EventTaskLocalObject(taskId: model.taskId, inspectionId: model.inspectionId, name: model.name, createTime: model.createTime, lng: model.lng, lat: model.lat, type: model.type, data: model.data, images: model.images, desc: model.description) + let results = queryTaskEventById(id: model.taskId) + if results.count == 0 { + try! realm.write { + realm.add(eventObject) + } + } + } + + /** + * 根据巡检Id查询事件数据 + */ + func queryTaskByInspection(inspectionId: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("inspectionId = %@", inspectionId) + } + + /** + * 查询所有事件数据 + */ + func queryAllTaskEvent() -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEvent(createTime: String, name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("createTime = %@ and name = %@", createTime, name) + } + + /** + * 条件查询巡检数据-根据事件标签查询 + */ + func queryTaskEventByName(name: String) -> Results { + realm.objects(EventTaskLocalObject.self).sorted(byKeyPath: "createTime", ascending: false).filter("name = %@", name) + } + + /** + * 条件查询事件数据-精确查询 + */ + func queryTaskEventById(id: String) -> Results { + realm.objects(EventTaskLocalObject.self).filter("taskId = %@", id) + } + + func isAddSuccess(taskId: String) -> Bool { + let results = queryTaskEventById(id: taskId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/InspectionRealmManager.swift b/LaserMethane/Util/InspectionRealmManager.swift new file mode 100644 index 0000000..a484463 --- /dev/null +++ b/LaserMethane/Util/InspectionRealmManager.swift @@ -0,0 +1,72 @@ +// +// InspectionRealmManager.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +class InspectionRealmManager { + public static let shared = InspectionRealmManager() + + let realm: Realm = { + let migration = InspectionMigrationInitializer() + migration.perform() + return try! Realm(configuration: migration.config) + }() + + /** + * 保存巡检记录到本地 + * */ + func addInspection(newModel: NewInspectionModel) { + let insObject = InspectionLocalObject(inspectionId: newModel.id, name: newModel.name, startTime: newModel.startTime, endTime: newModel.endTime, date: newModel.date, startLng: newModel.startLng, startLat: newModel.startLat, endLng: newModel.endLng, endLat: newModel.endLat, routes: newModel.routes) + let results = queryInspectionById(id: newModel.id) + if results.count == 0 { + try! realm.write { + realm.add(insObject) + } + } + } + + /** + * 查询所有巡检数据 + */ + func queryAllInspection() -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspectionById(id: String) -> Results { + realm.objects(InspectionLocalObject.self).filter("inspectionId = %@", id) + } + + /** + * 条件查询巡检数据-精确查询 + */ + func queryInspection(startTime: String, endTime: String, name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("startTime = %@ and endTime = %@ and name = %@", startTime, endTime, name) + } + + /** + * 条件查询巡检数据-根据巡检标签查询 + */ + func queryInspectionByName(name: String) -> Results { + realm.objects(InspectionLocalObject.self).sorted(byKeyPath: "startTime", ascending: false).filter("name = %@", name) + } + + /** + * 判断是否插入成功 + */ + func isAddSuccess(inspectionId: String) -> Bool { + let results = queryInspectionById(id: inspectionId) + if results.isEmpty { + return false + } else { + return true + } + } +} diff --git a/LaserMethane/Util/RealmConfiguration.swift b/LaserMethane/Util/RealmConfiguration.swift new file mode 100644 index 0000000..54d8b83 --- /dev/null +++ b/LaserMethane/Util/RealmConfiguration.swift @@ -0,0 +1,25 @@ +// +// RealmConfiguration.swift +// LaserMethane +// +// Created by 203 on 2021/8/23. +// + +import Foundation +import RealmSwift + +struct RealmConfiguration { + static func inspectionConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("inspection.realm") + return Realm.Configuration(fileURL: url) + } + + static func eventTaskConfiguration() -> Realm.Configuration { + let config = Realm.Configuration() + let directory = config.fileURL!.deletingLastPathComponent() + let url = directory.appendingPathComponent("eventTask.realm") + return Realm.Configuration(fileURL: url) + } +} diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift index 4f4617a..7b7b415 100644 --- a/LaserMethane/ViewController/Map/MapViewController.swift +++ b/LaserMethane/ViewController/Map/MapViewController.swift @@ -410,8 +410,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": true, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -420,8 +420,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": false, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -703,10 +703,10 @@ isGeneratingTask = false alarmCount = 0 } else { - AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") + view.makeToast("保存失败,服务器异常", duration: 2, position: .center) } case .failure: - AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") + view.makeToast("保存失败,网络异常", duration: 2, position: .center) } }) } diff --git a/LaserMethane/ViewController/Map/NewEventViewController.swift b/LaserMethane/ViewController/Map/NewEventViewController.swift index 5fb076e..305282d 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.swift +++ b/LaserMethane/ViewController/Map/NewEventViewController.swift @@ -20,7 +20,6 @@ private var longitude: Double! private var latitude: Double! - @IBOutlet var rootView: UIView! @IBOutlet var firstView: UIView! @IBOutlet var secondView: UIView! @IBOutlet var thirdView: UIView! @@ -68,7 +67,7 @@ } func setupLayerView() { - rootView.backgroundColor = [238, 238, 238].transferUIColor() + view.backgroundColor = [238, 238, 238].transferUIColor() LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) if isWarning! { @@ -88,7 +87,7 @@ func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let length = string.lengthOfBytes(using: .utf8) - for loopIndex in 0 ..< length { + for loopIndex in 0.. String { @@ -203,26 +202,6 @@ // GMT时间 转字符串,直接是系统当前时间 return dateformatter.string(from: Date()) } -} - -extension NewEventViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate { - func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { - let tackedImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage - uploadImage(image: tackedImage, quality: 0.5) - dismiss(animated: true, completion: nil) - } -} - -extension NewEventViewController: PhotoPickerControllerDelegate { - func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) { - result.getImage(imageHandler: { [self] image, _, _ in - if let image = image { - uploadImage(image: image, quality: 0.75) // 75%压缩比 - } - }, completionHandler: { images in - print("图片数组: \(images)") - }) - } func uploadImage(image: UIImage, quality: CGFloat) { index += 1 @@ -259,6 +238,26 @@ } } +extension NewEventViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate { + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { + let tackedImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage + uploadImage(image: tackedImage, quality: 0.5) + dismiss(animated: true, completion: nil) + } +} + +extension NewEventViewController: PhotoPickerControllerDelegate { + func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) { + result.getImage(imageHandler: { [self] image, _, _ in + if let image = image { + uploadImage(image: image, quality: 0.75) // 75%压缩比 + } + }, completionHandler: { images in + print("图片数组: \(images)") + }) + } +} + extension NewEventViewController: UICollectionViewDataSource { // 每行几个 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { @@ -274,11 +273,11 @@ let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell let row = (indexPath as NSIndexPath).row KF.url(imageUrlArray[row]) - .loadDiskFileSynchronously() - .placeholder(UIImage(named: "load_imag_error.png")) - .cacheMemoryOnly() - .fade(duration: 0.25) - .set(to: cell.imageView) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) // 传递点击按钮的位置 cell.delButton.tag = row cell.delButton.addTarget(self, action: #selector(delImageAction), for: .touchUpInside) diff --git a/LaserMethane/ViewController/Map/NewEventViewController.xib b/LaserMethane/ViewController/Map/NewEventViewController.xib index 75be488..7e636d5 100644 --- a/LaserMethane/ViewController/Map/NewEventViewController.xib +++ b/LaserMethane/ViewController/Map/NewEventViewController.xib @@ -15,7 +15,6 @@ - @@ -96,7 +95,7 @@ - + @@ -138,7 +137,7 @@ - + diff --git a/LaserMethane/ViewController/Map/SingModeMapViewController.swift b/LaserMethane/ViewController/Map/SingModeMapViewController.swift index a76316b..c618044 100644 --- a/LaserMethane/ViewController/Map/SingModeMapViewController.swift +++ b/LaserMethane/ViewController/Map/SingModeMapViewController.swift @@ -19,6 +19,8 @@ private let defaults = Defaults.shared private let defaultKey = Key("InspectionCacheModel") private let statusKey = Key("inspectionStatus") + private let inspectionShared = InspectionRealmManager.shared + private let taskShared = EventTaskRealmManager.shared private var mapView: MAMapView! private var topTagView: UIView! @@ -295,14 +297,28 @@ let endLat = keychain[Constant.CurrentLatitude.rawValue]! as String // 提交巡检 let timeInterval: TimeInterval = Date().timeIntervalSince1970 - let endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) - let param: [String: Any] = ["id": model.id, "name": model.name, "startTime": model.startTime, - "endTime": endTime, "date": model.date, "startLng": model.startLng, - "startLat": model.startLat, "endLng": Double(endLng)!, "endLat": Double(endLat)!, - "routes": model.routes, "user": model.user] - // 提交参数: ["startLat": 39.915913628472225, "id": "162925125712000", "date": "2021-08-18", "startTime": "2021-08-18 09:47:37", "endLng": 116.26874240451389, "startLng": 116.26874240451389, "routes": "[{\"lat\":39.915913628472225,\"lng\":116.26874240451389}]", "user": "王晓颖", "name": "测试iOS", "endTime": "2021-08-18 09:47:56", "endLat": 39.915913628472225] - print("提交参数: \(param)") - //保存本地数据库 + model.endTime = timeFormatter.string(from: Date(timeIntervalSince1970: timeInterval)) + model.endLng = Double(endLng)! + model.endLat = Double(endLat)! + // 保存本地数据库 + inspectionShared.addInspection(newModel: model!) + if inspectionShared.isAddSuccess(inspectionId: model.id) { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { [self] _ in + defaults.set(true, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } else { + let alertController = UIAlertController(title: "提示", message: "巡检记录保存失败,已替您缓存到本地", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { [self] _ in + defaults.set(false, for: statusKey) + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } } let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil) // 设置取消按钮颜色为红色 @@ -369,7 +385,7 @@ let lat = keychain[Constant.CurrentLatitude.rawValue]! as String print("新建事件位置信息: [\(lng), \(lat)]") - let newEventViewController = NewEventViewController(nibName: "NewEventViewController", bundle: nil) + let newEventViewController = SingModeNewEventViewController(nibName: "SingModeNewEventViewController", bundle: nil) // 委托代理 valueDelegate = newEventViewController let selectController = UIAlertController(title: "选择事件类型", message: nil, preferredStyle: .alert) @@ -378,8 +394,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": true, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -388,8 +404,8 @@ // 实现代理的方法,传值 valueDelegate.transfer(controller: self, dic: ["isWarning": false, - "inspectionId": inspectionId!, - "inspectionName": inspectNameLabel.text!, + "inspectionId": model.id, + "inspectionName": model.name, "longitude": Double(lng)!, "latitude": Double(lat)!]) navigationController?.pushViewController(newEventViewController, animated: true) @@ -656,27 +672,16 @@ let longitude = keychain[Constant.CurrentLongitude.rawValue]! as String let latitude = keychain[Constant.CurrentLatitude.rawValue]! as String // 提交事件 - let param: [String: Any] = ["id": "t".id(), "inspectionId": model.id, "name": model.name, - "createTime": model.startTime, "type": "报警事件", "lng": Double(longitude)!, - "lat": Double(latitude)!, "data": Double(maxValue)!, "images": "", - "description": "自动报警记录", "user": model.user] - print("提交参数: \(param)") -// Alamofire.request(addEventURL, method: .post, parameters: param, headers: ["token": keychain[Constant.Token.rawValue]!]) -// .responseJSON(completionHandler: { [self] response in -// switch response.result { -// case let .success(value): -// let actionModel = ActionResultModel(respJson: JSON(value)) -// if actionModel.code == 200 { -// view.makeToast("保存成功") -// isGeneratingTask = false -// alarmCount = 0 -// } else { -// AlertHub.shared.showWaringAlert(controller: self, message: "服务器异常") -// } -// case .failure: -// AlertHub.shared.showWaringAlert(controller: self, message: "网络异常,提交失败") -// } -// }) + let taskId = "t".id() + let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: model.id, name: model.name, createTime: model.startTime, type: "报警事件", lng: Double(longitude)!, lat: Double(latitude)!, data: Double(maxValue)!, images: "", description: "自动报警记录", user: "智巡宝") + taskShared.addEventTask(model: eventModel) + if taskShared.isAddSuccess(taskId: taskId) { + view.makeToast("保存成功", duration: 2, position: .center) + isGeneratingTask = false + alarmCount = 0 + } else { + view.makeToast("保存失败,网络异常", duration: 2, position: .center) + } } } diff --git a/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift new file mode 100644 index 0000000..c88313b --- /dev/null +++ b/LaserMethane/ViewController/Map/SingModeNewEventViewController.swift @@ -0,0 +1,270 @@ +// +// SingModeNewEventViewController.swift +// LaserMethane +// +// Created by 203 on 2021/8/24. +// + +import Alamofire +import HXPHPicker +import KeychainAccess +import Kingfisher +import UIKit +import ZLPhotoBrowser + +class SingModeNewEventViewController: UIViewController, TransferValueDelegate, UITextFieldDelegate { + private let taskShared = EventTaskRealmManager.shared + private var isWarning: Bool! + private var inspectionId: String! + private var inspectionName: String! + private var longitude: Double! + private var latitude: Double! + + @IBOutlet var firstView: UIView! + @IBOutlet var secondView: UIView! + @IBOutlet var thirdView: UIView! + + @IBOutlet var eventTimeLabel: UILabel! + @IBOutlet var eventDescField: UITextField! + @IBOutlet var maxValueField: UITextField! + + @IBOutlet var imageCollectionView: UICollectionView! + @IBOutlet var saveEventButton: UIButton! + + private let keychain = Keychain() + private let dateformatter = DateFormatter() + private var imageUrlArray = [URL]() // 完整的图片url + private var imageArray = [String]() // 上传图片成功后服务器返回的图片数组 + private var index: Int = 0 + + private var eventType = "" + private var eventValueData: Double = -1 + + override func viewDidLoad() { + super.viewDidLoad() + // 设置导航栏背景和标题 + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.barTintColor = .systemBlue + let dict: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white] + navigationController?.navigationBar.titleTextAttributes = dict + navigationController?.navigationBar.tintColor = .white + // Do any additional setup after loading the view. + setupLayerView() + eventTimeLabel.text = currentTime() + maxValueField.delegate = self + // 注册UICollectionView相关协议和委托 + imageCollectionView.register(UINib(nibName: "ImageCollectionViewDelCell", bundle: nil), forCellWithReuseIdentifier: "collectionViewDelCell") + imageCollectionView.dataSource = self + imageCollectionView.delegate = self + imageCollectionView.reloadData() + } + + func setupLayerView() { + view.backgroundColor = [238, 238, 238].transferUIColor() + LayerShadowHub.shared.setShadow(view: firstView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + LayerShadowHub.shared.setShadow(view: thirdView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + if isWarning! { + title = "报警事件记录(单机模式)" + secondView.isHidden = false + LayerShadowHub.shared.setShadow(view: secondView, sColor: [211, 211, 211].transferUIColor(), offset: CGSize(width: 0, height: 0), alpha: 1.0, radius: CGFloat(5.0)) + } else { + title = "自定义事件记录(单机模式)" + secondView.isHidden = true + secondView.removeFromSuperview() // 光隐藏没用,需要完全从它父布局移除,不然会占位,类似Android的GONE和VISIABLE + thirdView.snp.makeConstraints { (make) -> Void in + make.top.equalTo(firstView.frame.height + 20) + } + } + saveEventButton.layer.cornerRadius = 8 + } + + func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + let length = string.lengthOfBytes(using: .utf8) + for loopIndex in 0.. 57 { + return false + } + } + let len = (textField.text?.lengthOfBytes(using: .utf8))! - range.length + string.lengthOfBytes(using: .utf8) + if len > 9 { + return false + } + return true + } + + func transfer(controller: UIViewController, dic: NSDictionary) { + isWarning = dic["isWarning"] as? Bool + inspectionId = dic["inspectionId"] as? String + inspectionName = dic["inspectionName"] as? String + longitude = dic["longitude"] as? Double + latitude = dic["latitude"] as? Double + } + + @IBAction func addImageAction(_ sender: Any) { + let actionSheetController = UIAlertController() + actionSheetController.addAction(UIAlertAction(title: "拍照", style: .default, handler: { [self] _ in + takePicture() + })) + actionSheetController.addAction(UIAlertAction(title: "相册", style: .default, handler: { [self] _ in + selectPicture() + })) + actionSheetController.addAction(UIAlertAction(title: "取消", style: .cancel)) + present(actionSheetController, animated: true, completion: nil) + } + + func takePicture() { + if UIImagePickerController.isSourceTypeAvailable(.camera) { + let picker = UIImagePickerController() + picker.sourceType = .camera + picker.delegate = self + picker.cameraDevice = .rear + picker.cameraCaptureMode = .photo + picker.cameraFlashMode = .auto + picker.allowsEditing = false + present(picker, animated: true, completion: nil) + } else { + AlertHub.shared.showWaringAlert(controller: self, message: "抱歉,无法打开照相机") + } + } + + func selectPicture() { + // 设置与微信主题一致的配置 + let config = PhotoTools.getWXPickerConfig() + config.maximumSelectedPhotoCount = 3 + config.selectOptions = [.photo] + config.allowSelectedTogether = false + config.photoList.allowAddCamera = false // 选图不显示相机 + let pickerController = PhotoPickerController(picker: config) + pickerController.pickerDelegate = self + // 是否选中原图 + pickerController.isOriginal = false + present(pickerController, animated: true, completion: nil) + } + + @IBAction func saveEventAction(_ sender: Any) { + let eventDesc = eventDescField.text?.filterString() + if eventDesc == "" { + AlertHub.shared.showWaringAlert(controller: self, message: "事件情况说明还未填写,请检查") + return + } + if isWarning! { + let maxValue = maxValueField.text?.filterString() + if maxValue == "" { + AlertHub.shared.showWaringAlert(controller: self, message: "最大泄露值还未填写,请检查") + return + } + eventType = "报警事件" + eventValueData = Double(maxValue!)! + } else { + eventType = "自定义事件" + } + // 提交事件 + let taskId = "t".id() + let eventModel = NewEventTaskModel(taskId: taskId, inspectionId: inspectionId!, name: inspectionName!, createTime: eventTimeLabel.text!, type: eventType, lng: longitude!, lat: latitude!, data: eventValueData, images: imageArray.reformat(), description: eventDesc!, user: "智巡宝") + taskShared.addEventTask(model: eventModel) + if taskShared.isAddSuccess(taskId: taskId) { + let alertController = UIAlertController(title: "提示", message: "事件记录保存成功", preferredStyle: .alert) + let okAction = UIAlertAction(title: "知道了", style: .default, handler: { [self] _ in + navigationController?.popViewController(animated: true) + }) + alertController.addAction(okAction) + present(alertController, animated: true, completion: nil) + } + } + + func currentTime() -> String { + dateformatter.dateFormat = "YYYY-MM-dd HH:mm:ss" // 自定义时间格式 + // GMT时间 转字符串,直接是系统当前时间 + return dateformatter.string(from: Date()) + } + + func addImage(image: UIImage) { + index += 1 + dateformatter.dateFormat = "yyyyMMddHHmmss" + let imageName = "IMG_\(dateformatter.string(from: Date()))_\(index).png" + + let imageData = image.pngData() + let url = imageData?.fromLocalImage(imageName: imageName) + imageArray.append(url!.path) + imageUrlArray.append(url!) // 用于本地展示 + imageCollectionView.reloadData() + } +} + +// 拍照 +extension SingModeNewEventViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate { + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { + let tackedImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage + addImage(image: tackedImage) + dismiss(animated: true, completion: nil) + } +} + +// 选图 +extension SingModeNewEventViewController: PhotoPickerControllerDelegate { + func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) { + result.getImage(imageHandler: { [self] image, _, _ in + if let image = image { + addImage(image: image) + } + }, completionHandler: { images in + print("图片数组: \(images)") + }) + } +} + +extension SingModeNewEventViewController: UICollectionViewDataSource { + // 每行几个 + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + imageUrlArray.count + } + + // 有几行 + func numberOfSections(in collectionView: UICollectionView) -> Int { + 1 + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell: ImageCollectionViewDelCell! = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewDelCell", for: indexPath) as? ImageCollectionViewDelCell + let row = (indexPath as NSIndexPath).row + KF.url(imageUrlArray[row]) + .loadDiskFileSynchronously() + .placeholder(UIImage(named: "load_imag_error.png")) + .cacheMemoryOnly() + .fade(duration: 0.25) + .set(to: cell.imageView) + // 传递点击按钮的位置 + cell.delButton.tag = row + cell.delButton.addTarget(self, action: #selector(delImageAction), for: .touchUpInside) + return cell + } + + @objc func delImageAction(sender: UIButton) { + imageArray.remove(at: sender.tag) + imageUrlArray.remove(at: sender.tag) + imageCollectionView.reloadData() + } +} + +extension SingModeNewEventViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + let row = (indexPath as NSIndexPath).row + // 查看大图 + let vc = ZLImagePreviewController(datas: imageUrlArray, index: row, showSelectBtn: false, showBottomView: false, urlType: { (_) -> ZLURLType in + .image + }, urlImageLoader: { url, imageView, progress, loadFinish in + imageView.kf.setImage(with: url) { receivedSize, totalSize in + let percentage = (CGFloat(receivedSize) / CGFloat(totalSize)) + progress(percentage) + } completionHandler: { _ in + loadFinish() + } + }) + vc.modalPresentationStyle = .fullScreen + showDetailViewController(vc, sender: nil) + } +} diff --git a/LaserMethane/ViewController/Map/SingModeNewEventViewController.xib b/LaserMethane/ViewController/Map/SingModeNewEventViewController.xib new file mode 100644 index 0000000..aa4cb76 --- /dev/null +++ b/LaserMethane/ViewController/Map/SingModeNewEventViewController.xib @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +