package com.deer.wms.produce.manage.constant;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

import com.deer.wms.project.seed.util.RandomUtil;


public class ProduceManagePublicMethod {

    /**
     * 自动生成唯一编码，规则：类型简称（type）+20190728+UUID后十位
     * type:WL,物料编码；JGD，加工单
     * @return
     */
    public static String creatUniqueCode(String type) {
        Date date = new Date();
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
        String timePartStr = sdf1.format(date);
        String uuidStr = UUID.randomUUID().toString().substring(24);
        String newCode = type+timePartStr+uuidStr;

        return newCode;
    }

    /**
     * 自动生成唯一的批次明细条码，规则：PCMX+八位日期+批次加工单id+批次号+卷号
     * @return
     */
    public static String creatBatchDetCode(Date createDate, Integer productProcessId, String batchCode, Integer piNum, String volumeNum) {
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
        String timePartStr = sdf1.format(createDate);

        int count=0; //位数计数
        while(piNum>=1) {
            piNum/=10;
            count++;
        }

        for (int i = 0; i < count-1 ; i++) {
            volumeNum = 0+volumeNum;//如果是一位数，卷号为1，如果是两位数，卷号为01，如果是三位数，卷号为001，以此类推
        }

        String batchDetCode = "PCMX"+timePartStr+productProcessId+batchCode+volumeNum;

        return batchDetCode;
    }


   public static void main(String[] args){
        String code = creatBatchDetCode(new Date(), 10, "1", 100, "1");
       System.out.println("----------"+code);
   }
}
