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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesCustomerSnTransformService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Slf4j
@Service
public class MesCustomerSnTransformService implements IMesCustomerSnTransformService {

    //通用汽车客制化58位条码转换
    @Override
    public String transformBarCodeGm(String barCode) {
        if (StringUtils.isEmpty(barCode)) return barCode;
        if (barCode.length() != MesPcnExtConstWords.CUSTOMER_SN_LENGTH_GM) return barCode;
        String a = barCode.substring(0, 3);
        String b = barCode.substring(3, 5);
        String c = barCode.substring(5, 20);
        String d = barCode.substring(20, 29);
        String e = barCode.substring(29, 41);
        String f = barCode.substring(41, 58);
        return a + (char)30 + b + (char)29 + c + (char)29 + d + (char)29 + e + (char)29 + f + (char)30 + (char)04;
        /*public static void main(String[] args) {
            String barCode = "[)>06Y4110000000000XP2638975612V545238347T1A24240A2B4C0242";
            String a = barCode.substring(0, 3);
            String b = barCode.substring(5, 20);
            String c = barCode.substring(20, 29);
            String d = barCode.substring(29, 41);
            String e = barCode.substring(41, 58);
            String sn = a + (char)30 + "06" + (char)29 + b + (char)29 + c + (char)29 + d + (char)29 + e + (char)30 + (char)04;
            System.out.println(barCode + "长度" + barCode.length());
            System.out.println(a + "长度" + a.length());
            System.out.println(b + "长度" + b.length());
            System.out.println(c + "长度" + c.length());
            System.out.println(d + "长度" + d.length());
            System.out.println(e + "长度" + e.length());
            System.out.println(sn + "长度" + sn.length());
        }*/
    }

}
