unidom-article_number 3.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/unidom/article_number/application_controller.rb +8 -2
- data/app/helpers/unidom/article_number/application_helper.rb +8 -1
- data/app/jobs/unidom/article_number/application_job.rb +7 -1
- data/app/mailers/unidom/article_number/application_mailer.rb +9 -3
- data/app/models/unidom/article_number/application_record.rb +8 -2
- data/app/models/unidom/article_number/concerns/as_barcode.rb +27 -19
- data/app/models/unidom/article_number/concerns/as_ean13_marked.rb +16 -8
- data/app/models/unidom/article_number/concerns/as_ean8_marked.rb +16 -8
- data/app/models/unidom/article_number/concerns/as_marked.rb +26 -18
- data/app/models/unidom/article_number/concerns/code128_barcode.rb +23 -15
- data/app/models/unidom/article_number/ean13_barcode.rb +35 -29
- data/app/models/unidom/article_number/ean8_barcode.rb +28 -22
- data/app/models/unidom/article_number/marking.rb +30 -24
- data/app/models/unidom/article_number/vehicle_identification_number.rb +30 -24
- data/app/validators/unidom/article_number/vehicle_identification_number_validator.rb +28 -22
- data/app/views/layouts/unidom/article_number/application.html.erb +1 -1
- data/db/migrate/20020101000000_create_unidom_markings.rb +4 -4
- data/db/migrate/20020102000000_create_unidom_ean_13_barcodes.rb +4 -4
- data/db/migrate/20020103000000_create_unidom_ean_8_barcodes.rb +4 -4
- data/db/migrate/20020111000000_create_unidom_vehicle_identification_numbers.rb +4 -4
- data/lib/unidom/article_number/engine.rb +1 -1
- data/lib/unidom/article_number/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 20387d317914c567cade086d61a214bdc1544df3db3188765a6d1d876fbbf0d4
|
|
4
|
+
data.tar.gz: f3122b1aff3157ba6e49b2c60a1dbd832debe28c985482cb64ff0aee74e5f1da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 41c78fa15b41db235ca0cd303c64127aa548339287eabe3d8a0f76ceecb277160457fec56f3a50233c825837258c0f909d21b2650cd36465522a9753cdc11096
|
|
7
|
+
data.tar.gz: 53956165e31e623a47cc60dfd1bba815050f0498d63a585d254c81886d03ecb39429132a5a35250c7322c96a82d05687a334b50df3ed49a40aac91e88f943186
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
##
|
|
2
2
|
# Application controller 是模块内所有控制器的基类。
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
module Unidom
|
|
5
|
+
module ArticleNumber
|
|
6
|
+
|
|
7
|
+
class ApplicationController < ActionController::Base
|
|
8
|
+
protect_from_forgery with: :exception
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end
|
|
6
12
|
end
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
##
|
|
2
2
|
# Application mailer 是模块内所有电子邮件发送类的基类。
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
module Unidom
|
|
5
|
+
module ArticleNumber
|
|
6
|
+
|
|
7
|
+
class ApplicationMailer < ActionMailer::Base
|
|
8
|
+
default from: 'from@example.com'
|
|
9
|
+
layout 'mailer'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
|
7
13
|
end
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
##
|
|
2
2
|
# Application record 是模块内所有模型的抽象基类。
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
module Unidom
|
|
5
|
+
module ArticleNumber
|
|
6
|
+
|
|
7
|
+
class ApplicationRecord < ActiveRecord::Base
|
|
8
|
+
self.abstract_class = true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end
|
|
6
12
|
end
|
|
@@ -1,31 +1,39 @@
|
|
|
1
1
|
##
|
|
2
2
|
# As Barcode 是条形码的领域逻辑关注点。
|
|
3
3
|
|
|
4
|
-
module Unidom
|
|
4
|
+
module Unidom
|
|
5
|
+
module ArticleNumber
|
|
6
|
+
module Concerns
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
module AsBarcode
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
extend ActiveSupport::Concern
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
has_many :marked_products, through: :markings, source: :marked, source_type: 'Unidom::Product::Product'
|
|
12
|
+
included do |includer|
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
raise ArgumentError.new('The by argument is required.' ) if by.blank?
|
|
16
|
-
raise ArgumentError.new('The at argument is required.' ) if at.blank?
|
|
17
|
-
markings.create! marked: marked, marker: by, opened_at: at
|
|
18
|
-
end
|
|
14
|
+
has_many :markings, class_name: 'Unidom::ArticleNumber::Marking', as: :barcode
|
|
15
|
+
has_many :marked_products, through: :markings, source: :marked, source_type: 'Unidom::Product::Product'
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
def mark!(marked, by: nil, at: Time.now)
|
|
18
|
+
raise ArgumentError.new('The marked argument is required.') if marked.blank?
|
|
19
|
+
raise ArgumentError.new('The by argument is required.' ) if by.blank?
|
|
20
|
+
raise ArgumentError.new('The at argument is required.' ) if at.blank?
|
|
21
|
+
markings.create! marked: marked, marker: by, opened_at: at
|
|
22
|
+
end
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
def mark?(marked, at: Time.now)
|
|
25
|
+
raise ArgumentError.new('The marked argument is required.') if marked.blank?
|
|
26
|
+
raise ArgumentError.new('The at argument is required.' ) if at.blank?
|
|
27
|
+
markings.marked_is(marked).valid_at(now: at).alive.exists?
|
|
28
|
+
end
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
+
end
|
|
30
31
|
|
|
32
|
+
module ClassMethods
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
31
39
|
end
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
##
|
|
2
2
|
# As EAN-13 Marked 是被 EAN-13 条形码标注的物品的领域逻辑关注点。
|
|
3
3
|
|
|
4
|
-
module Unidom
|
|
4
|
+
module Unidom
|
|
5
|
+
module ArticleNumber
|
|
6
|
+
module Concerns
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
module AsEan13Marked
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
extend ActiveSupport::Concern
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
include Unidom::ArticleNumber::Concerns::AsMarked
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
included do |includer|
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
has_many :ean13_barcodes, through: :markings, source: :barcode, source_type: 'Unidom::ArticleNumber::Ean13Barcode'
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module ClassMethods
|
|
21
|
+
end
|
|
18
22
|
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
19
27
|
end
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
##
|
|
2
2
|
# As EAN-8 Marked 是被 EAN-8 条形码标注的物品的领域逻辑关注点。
|
|
3
3
|
|
|
4
|
-
module Unidom
|
|
4
|
+
module Unidom
|
|
5
|
+
module ArticleNumber
|
|
6
|
+
module Concerns
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
module AsEan8Marked
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
extend ActiveSupport::Concern
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
include Unidom::ArticleNumber::Concerns::AsMarked
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
included do |includer|
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
has_many :ean8_barcodes, through: :markings, source: :barcode, source_type: 'Unidom::ArticleNumber::Ean8Barcode'
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module ClassMethods
|
|
21
|
+
end
|
|
18
22
|
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
19
27
|
end
|
|
@@ -1,30 +1,38 @@
|
|
|
1
1
|
##
|
|
2
2
|
# As Marked 是被条形码标注的物品的领域逻辑关注点。
|
|
3
3
|
|
|
4
|
-
module Unidom
|
|
4
|
+
module Unidom
|
|
5
|
+
module ArticleNumber
|
|
6
|
+
module Concerns
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
module AsMarked
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
extend ActiveSupport::Concern
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
included do |includer|
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
raise ArgumentError.new('The as argument is required.') if as.blank?
|
|
14
|
-
raise ArgumentError.new('The by argument is required.') if by.blank?
|
|
15
|
-
raise ArgumentError.new('The at argument is required.') if at.blank?
|
|
16
|
-
markings.create! barcode: as, marker: by, opened_at: at
|
|
17
|
-
end
|
|
14
|
+
has_many :markings, class_name: 'Unidom::ArticleNumber::Marking', as: :marked
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
def is_marked!(as: nil, by: nil, at: Time.now)
|
|
17
|
+
raise ArgumentError.new('The as argument is required.') if as.blank?
|
|
18
|
+
raise ArgumentError.new('The by argument is required.') if by.blank?
|
|
19
|
+
raise ArgumentError.new('The at argument is required.') if at.blank?
|
|
20
|
+
markings.create! barcode: as, marker: by, opened_at: at
|
|
21
|
+
end
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
def is_marked?(as: nil, at: Time.now)
|
|
24
|
+
raise ArgumentError.new('The as argument is required.') if as.blank?
|
|
25
|
+
raise ArgumentError.new('The at argument is required.') if at.blank?
|
|
26
|
+
markings.barcode_is(as).valid_at(now: at).alive.exists?
|
|
27
|
+
end
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
+
end
|
|
29
30
|
|
|
31
|
+
module ClassMethods
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
30
38
|
end
|
|
@@ -4,28 +4,36 @@
|
|
|
4
4
|
# Code 128 B 条形码 code set: ASCII characters 32 to 127 (0-9, A-Z, a-z), special characters, and FNC 1-4.
|
|
5
5
|
# Code 128 C 条形码 code set: 00-99 (encodes each two digits with one code) and FNC1.
|
|
6
6
|
|
|
7
|
-
module Unidom
|
|
7
|
+
module Unidom
|
|
8
|
+
module ArticleNumber
|
|
9
|
+
module Concerns
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
module Code128Barcode
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
extend ActiveSupport::Concern
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
validates :code, numericality: { only_integer: true }, if: Proc.new { |barcode| 'C'==barcode.code_set_code }
|
|
15
|
+
included do |includer|
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
validates :code, uniqueness: true
|
|
18
|
+
validates :code, numericality: { only_integer: true }, if: Proc.new { |barcode| 'C'==barcode.code_set_code }
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
has_many :markings, class_name: 'Unidom::ArticleNumber::Marking'
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
# sum = 103
|
|
22
|
-
# codes.each_with_index do |char, index| sum += (char.unpack('C').first-32)*(index+1) end
|
|
23
|
-
# sum%103
|
|
24
|
-
#end
|
|
22
|
+
include Unidom::Common::Concerns::ModelExtension
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
#def weighted_modulo_103_checksum(codes)
|
|
25
|
+
# sum = 103
|
|
26
|
+
# codes.each_with_index do |char, index| sum += (char.unpack('C').first-32)*(index+1) end
|
|
27
|
+
# sum%103
|
|
28
|
+
#end
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
module ClassMethods
|
|
33
|
+
end
|
|
30
34
|
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
31
39
|
end
|
|
@@ -3,34 +3,40 @@
|
|
|
3
3
|
# https://en.wikipedia.org/wiki/EAN-13
|
|
4
4
|
# https://en.wikipedia.org/wiki/International_Article_Number_(EAN)
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
RESTRICTED_DISTRIBUTION_GS1_PREFIXES = (('020'..'029').to_a + ('040'..'049').to_a + ('200'..'299').to_a).freeze
|
|
9
|
-
|
|
10
|
-
self.table_name = 'unidom_ean_13_barcodes'
|
|
11
|
-
|
|
12
|
-
include Unidom::Common::Concerns::ModelExtension
|
|
13
|
-
include Unidom::ArticleNumber::Concerns::AsBarcode
|
|
14
|
-
|
|
15
|
-
validates :code, uniqueness: true, length: { minimum: 13 }, numericality: { only_integer: true }
|
|
16
|
-
validates :gs1_prefix, presence: true, length: { is: 3 }, numericality: { only_integer: true }
|
|
17
|
-
validates :company_number, presence: true, length: { is: 4 }, numericality: { only_integer: true }
|
|
18
|
-
validates :item_reference, presence: true, length: { is: 5 }, numericality: { only_integer: true }
|
|
19
|
-
validates :check_digit, presence: true, length: { is: 1 }, numericality: { only_integer: true }
|
|
20
|
-
|
|
21
|
-
def code=(code)
|
|
22
|
-
code = code.to_s
|
|
23
|
-
write_attribute :code, code
|
|
24
|
-
if code.present?
|
|
25
|
-
write_attribute :gs1_prefix, code[0..2]
|
|
26
|
-
write_attribute :company_number, code[3..6]
|
|
27
|
-
write_attribute :item_reference, code[7..11]
|
|
28
|
-
write_attribute :check_digit, code[12]
|
|
29
|
-
end
|
|
30
|
-
end
|
|
6
|
+
module Unidom
|
|
7
|
+
module ArticleNumber
|
|
31
8
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
9
|
+
class Ean13Barcode < ApplicationRecord
|
|
10
|
+
|
|
11
|
+
RESTRICTED_DISTRIBUTION_GS1_PREFIXES = (('020'..'029').to_a + ('040'..'049').to_a + ('200'..'299').to_a).freeze
|
|
12
|
+
|
|
13
|
+
self.table_name = 'unidom_ean_13_barcodes'
|
|
14
|
+
|
|
15
|
+
include Unidom::Common::Concerns::ModelExtension
|
|
16
|
+
include Unidom::ArticleNumber::Concerns::AsBarcode
|
|
35
17
|
|
|
36
|
-
|
|
18
|
+
validates :code, uniqueness: true, length: { minimum: 13 }, numericality: { only_integer: true }
|
|
19
|
+
validates :gs1_prefix, presence: true, length: { is: 3 }, numericality: { only_integer: true }
|
|
20
|
+
validates :company_number, presence: true, length: { is: 4 }, numericality: { only_integer: true }
|
|
21
|
+
validates :item_reference, presence: true, length: { is: 5 }, numericality: { only_integer: true }
|
|
22
|
+
validates :check_digit, presence: true, length: { is: 1 }, numericality: { only_integer: true }
|
|
23
|
+
|
|
24
|
+
def code=(code)
|
|
25
|
+
code = code.to_s
|
|
26
|
+
write_attribute :code, code
|
|
27
|
+
if code.present?
|
|
28
|
+
write_attribute :gs1_prefix, code[0..2]
|
|
29
|
+
write_attribute :company_number, code[3..6]
|
|
30
|
+
write_attribute :item_reference, code[7..11]
|
|
31
|
+
write_attribute :check_digit, code[12]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def restricted_distribution?
|
|
36
|
+
self.class::RESTRICTED_DISTRIBUTION_GS1_PREFIXES.include? gs1_prefix
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::ArticleNumber::Ean13Barcode'
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -2,32 +2,38 @@
|
|
|
2
2
|
# EAN-8 Barcode 是8位条形码。
|
|
3
3
|
# https://en.wikipedia.org/wiki/EAN-8
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
module Unidom
|
|
6
|
+
module ArticleNumber
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
class Ean8Barcode < ApplicationRecord
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
RESTRICTED_DISTRIBUTION_GS1_PREFIXES = (('020'..'029').to_a + ('040'..'049').to_a + ('200'..'299').to_a).freeze
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
include Unidom::ArticleNumber::Concerns::AsBarcode
|
|
12
|
+
self.table_name = 'unidom_ean_8_barcodes'
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
validates :item_reference, presence: true, length: { is: 4 }, numericality: { only_integer: true }
|
|
17
|
-
validates :check_digit, presence: true, length: { is: 1 }, numericality: { only_integer: true }
|
|
14
|
+
include Unidom::Common::Concerns::ModelExtension
|
|
15
|
+
include Unidom::ArticleNumber::Concerns::AsBarcode
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
write_attribute :gs1_prefix, code[0..2]
|
|
24
|
-
write_attribute :item_reference, code[3..6]
|
|
25
|
-
write_attribute :check_digit, code[7]
|
|
26
|
-
end
|
|
27
|
-
end
|
|
17
|
+
validates :code, uniqueness: true, length: { minimum: 8 }, numericality: { only_integer: true }
|
|
18
|
+
validates :gs1_prefix, presence: true, length: { is: 3 }, numericality: { only_integer: true }
|
|
19
|
+
validates :item_reference, presence: true, length: { is: 4 }, numericality: { only_integer: true }
|
|
20
|
+
validates :check_digit, presence: true, length: { is: 1 }, numericality: { only_integer: true }
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
def code=(code)
|
|
23
|
+
code = code.to_s
|
|
24
|
+
write_attribute :code, code
|
|
25
|
+
if code.present?
|
|
26
|
+
write_attribute :gs1_prefix, code[0..2]
|
|
27
|
+
write_attribute :item_reference, code[3..6]
|
|
28
|
+
write_attribute :check_digit, code[7]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def restricted_distribution?
|
|
33
|
+
self.class::RESTRICTED_DISTRIBUTION_GS1_PREFIXES.include? gs1_prefix
|
|
34
|
+
end
|
|
32
35
|
|
|
33
|
-
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::ArticleNumber::Ean8Barcode'
|
|
36
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::ArticleNumber::Ean8Barcode'
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -1,36 +1,42 @@
|
|
|
1
1
|
##
|
|
2
2
|
# Marking 是条码和物品的标记关系。
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
module Unidom
|
|
5
|
+
module ArticleNumber
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
class Marking < ApplicationRecord
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
self.table_name = 'unidom_markings'
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
belongs_to :marked, polymorphic: true
|
|
12
|
-
belongs_to :marker, polymorphic: true
|
|
11
|
+
include Unidom::Common::Concerns::ModelExtension
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
belongs_to :barcode, polymorphic: true
|
|
14
|
+
belongs_to :marked, polymorphic: true
|
|
15
|
+
belongs_to :marker, polymorphic: true
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
scope :barcode_is, ->(barcode) { where barcode: barcode }
|
|
18
|
+
scope :marked_by, ->(marker) { where marker: marker }
|
|
19
|
+
scope :marked_is, ->(marked) { where marked: marked }
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
raise ArgumentError.new('The marked argument is required.' ) if marked.blank?
|
|
22
|
-
raise ArgumentError.new('The opened_at argument is required.') if opened_at.blank?
|
|
21
|
+
def self.mark!(barcode: nil, marked: nil, marker: nil, opened_at: Time.now)
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
creation[:marker] = marker
|
|
28
|
-
else
|
|
29
|
-
creation[:marker_id] = Unidom::Common::NULL_UUID
|
|
30
|
-
creation[:marker_type] = ''
|
|
31
|
-
end
|
|
32
|
-
query.first_or_create! creation
|
|
23
|
+
raise ArgumentError.new('The barcode argument is required.' ) if barcode.blank?
|
|
24
|
+
raise ArgumentError.new('The marked argument is required.' ) if marked.blank?
|
|
25
|
+
raise ArgumentError.new('The opened_at argument is required.') if opened_at.blank?
|
|
33
26
|
|
|
34
|
-
|
|
27
|
+
query = barcode_is(barcode).marked_is(marked).valid_at.alive
|
|
28
|
+
creation = { opened_at: opened_at }
|
|
29
|
+
if marker.present? && marker.respond_to?(:id)
|
|
30
|
+
creation[:marker] = marker
|
|
31
|
+
else
|
|
32
|
+
creation[:marker_id] = Unidom::Common::NULL_UUID
|
|
33
|
+
creation[:marker_type] = ''
|
|
34
|
+
end
|
|
35
|
+
query.first_or_create! creation
|
|
36
|
+
|
|
37
|
+
end
|
|
35
38
|
|
|
36
|
-
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::ArticleNumber::Marking'
|
|
39
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::ArticleNumber::Marking'
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -3,28 +3,34 @@
|
|
|
3
3
|
# https://en.wikipedia.org/wiki/Vehicle_identification_number
|
|
4
4
|
# GB 16735-2004
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
validates :vehicle_descriptor_section, presence: true, length: { is: columns_hash['vehicle_descriptor_section'].limit }
|
|
16
|
-
validates :check_digit, presence: true, length: { is: columns_hash['check_digit'].limit }
|
|
17
|
-
validates :vehicle_identifier_section, presence: true, length: { is: columns_hash['vehicle_identifier_section'].limit }
|
|
18
|
-
|
|
19
|
-
def code=(code)
|
|
20
|
-
code = code.to_s
|
|
21
|
-
write_attribute :code, code
|
|
22
|
-
if code.present?
|
|
23
|
-
write_attribute :world_manufacturer_identifier, code[0..2]
|
|
24
|
-
write_attribute :vehicle_descriptor_section, code[3..7]
|
|
25
|
-
write_attribute :check_digit, code[8]
|
|
26
|
-
write_attribute :vehicle_identifier_section, code[9..16]
|
|
27
|
-
end
|
|
28
|
-
end
|
|
6
|
+
module Unidom
|
|
7
|
+
module ArticleNumber
|
|
8
|
+
|
|
9
|
+
class VehicleIdentificationNumber < ApplicationRecord
|
|
10
|
+
|
|
11
|
+
self.table_name = 'unidom_vehicle_identification_numbers'
|
|
12
|
+
|
|
13
|
+
include Unidom::Common::Concerns::ModelExtension
|
|
14
|
+
include Unidom::ArticleNumber::Concerns::AsBarcode
|
|
29
15
|
|
|
30
|
-
|
|
16
|
+
validates :code, uniqueness: true, 'unidom/article_number/vehicle_identification_number': true
|
|
17
|
+
validates :world_manufacturer_identifier, presence: true, length: { is: columns_hash['world_manufacturer_identifier'].limit }
|
|
18
|
+
validates :vehicle_descriptor_section, presence: true, length: { is: columns_hash['vehicle_descriptor_section'].limit }
|
|
19
|
+
validates :check_digit, presence: true, length: { is: columns_hash['check_digit'].limit }
|
|
20
|
+
validates :vehicle_identifier_section, presence: true, length: { is: columns_hash['vehicle_identifier_section'].limit }
|
|
21
|
+
|
|
22
|
+
def code=(code)
|
|
23
|
+
code = code.to_s
|
|
24
|
+
write_attribute :code, code
|
|
25
|
+
if code.present?
|
|
26
|
+
write_attribute :world_manufacturer_identifier, code[0..2]
|
|
27
|
+
write_attribute :vehicle_descriptor_section, code[3..7]
|
|
28
|
+
write_attribute :check_digit, code[8]
|
|
29
|
+
write_attribute :vehicle_identifier_section, code[9..16]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::ArticleNumber::VehicleIdentificationNumber'
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
# https://en.wikipedia.org/wiki/Vehicle_identification_number#Check-digit_calculation
|
|
2
2
|
# GB 16735-2004
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
WEIGHTS = '8765432X098765432'.freeze
|
|
7
|
-
TRANSLITERATION = '0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ'.freeze
|
|
8
|
-
CHECK_DIGITS = '0123456789X'.freeze
|
|
9
|
-
|
|
10
|
-
def validate_each(record, attribute, value)
|
|
11
|
-
value = value.to_s.upcase
|
|
12
|
-
if value.length>17
|
|
13
|
-
record.errors[attribute] << (options[:message]||'The length should be 17')
|
|
14
|
-
elsif value.match /I|O|Q/
|
|
15
|
-
record.errors[attribute] << (options[:message]||'I, O, Q should be excluded')
|
|
16
|
-
else
|
|
17
|
-
record.errors[attribute] << (options[:message]||'is invalid') unless check_digit(value)==value[8]
|
|
18
|
-
end
|
|
19
|
-
end
|
|
4
|
+
module Unidom
|
|
5
|
+
module ArticleNumber
|
|
20
6
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
7
|
+
class VehicleIdentificationNumberValidator < ActiveModel::EachValidator
|
|
8
|
+
|
|
9
|
+
WEIGHTS = '8765432X098765432'.freeze
|
|
10
|
+
TRANSLITERATION = '0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ'.freeze
|
|
11
|
+
CHECK_DIGITS = '0123456789X'.freeze
|
|
12
|
+
|
|
13
|
+
def validate_each(record, attribute, value)
|
|
14
|
+
value = value.to_s.upcase
|
|
15
|
+
if value.length>17
|
|
16
|
+
record.errors[attribute] << (options[:message]||'The length should be 17')
|
|
17
|
+
elsif value.match /I|O|Q/
|
|
18
|
+
record.errors[attribute] << (options[:message]||'I, O, Q should be excluded')
|
|
19
|
+
else
|
|
20
|
+
record.errors[attribute] << (options[:message]||'is invalid') unless check_digit(value)==value[8]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
def check_digit(value)
|
|
25
|
+
checksum = 0
|
|
26
|
+
value.chars.each_with_index do |char, index| checksum += self.class::TRANSLITERATION.index(char)%10*self.class::CHECK_DIGITS.index(self.class::WEIGHTS.at(index)) end
|
|
27
|
+
self.class::CHECK_DIGITS.at checksum%11
|
|
28
|
+
end
|
|
28
29
|
|
|
30
|
+
private :check_digit
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
29
35
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class CreateUnidomMarkings < ActiveRecord::Migration
|
|
1
|
+
class CreateUnidomMarkings < ActiveRecord::Migration[6.0]
|
|
2
2
|
|
|
3
3
|
def change
|
|
4
4
|
|
|
@@ -11,9 +11,9 @@ class CreateUnidomMarkings < ActiveRecord::Migration
|
|
|
11
11
|
t.references :marker, type: :uuid, null: false,
|
|
12
12
|
polymorphic: { null: false, default: '', limit: 200 }
|
|
13
13
|
|
|
14
|
-
t.column :state, 'char(1)', null: false, default:
|
|
15
|
-
t.datetime :opened_at, null: false, default: ::
|
|
16
|
-
t.datetime :closed_at, null: false, default: ::
|
|
14
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
|
15
|
+
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
|
16
|
+
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
|
17
17
|
t.boolean :defunct, null: false, default: false
|
|
18
18
|
t.jsonb :notation, null: false, default: {}
|
|
19
19
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class CreateUnidomEan13Barcodes < ActiveRecord::Migration
|
|
1
|
+
class CreateUnidomEan13Barcodes < ActiveRecord::Migration[6.0]
|
|
2
2
|
|
|
3
3
|
def change
|
|
4
4
|
|
|
@@ -10,9 +10,9 @@ class CreateUnidomEan13Barcodes < ActiveRecord::Migration
|
|
|
10
10
|
t.string :item_reference, null: false, default: '0'*2, limit: 6
|
|
11
11
|
t.column :check_digit, 'char(1)', null: false, default: '0'
|
|
12
12
|
|
|
13
|
-
t.column :state, 'char(1)', null: false, default:
|
|
14
|
-
t.datetime :opened_at, null: false, default: ::
|
|
15
|
-
t.datetime :closed_at, null: false, default: ::
|
|
13
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
|
14
|
+
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
|
15
|
+
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
|
16
16
|
t.boolean :defunct, null: false, default: false
|
|
17
17
|
t.jsonb :notation, null: false, default: {}
|
|
18
18
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class CreateUnidomEan8Barcodes < ActiveRecord::Migration
|
|
1
|
+
class CreateUnidomEan8Barcodes < ActiveRecord::Migration[6.0]
|
|
2
2
|
|
|
3
3
|
def change
|
|
4
4
|
|
|
@@ -9,9 +9,9 @@ class CreateUnidomEan8Barcodes < ActiveRecord::Migration
|
|
|
9
9
|
t.column :item_reference, 'char(4)', null: false, default: '0'*4
|
|
10
10
|
t.column :check_digit, 'char(1)', null: false, default: '0'
|
|
11
11
|
|
|
12
|
-
t.column :state, 'char(1)', null: false, default:
|
|
13
|
-
t.datetime :opened_at, null: false, default: ::
|
|
14
|
-
t.datetime :closed_at, null: false, default: ::
|
|
12
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
|
13
|
+
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
|
14
|
+
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
|
15
15
|
t.boolean :defunct, null: false, default: false
|
|
16
16
|
t.jsonb :notation, null: false, default: {}
|
|
17
17
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class CreateUnidomVehicleIdentificationNumbers < ActiveRecord::Migration
|
|
1
|
+
class CreateUnidomVehicleIdentificationNumbers < ActiveRecord::Migration[6.0]
|
|
2
2
|
|
|
3
3
|
def change
|
|
4
4
|
|
|
@@ -10,9 +10,9 @@ class CreateUnidomVehicleIdentificationNumbers < ActiveRecord::Migration
|
|
|
10
10
|
t.column :check_digit, 'char(1)', null: false, default: '0'
|
|
11
11
|
t.column :vehicle_identifier_section, 'char(8)', null: false, default: '0'*8
|
|
12
12
|
|
|
13
|
-
t.column :state, 'char(1)', null: false, default:
|
|
14
|
-
t.datetime :opened_at, null: false, default: ::
|
|
15
|
-
t.datetime :closed_at, null: false, default: ::
|
|
13
|
+
t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
|
|
14
|
+
t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
|
|
15
|
+
t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
|
|
16
16
|
t.boolean :defunct, null: false, default: false
|
|
17
17
|
t.jsonb :notation, null: false, default: {}
|
|
18
18
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: unidom-article_number
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Topbit Du
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-08-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: unidom-common
|
|
@@ -75,11 +75,11 @@ files:
|
|
|
75
75
|
- lib/unidom/article_number/types_rspec.rb
|
|
76
76
|
- lib/unidom/article_number/validators_rspec.rb
|
|
77
77
|
- lib/unidom/article_number/version.rb
|
|
78
|
-
homepage: https://
|
|
78
|
+
homepage: https://gitee.com/Unidom/unidom-article_number
|
|
79
79
|
licenses:
|
|
80
80
|
- MIT
|
|
81
81
|
metadata: {}
|
|
82
|
-
post_install_message:
|
|
82
|
+
post_install_message:
|
|
83
83
|
rdoc_options: []
|
|
84
84
|
require_paths:
|
|
85
85
|
- lib
|
|
@@ -94,8 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
95
|
version: '0'
|
|
96
96
|
requirements: []
|
|
97
|
-
rubygems_version: 3.
|
|
98
|
-
signing_key:
|
|
97
|
+
rubygems_version: 3.2.3
|
|
98
|
+
signing_key:
|
|
99
99
|
specification_version: 4
|
|
100
100
|
summary: Unidom Article Number Domain Model Engine 物品编码领域模型引擎
|
|
101
101
|
test_files: []
|