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

import cn.estsh.i3plus.ext.mes.pcn.api.base.ISxWorkOrderExtService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxPrintTemplateMethodService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.BigOuterPackageModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxPrintTemplateModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description 净水器本体条码打印数据
 * @Author: mingliang.li
 * @CreateDate: 2020/6/22 9:38 AM
 * @Description:
 **/
@Slf4j
@Service
public class SxPrintBigPackageCodeService extends SxPrintDispatchService implements ISxPrintTemplateMethodService {

    @Autowired
    private ISxWorkOrderExtService sxWorkOrderExtService;

    @Override
    public List<Map<String, Object>> exec(SxPrintTemplateModel printModel) {
        List<Map<String, Object>> resultMapList = null;
        List<BigOuterPackageModel> snList = printModel.getBigOuterPackageList();

        for (BigOuterPackageModel sn : snList) {
            if (null == sn) {
                continue;
            }
            if (CollectionUtils.isEmpty(resultMapList)) {
                resultMapList = new ArrayList<>();
            }
            Map<String, Object> resultMap = new HashMap<>();
            resultMap.put(MesPcnExtConstWords.COLOR_CODE, printModel.getPart().getColorCode());
            resultMap.put(MesPcnExtConstWords.OUTER_PACKAGE_NO, getSnWithOutPercent(sn.getOuterPackageNo()));
            resultMap.put(MesPcnExtConstWords.OUTER_PACKAGE_NO2, getSnWithOutPercent(sn.getOuterPackageNo()));
            resultMap.put(MesPcnExtConstWords.BAR_CODE, sn.getOuterPackageNo());
            resultMap.put(MesPcnExtConstWords.PRODUCT_NUMBER, printModel.getPart().getProductNumber());
            resultMap.put(MesPcnExtConstWords.SHI_XIANG_DI_CODE, printModel.getPart().getShiXiangDiCode());
            resultMap.put(MesPcnExtConstWords.MODEL, printModel.getPart().getModel());
            resultMap.put(MesPcnExtConstWords.SHI_XIANG_DI_CODE_2, "-" + printModel.getPart().getShiXiangDiCode());
            resultMapList.add(resultMap);
        }
        return resultMapList;
    }

}
