消耗品を管理する Part2

06/07

消耗品を管理する Part2

目次

技術検証など

2023/06/10更新 テーブル定義を大幅に手を入れる

仕組み

さて、続き。
仕組みを考える。
まずは消耗品リスト(Consumables List)を作り上げる。
消耗品リストとは、家に存在する消耗品を全て登録してできる全消耗品のリストのこと。
各消耗品には消費日数 (Durable Days)があって、日付ではなく日数で管理される。
購入日 (Purchase Date)に消費日数を足してやって切れる日 (Durable Date)を算出する。
で、消耗品リストの中から切れる日が迫るものを次買うものリスト(Gonna-buy List)として作り上げる。
買い物し終わったら、次買うものリストを完了にしたら購入日が更新される。
こんな感じだろうか。

では、消耗品リストを作り上げるのにどんなことが必要かを考える。

機能

  • 消耗品情報登録 (Add Consumable)
  • 消耗品情報更新 (Edit Consumable)
    • 消耗品延期 (Delay Consumables)
    • 消耗品繰り上げ (Carry Forward Consumables)
  • 消耗品情報削除 (Delete Consumables)
  • マスタ管理 (Maintenance)

多分こんなところが基本機能だろう。
で、運用を楽にするためには、如何にマスタ管理をしっかりやっておくかにかかっていると思う。
そしてもう一つ大事なのがI/F
マスタ管理をしっかりやった上で、登録しやすい見た目をしていないとストレスばかり貯まることになるので。
だいぶわかってきたぞ。

定義

消耗品マスタがあって、そのマスタ情報を使って消耗品情報を登録していき、消耗品リストを作り上げる。

ER図

erDiagram
    M_CONSUMABLE ||--||M_CATEGORY: "category_id"
    M_CONSUMABLE ||--||M_PLACE: "place_id"
    M_CONSUMABLE ||--o{T_PURCHASE_HISTORY: "consumable_id"
    M_USER||--o{M_CONSUMABLE: "user_id"
    M_USER||--o{M_CATEGORY: "user_id"
    M_USER||--o{M_PLACE: "user_id"
    M_USER||--o{T_GONNABUY: "user_id"
    M_USER||--o{M_CATEGORY: "user_id"
    M_USER||--o{T_PURCHASE_HISTORY: "user_id"
    T_GONNABUY ||--||M_CONSUMABLE: "id"


    M_USER {
        string id PK
        string password "not null"
        string name "not null"
        datetime login_timestamp "not null"
        int delete_flag "not null"
        int force_login_flag "not null, 0"
        datetime registered_timestamp "not null, current_timestamp"
        datetime deleted_timestamp
        datetime updated_timestamp
    }

    M_CONSUMABLE {
        int id PK
        string name "not null"
        int category_id FK "not null"
        int place_id FK "not null"
        int durable_days "not null"
        int overdue_days "not null"
        text description
        blob image
        string user_id FK "not null"
        datetime registered_timestamp "not null, current_timestamp"
        datetime updated_timestamp
    }

    M_CATEGORY {
        int id PK
        string name "not null"
        int parent_id
        string user_id FK "not null"
        datetime registered_timestamp "not null, current_timestamp"
        datetime updated_timestamp
    }

    M_PLACE {
        int id PK
        string name "not null"
        text address 
        text url
        string user_id FK "not null"
        datetime registered_timestamp "not null, current_timestamp"
        datetime updated_timestamp
    }

    T_GONNABUY {
        int id PK "FK"
        date purchase_date "not null"
        int purchase_count "not null, 1"
        int overdue_count "not null, 0"
        int delete_flag "not null, 0"
        string user_id FK "not null"
        datetime registered_timestamp "not null, current_timestamp"
        datetime updated_timestamp
    }

    T_PURCHASE_HISTORY {
        bigint id PK
        int consumable_id FK "not null"
        date purchase_date "not null"
        string user_id FK "not null"
        datetime registered_timestamp "not null, current_timestamp"
        datetime updated_timestamp        
    }
No Table Name Table Name (Translated)
1 M_USER ユーザマスタ
2 M_CONSUMABLE 消耗品マスタ
3 M_CATEGORY カテゴリマスタ
4 M_PLACE 購入場所マスタ
5 T_GONNABUY 消耗品リスト
6 T_PURCHASE_HISTORY 購入履歴

ユーザマスタ

No Primary Key Foreign Key Column Name Column Name (Translated) Description Data Type Length (byte) Not Null Initial Value Column Constraint
1 id ユーザID varchar 20
2 password パスワード varchar 40
3 name ユーザ名 varchar 255
4 login_timestamp ログイン時刻 datetime 4
5 delete_flag 削除フラグ int 1
6 force_login_flag 強制ログインフラグ int 1
7 deleted_timestamp 削除日時 datetime 4
8 registered_timestamp 登録日時 datetime 4 current_timestamp
9 updated_timestamp 更新日時 datetime 4

消耗品マスタ

No Primary Key Foreign Key Column Name Column Name (Translated) Description Data Type Length (byte) Not Null Initial Value Column Constraint
1 id 消耗品ID int 4
2 name 消耗品名 varchar 255
3 category_id カテゴリID int 4
4 place_id 購入場所ID int 4
5 durable_days 消費日数 int 4 7
6 overdue_days 延長日数 購入延期のときに更新する日数 int 4 7
7 description 説明 text
8 image 消耗品画像
8 user_id ユーザID varchar 20
9 registered_timestamp 登録時日 datetime 4 current_timestamp
10 updated_timestamp 更新日時 datetime 4

カテゴリマスタ

消耗品の登録を簡単にするための工夫。

No Primary Key Foreign Key Column Name Column Name (Translated) Description Data Type Length (byte) Not Null Initial Value Column Constraint
1 id カテゴリID int 4
2 name カテゴリ名 varchar 255
3 parent_id 親カテゴリID int 4
4 user_id ユーザID varchar 20
5 registered_timestamp 登録日時 datetime 4 current_timestamp
6 updated_timestamp 更新日時 datetime 4

購入場所マスタ

買う場所もあったほうがいい。

No Primary Key Foreign Key Column Name Column Name (Translated) Description Data Type Length (byte) Not Null Initial Value Column Constraint
1 id 購入場所ID int 4
2 name 購入場所 varchar 255
3 address 購入場所住所 varchar 255
4 url 購入場所URL varchar 255
5 user_id ユーザID varchar 20
6 registered_timestamp 登録日時 datetime 4 current_timestamp
7 updated_timestamp 更新日時 datetime 4

消耗品リスト

No Primary Key Foreign Key Column Name Column Name (Translated) Description Data Type Length (byte) Not Null Initial Value Column Constraint
1 id 消耗品ID int 4
2 purchase_date 購入日 date 3
3 purchase_count 購入回数 int 4
4 overdue_count 延期回数 int 4
5 delete_flag 削除フラグ int 1
6 user_id ユーザID varchar 20
7 registered_timestamp 登録日時 datetime 4 current_timestamp
8 updated_timestamp 更新日時 datetime 4

購入履歴

No Primary Key Foreign Key Column Name Column Name (Translated) Description Data Type Length (byte) Not Null Initial Value Column Constraint
1 id 購入履歴ID bigint
2 purchase_date 購入日 date 3
3 purchase_count 購入回数 int 4
4 overdue_count 延期回数 int 4
5 delete_flag 削除フラグ int 1
6 user_id ユーザID varchar 20
7 registered_timestamp 登録日時 datetime 4 current_timestamp
8 updated_timestamp 更新日時 datetime 4

ひとまずここまで

さてと次は画面遷移とI/Fでもやりますかね。


コメント: