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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxPrintTemplateMethodService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.PackageExtModel;
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.stereotype.Service;

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

/**
 * @Description 工单包装条码打印数据
 * @Author: wangjie
 * @CreateDate: 2020/6/22 9:38 AM
 * @Description:
 **/
@Slf4j
@Service
public class SxWorkOrderPrintPackageService extends SxPrintDispatchService implements ISxPrintTemplateMethodService {

    @Override
    public List<Map<String, Object>> exec(SxPrintTemplateModel printModel) {
        List<Map<String, Object>> resultMapList = null;
        List<PackageExtModel> packList = printModel.getPackList();
        for (PackageExtModel pack : packList) {
            if (null == pack) {
                continue;
            }
            if (CollectionUtils.isEmpty(resultMapList)) {
                resultMapList = new ArrayList<>();
            }
            Map<String, Object> resultMap = new HashMap<>();
            resultMap.put(MesPcnExtConstWords.PART_NO, pack.getPartNo());
            resultMap.put(MesPcnExtConstWords.PART_NAME_RDD, pack.getPartNameRdd());
            resultMap.put(MesPcnExtConstWords.PACKAGENO, getSnWithOutPercent(pack.getPackageNo()));
            resultMap.put(MesPcnExtConstWords.QTY, pack.getQty());

            resultMapList.add(resultMap);
        }
        return resultMapList;
    }

}
