package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.numberrule;

import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.MesPcnException;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.mes.pcn.api.iservice.busi.INumberRulePackAttributeStrategyService;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.StringJoiner;

/**
 * @Description : 内部条码
 * @Reference :
 * @Author : junsheng.li
 * @CreateDate 2024/9/27 13:23
 * @Modify:
 **/
@Component
public class InternalBarcodeNumberRuleStrategyService implements INumberRulePackAttributeStrategyService {


    @Override
    public GenSerialNoModel execute(GenSerialNoModel genSerialNoModel) {
        if (StringUtils.isEmpty(genSerialNoModel.getShiftCode())) {
            MesPcnException.throwMesBusiException("班次代码未维护");
        }
        genSerialNoModel.setDynamicRule(genSerialNoModel.getShiftCode());
        Date date = new Date();
        //年月日缩写
        genSerialNoModel.setYear(getYearShort(date));
        genSerialNoModel.setMonth(getMonthShort(date));
        genSerialNoModel.setDay(getDayShort(date));
        return genSerialNoModel;
    }

    private String getYearShort(Date date) {
        return MesExtEnumUtil.YEAR_SHORT.valueOfDescription(Integer.parseInt(TimeTool.getYear(date)));
    }

    private String getMonthShort(Date date) {
        return MesExtEnumUtil.MONTH_SHORT.valueOfDescription(Integer.parseInt(TimeTool.getMonth(date)));
    }

    private String getDayShort(Date date) {
        return TimeTool.getDay(date);
    }

}
