package com.sw.mes.store.utils;

import com.sw.mes.core.utils.DateUtil;
import com.sw.mes.redis.server.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author zhaowenjie
 */
@Component
public class CodeGenUtil {

    private static RedisUtils redisUtils;

    @Autowired
    public CodeGenUtil(RedisUtils redisUtils) {
        CodeGenUtil.redisUtils = redisUtils;
    }

    /**
     * 在序号前面加0
     *
     * @param number 需要加的序号
     * @param width  需要加的长度
     * @return 字符串
     */
    public static String pad(Long number, int width) {
        return String.format("%0" + width + "d", number);
    }

    /**
     * @return eg：RK20230728001  RK20230728002  RK20230728003
     * @Author wupeng
     * @Description 生成入库单号
     * @Date 14:02 2023/7/28
     * @Param
     **/
    public static String genInputBillNo() {
        return "RK" + DateUtil.formatDate(new Date(), "yyyyMMdd") + pad(redisUtils.increment("input_bill_order_code"), 3);
    }

    /**
     * @return eg：SH20230728001  SH20230728002  SH20230728003
     * @Author wupeng
     * @Description 生成入库审核记录单号
     * @Date 14:02 2023/7/28
     * @Param
     **/
    public static String genInputRecordBillNo() {
        return "RKSH" + DateUtil.formatDate(new Date(), "yyyyMMdd") + pad(redisUtils.increment("input_record_bill_order_code"), 3);
    }

    /**
     * @return eg：CK20230728001  CK20230728002  CK20230728003
     * @Author wupeng
     * @Description 生成出库单号
     * @Date 14:02 2023/7/28
     * @Param
     **/
    public static String genOutputBillNo() {
        return "CK" + DateUtil.formatDate(new Date(), "yyyyMMdd") + pad(redisUtils.increment("output_bill_order_code"), 3);
    }

    /**
     * @return eg：CKSH20230728001  CKSH20230728002  CKSH20230728003
     * @Author wupeng
     * @Description 生成出库审核记录单号
     * @Date 14:02 2023/7/28
     * @Param
     **/
    public static String genOutputRecordBillNo() {
        return "CKSH" + DateUtil.formatDate(new Date(), "yyyyMMdd") + pad(redisUtils.increment("output_record_bill_order_code"), 3);
    }


    /**
     * @return eg：DB20230728001  DB20230728002  DB20230728003
     * @Author wupeng
     * @Description 生成调拨单号
     * @Date
     * @Param
     **/
    public static String genAllotBillNo() {
        return "DB" + DateUtil.formatDate(new Date(), "yyyyMMdd") + pad(redisUtils.increment("allot_bill_order_code"), 3);
    }

    /**
     * @return eg：DBSH20230728001  DBSH20230728002  DBSH20230728003
     * @Author wupeng
     * @Description 生成调拨单号
     * @Date
     * @Param
     **/
    public static String genAllotRecordBillNo() {
        return "DBSH" + DateUtil.formatDate(new Date(), "yyyyMMdd") + pad(redisUtils.increment("allot_record_bill_order_code"), 3);
    }

}
