简体   繁体   中英

Database design for barcode ranges

I'm working on a shipping system for our warehouse. Basically what I'm trying to accomplish is, taking a number from a barcode range, and assigning it to a shipping order.

The ranges are given by our partner couriers periodically and they are usually not consecutive, eg 9000000-9009999 , 9020000-9029999 . Each number in a range should be used only once.

Currently the range is hardcoded in the script and the current index is stored in a file. (legacy implementation)

But I feel it's proper to have an interface where even non-programmers can manage ranges, monitor the status of each range (eg which one is currently “active”, what's the current index, etc). And when the current range runs out, it should automatically switch to the next range available. Below is the UI design I came up with. 条码范围管理界面

Do you think it's a good idea to store the range data in the database? If so, how should I design the database table?

Some other things to be taken into considerations are:

  • Some ranges are recycled by the courier, so there is a chance we receive the same range twice. (Well, maybe some years later)
  • Most of the time a range can last 4 months to 6 months, so there won't be many ranges. (If we use a table to store the ranges, we're looking at 2 to 4 new range records a year)
  • When a range is finished, it's basically useless?

I believe you need to take a higher-level view of matters.

Key is the GS1 system, previously known as EAN (which I use as I've used it for 20+ years.)

Important issue is that you should not allow YOUR shipment number to be dictated by an outside agency. If you decide to keep shipment details for 7 years say, and they decide to recycle numbers after 3, then you have a data problem. Equally, if you have more than one shipping agency (or take another on in the future, of the existing agency gets split into parts or sold or whatever) then again you can get a data problem when THEIR system changes.

(and that applies to ALL data not directly controlled by your organisation)

The EAN way is by using a SSCC - Serial Shipping Container Code. This is an 18-digit code assigned to an object and uniquely identifies that object. It has a nominal life of three years, so it should not be re-issued more frequently.

The SSCC is produced according to an internationally-recognised structure and encoded in a "code 128" barcode (hence it is often referred to as GS1-128 or EAN-128) which has a lead character of [fnc1] - internationally accepted to signify "This is a barcode following the EAN-128 format". The remaining characters are:

00 - AI for an SSCC (there is a whole slough of codes for various uses. "00" means "SSCC". It is actually an Application Identifier - though even barcode-printer manufacturers have been known to believe it forms part of a "20-digit code".

1 digit - In former times, "3" was an "internal pallet" and "4" and "external pallet". Since the one often became the other, this system was quickly abandoned, but the legend persists - some will incorrectly insist that the leading digit must be a "3".

7-9 digits - country code + organisation code. Allotted by the controlling organisation and licensed to the using member organisation.

9-7 digits - individual shipment number issued by the using member organisation.

1 digit - check digit produced according to the published algorithm and usually calculated by the printer firmware.

So the first and penultimate group of digits are allocated by the GS1-member organisation (ie your organisation) at their own discretion.

This system can be used for shipping your goods outside of your organisation and also for tracking the goods within your organisation.

In all probability, your shipper has allotted a subset of their numbers to you as they commonly do with small organisations that are not GS1 members. Unfortunately, the clerks performing this task prefer to treat all of their customers the same way, so the legend arises that you have to use their system. If this idea has taken root in the fertile minds of their IT monkeys, they may have set their system up on that assumption.

If their IT system has been set up by a professional, then they will be able to accept any complying SSCC - you simply send then your list of shipments issued with your numbers and their software will validate it against the label produced by your printer when the goods are picked up.

You'd really need to talk to their IT department on what their requirements are.

This would mean that you simply don't need to use their number at all - you can use the system as it was designed, using your numbers over which you have control.

If non-adjacent ranges belong to the same Entity, then one table would have Entities, including an entity_id . The other table would contain barcode ranges (start and end), plus the entity_id .

You would need code to verify that you don't create overlapping ranges. And to deal with deleting a sub-range.

If you expect to have millions of ranges, then I suggest you adapt my IP-address blocks code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM