2 // LocalDataStoreAccessor.swift
5 // Created by Hori,Masaki on 2017/10/25.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
9 extension LocalDataStore {
11 func unmarkedDropShipHistories(befor days: Int) -> [DropShipHistory] {
13 let date = Date(timeIntervalSinceNow: TimeInterval(-1 * days * 24 * 60 * 60))
14 let predicate = NSPredicate
16 NSPredicate(#keyPath(DropShipHistory.date), lessThan: date),
17 NSPredicate(#keyPath(DropShipHistory.mark), equal: 0)
18 .or(.isNil(#keyPath(DropShipHistory.mark))),
19 NSPredicate(#keyPath(DropShipHistory.mapArea), valuesIn: ["1", "2", "3", "4", "5", "6", "7", "8", "9"])
22 guard let dropHistories = try? objects(of: DropShipHistory.entity, predicate: predicate) else { return [] }
27 func createDropShipHistory() -> DropShipHistory? {
29 return insertNewObject(for: DropShipHistory.entity)
32 func kaihatuHistories() -> [KaihatuHistory] {
34 guard let kaihatuHistories = try? objects(of: KaihatuHistory.entity) else { return [] }
36 return kaihatuHistories
39 func unmarkedKaihatuHistories(befor days: Int) -> [KaihatuHistory] {
41 let date = Date(timeIntervalSinceNow: TimeInterval(-1 * days * 24 * 60 * 60))
42 let predicate = NSPredicate
44 NSPredicate(#keyPath(KaihatuHistory.date), lessThan: date),
45 NSPredicate(#keyPath(KaihatuHistory.mark), equal: 0)
46 .or(.isNil(#keyPath(KaihatuHistory.mark)))
49 guard let kaihatuHistories = try? objects(of: KaihatuHistory.entity, predicate: predicate) else { return [] }
51 return kaihatuHistories
54 func createKaihatuHistory() -> KaihatuHistory? {
56 return insertNewObject(for: KaihatuHistory.entity)
59 func kenzoMark(byDockId dockId: Int) -> KenzoMark? {
61 let predicate = NSPredicate(#keyPath(KenzoMark.kDockId), equal: dockId)
63 guard let kenzoMarks = try? objects(of: KenzoMark.entity, predicate: predicate) else { return nil }
65 return kenzoMarks.first
68 // swiftlint:disable function_parameter_count
69 func kenzoMark(fuel: Int, bull: Int, steel: Int, bauxite: Int, kaihatusizai: Int, kDockId: Int, shipId: Int) -> KenzoMark? {
71 let predicate = NSPredicate.empty
72 .and(NSPredicate(#keyPath(KenzoMark.fuel), equal: fuel))
73 .and(NSPredicate(#keyPath(KenzoMark.bull), equal: bull))
74 .and(NSPredicate(#keyPath(KenzoMark.steel), equal: steel))
75 .and(NSPredicate(#keyPath(KenzoMark.bauxite), equal: bauxite))
76 .and(NSPredicate(#keyPath(KenzoMark.kaihatusizai), equal: kaihatusizai))
77 .and(NSPredicate(#keyPath(KenzoMark.kDockId), equal: kDockId))
78 .and(NSPredicate(#keyPath(KenzoMark.created_ship_id), equal: shipId))
80 guard let kenzoMarks = try? objects(of: KenzoMark.entity, predicate: predicate) else { return nil }
82 return kenzoMarks.first
85 func createKenzoMark() -> KenzoMark? {
87 return insertNewObject(for: KenzoMark.entity)
90 func unmarkedKenzoHistories(befor days: Int) -> [KenzoHistory] {
92 let date = Date(timeIntervalSinceNow: TimeInterval(-1 * days * 24 * 60 * 60))
93 let predicate = NSPredicate
95 NSPredicate(#keyPath(KenzoHistory.date), lessThan: date),
96 NSPredicate(#keyPath(KenzoHistory.mark), equal: 0)
97 .or(.isNil(#keyPath(KenzoHistory.mark)))
100 guard let kenzoHistories = try? objects(of: KenzoHistory.entity, predicate: predicate) else { return [] }
102 return kenzoHistories
105 func createKenzoHistory() -> KenzoHistory? {
107 return insertNewObject(for: KenzoHistory.entity)
110 func hiddenDropShipHistories() -> [HiddenDropShipHistory] {
112 guard let dropShipHistories = try? objects(of: HiddenDropShipHistory.entity) else { return [] }
114 return dropShipHistories
117 func createHiddenDropShipHistory() -> HiddenDropShipHistory? {
119 return insertNewObject(for: HiddenDropShipHistory.entity)