package com.sw.mes.yb.printer.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sw.mes.base.factory.inspect.entity.DocumentPrint;
import com.sw.mes.base.factory.inspect.service.DefaultCrystalAttrService;
import com.sw.mes.base.factory.inspect.service.DocumentPrintService;
import com.sw.mes.base.factory.material.entity.MaterialModel;
import com.sw.mes.base.factory.material.service.MaterialModelService;
import com.sw.mes.base.system.entity.DictionaryItem;
import com.sw.mes.base.system.service.DictionaryItemService;
import com.sw.mes.base.system.service.impl.PrintService;
import com.sw.mes.base.workinprocess.entity.PlanProcessingOrder;
import com.sw.mes.base.workinprocess.entity.WipStorage;
import com.sw.mes.base.workinprocess.service.PlanProcessingOrderService;
import com.sw.mes.base.workinprocess.service.WipStorageService;
import com.sw.mes.core.api.materialclean.MaterialCleanFeignClients;
import com.sw.mes.core.api.system.FbFeignClients;
import com.sw.mes.core.api.system.StoreFeignClients;
import com.sw.mes.core.constant.Constants;
import com.sw.mes.core.context.BaseContextHandler;
import com.sw.mes.core.dto.FbTurnstoreTrayItemDto;
import com.sw.mes.core.dto.PrintInfoDto;
import com.sw.mes.core.dto.store.StoreInputApplyCodeDto;
import com.sw.mes.core.dto.store.WarehouseOutputBillBo;
import com.sw.mes.core.dto.store.WarehouseOutputBillDetailBo;
import com.sw.mes.core.entity.FbCheckOutData;
import com.sw.mes.core.enums.EnumValuesFactory;
import com.sw.mes.core.enums.SectionIndexRangeEnum;
import com.sw.mes.core.exception.BusinessException;
import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultCode;
import com.sw.mes.core.utils.BeanUtil;
import com.sw.mes.core.utils.DateUtil;
import com.sw.mes.core.utils.NumberUtil;
import com.sw.mes.enumvalue.EnumDocketPrint;
import com.sw.mes.enumvalue.EnumValuesServer;
import com.sw.mes.inspect.dao.YbOemDataDao;
import com.sw.mes.inspect.entity.YbInspectData;
import com.sw.mes.inspect.entity.YbOemData;
import com.sw.mes.inspect.service.YbInspectDataService;
import com.sw.mes.production.entity.FormulaMaterialClass;
import com.sw.mes.production.entity.FormulaSchemeDetail;
import com.sw.mes.production.service.FormulaMaterialClassService;
import com.sw.mes.production.service.FormulaSchemeDetailService;
import com.sw.mes.production.service.FormulaSchemeService;
import com.sw.mes.utils.StringUtils;
import com.sw.mes.yb.check.entity.CrystallonData;
import com.sw.mes.yb.check.service.CrystallonDataService;
import com.sw.mes.yb.pad.dto.DrawLineDetailDto;
import com.sw.mes.yb.pad.dto.DrawLineDto;
import com.sw.mes.yb.pad.entity.*;
import com.sw.mes.yb.pad.service.*;
import com.sw.mes.yb.pc.entity.SideSkinCodingRule;
import com.sw.mes.yb.pc.service.SectionService;
import com.sw.mes.yb.pc.service.SideSkinCodingRuleService;
import com.sw.mes.yb.printer.dto.*;
import com.sw.mes.yb.printer.entity.PrinterLog;
import com.sw.mes.yb.printer.service.DocketPrintService;
import com.sw.mes.yb.printer.service.PrinterLogService;
import com.sw.mes.yb.production.dto.*;
import com.sw.mes.yb.production.entity.*;
import com.sw.mes.yb.production.service.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author: GaoXinJian
 * @Date: 2022-01-20 11:44
 */
@Service
@Transactional
@Log4j2
public class DocketPrintServiceImpl implements DocketPrintService {


    @Autowired
    PlanProcessingOrderService planProcessingOrderService;
    @Autowired
    private DocumentPrintService documentMouldService;
    @Autowired
    private PrintService printService;
    @Autowired
    private LongCrystalService longCrystalService;
    @Autowired
    private ProductionPaintingLineService productionPaintingLineService;
    @Autowired
    private ProductionPaintingLineDetailService productionPaintingLineDetailService;
    @Autowired
    private YbInspectDataService inspectDataBaseService;
    @Autowired
    private SideSkinCodingRuleService sideSkinCodingRuleService;
    @Autowired
    private FbFeignClients fbFeignClients;
    @Autowired
    private PrinterLogService printerLogService;
    @Autowired
    private DefaultCrystalAttrService defaultCrystalAttrService;
    @Autowired
    private FbProductCardService fbProductCardService;
    @Autowired
    private FbReCutService fbReCutService;
    @Autowired
    private SectionNoDetailService sectionNoDetailService;
    @Autowired
    RecutDetailService recutDetailService;
    @Autowired
    private ProductionRecutService productionRecutService;
    @Autowired
    private SectionService sectionService;
    @Autowired
    private DictionaryItemService dictionaryItemService;
    @Autowired
    private AgainTaskDetailService againTaskDetailService;
    @Autowired
    private LoadingTaskService loadingTaskService;
    @Autowired
    private StoreFeignClients storeFeignClients;
    @Autowired
    private WipStorageService wipStorageService;

    @Autowired
    private CrystallonDataService crystallonDataService;

    @Autowired
    private YbOemDataDao ybOemDataDao;

    @Autowired
    private MaterialModelService materialModelService;

    @Autowired
    private RecycledMaterialManageService recycledMaterialManageService;

    @Autowired
    private MaterialCleanFeignClients cleanFeignClients;

    @Autowired
    private SurplusInfoService surplusInfoService;

    @Autowired
    private FormulaSchemeService formulaSchemeService;

    @Autowired
    private LoadingTaskLogService loadingTaskLogService;

    @Autowired
    private BlastFurnaceDetailService blastFurnaceDetailService;

    @Autowired
    private InputFurnaceBurdenService inputFurnaceBurdenService;

    @Autowired
    private InputFurnaceDetailService inputFurnaceDetailService;

    @Autowired
    private FormulaMaterialClassService formulaMaterialClassService;

    @Autowired
    private FormulaSchemeDetailService formulaSchemeDetailService;

    DecimalFormat df = new DecimalFormat("#.#");
    DecimalFormat df2 = new DecimalFormat("#.##");

    @Override
    public DocketPrintResultDto docketPrint(List<DocketPrintDto> docketPrintDtoList) {
        //预览结果：打印操作时为null
        List<String> previewList = new ArrayList<>();
        //打印结果
        DocketPrintResultDto docketPrintResultDto = new DocketPrintResultDto();
        //打印成功条数
        Integer successfulNum = 0;
        //打印失败条数
        Integer failedNum = 0;
        //成功长晶棒/晶段编码集合
        List<String> successfulCodeList = new ArrayList<>();
        //失败详情集合（包括失败长晶棒/晶段编码及失败描述
        List<DocketPrintFailedDetail> docketPrintFailedDetailList = new ArrayList<>();
        //打印日志
        List<PrinterLog> printerLogList = new ArrayList<>();

        for (DocketPrintDto docketPrintDto : docketPrintDtoList) {
            //打印失败详情
            DocketPrintFailedDetail docketPrintFailedDetail = new DocketPrintFailedDetail();
            //验证编号和模板是否符合（根据加工工单类型判断，PlanProcessingOrder：加工工单）
            List<PlanProcessingOrder> planProcessingOrderList = planProcessingOrderService.findByCodeOrderByIdDesc(docketPrintDto.getCode());
            if (planProcessingOrderList.size() > 0) {
                PlanProcessingOrder planProcessingOrder = planProcessingOrderList.get(0);
                if (docketPrintDto.getPrintType().equals(EnumDocketPrint.PrintModelType.长晶棒头划线.getValue())) {
                    //长晶棒头划线传入的为长棒
                    if (!planProcessingOrder.getOrderType().equals(EnumValuesFactory.PlanProcessingOrderOrderType.单晶.getKey())) {
                        //编码和模板不符

                        //打印失败详情
                        failedNum++;
                        docketPrintFailedDetail.setCode(docketPrintDto.getCode());
                        docketPrintFailedDetail.setDescription("编码和模板不符");
                        docketPrintFailedDetailList.add(docketPrintFailedDetail);

                        //打印日志
                        PrinterLog printerLog = this.initPrinterLog(docketPrintDto, false, JSONObject.toJSONString(docketPrintFailedDetail));
                        printerLogList.add(printerLog);
                        continue;
                    }
                } else {
                    //其它类型模板传入的为短棒
                    if (!planProcessingOrder.getOrderType().equals(EnumValuesFactory.PlanProcessingOrderOrderType.晶段.getKey())) {
                        //                        //编码和模板不符
                        //打印失败详情
                        failedNum++;
                        docketPrintFailedDetail.setCode(docketPrintDto.getCode());
                        docketPrintFailedDetail.setDescription("编码和模板不符");
                        log.error("编码和模板不符");
                        docketPrintFailedDetailList.add(docketPrintFailedDetail);

                        //打印日志
                        PrinterLog printerLog = this.initPrinterLog(docketPrintDto, false, JSONObject.toJSONString(docketPrintFailedDetail));
                        printerLogList.add(printerLog);
                        continue;
                    }
                }

            } else {
                //输入的不是晶段编号的时候如何处理
                // TODO: 2022/1/20  未查询到加工工单，暂时不处理，直接打印
            }
            EnumDocketPrint.PrintModelType printModelType = EnumDocketPrint.PrintModelType.getEnum(docketPrintDto.getPrintType());
            //预览结果
            List<String> preview = new ArrayList<>();
            if (printModelType == null) {
                throw new BusinessException("打印类型为空");
            }
            try {
                switch (printModelType) {
//                    case 画线标签:
//                        preview = this.printDrawLineLabel(docketPrintDto);
//                        break;
//                    case 圆棒合格证:
//                        preview = this.printYbCrystalCertificate(docketPrintDto);
//                        break;
//                    case 合格证标签:
//                        preview = this.printCertificateLabel(docketPrintDto);
//                        break;
                    case 圆棒反切标签:
                        preview = this.printRoundReverseTangent(docketPrintDto);
                        break;
//                    case 圆棒初级标签:
//                        preview = this.printYbPrimaryLabel(docketPrintDto);
//                        break;
//                    case 方棒合格证:
//                        preview = this.printFbCrystalCertificate(docketPrintDto);
//                        break;
                    case 方棒反切标签:
                        preview = this.printFbReCuttingLabel(docketPrintDto);
                        break;
//                    case 方棒唛头:
//                        preview = this.printFbShippingMark(docketPrintDto);
//                        break;
                    case PDA补签:
                        preview = this.printPdaReLabel(docketPrintDto);
                        break;
                    case 晶棒划线条码:
                        preview = this.printCrystalDocumentMould(docketPrintDto);
                        break;
                    case 长晶棒头划线:
                        preview = this.printLongShippingMark(docketPrintDto);
                        break;
                    case 热场条码:
                        preview = this.printHotSpotCode(docketPrintDto);
                        break;
                    case 圆棒标签:
                        preview = this.printYBLabel(docketPrintDto);
                        break;
                    case 方棒标签:
                        preview = this.printFBLabel(docketPrintDto);
                        break;
//                    case 成品标签:
//                        preview = this.printCleanBox(docketPrintDto);
//                        break;
//                    case 成托标签:
//                        preview = this.printCleanGroup(docketPrintDto);
//                        break;
                    case 方棒组拖:
                        preview = this.printFbTutnStore(docketPrintDto);
                        break;
                    case 方棒组拖拖号:
                        preview = this.printFbTutnStoreNo(docketPrintDto);
                        break;
                    case 籽晶打印:
                        preview = crystallonSinglePrint(docketPrintDto);
                        break;
                    case 分选打印:
                        preview = this.cleanUnpackingPrint(docketPrintDto);
                        break;
                    case 无尘打印:
                        preview = this.cleanGroupPrint(docketPrintDto);
                        break;
                    case 返工打印:
                        preview = this.cleanReworkPrint(docketPrintDto);
                        break;
                    case 余料打印:
                        preview = this.recycledGroupPrint(docketPrintDto);
                        break;
                    case 单晶余料标签:
                        preview = this.printPcSurplusInfo(docketPrintDto);
                        break;
                    case 单晶补标签:
                        preview = this.printCrystalPatchLabel(docketPrintDto);
                        break;
                    case 废料标签:
                        preview = this.printCrystalelOutPut(docketPrintDto);
                        break;
                    case 余料出库打印:
                        preview = this.printStoreOutPut(docketPrintDto);
                        break;
                    default:
                        throw new BusinessException("打印类型待开发");
                }

                //打印结果
                successfulCodeList.add(docketPrintDto.getCode());
                successfulNum++;

                //打印日志
                PrinterLog printerLog = this.initPrinterLog(docketPrintDto, true, JSONObject.toJSONString(docketPrintDto.getCode() + ":" + preview));
                printerLogList.add(printerLog);
                previewList.addAll(preview);
            } catch (Exception e) {
                e.printStackTrace();
                //打印结果
                failedNum++;
                docketPrintFailedDetail.setDescription(e.getMessage());
                docketPrintFailedDetail.setCode(docketPrintDto.getCode());
                docketPrintFailedDetailList.add(docketPrintFailedDetail);

                //打印日志
                PrinterLog printerLog = this.initPrinterLog(docketPrintDto, false, JSONObject.toJSONString(docketPrintFailedDetail));
                printerLogList.add(printerLog);
            }


        }

        docketPrintResultDto.setDocketPrintFailedDetailList(docketPrintFailedDetailList);
        docketPrintResultDto.setFailedNum(failedNum);
        docketPrintResultDto.setSuccessfulNum(successfulNum);
        docketPrintResultDto.setSuccessfulCodeList(successfulCodeList);
        //保存打印日志
        if (docketPrintDtoList.get(0).getIsPreview() == null || !docketPrintDtoList.get(0).getIsPreview()) {
            this.saveLog(printerLogList);

        }
        docketPrintResultDto.setPreviewList(previewList);
        return docketPrintResultDto;


    }

    @Override
    public DocketPrintResultDto docketPrint1(List<DocketPrintDto> docketPrintDtoList) {
        //预览结果：打印操作时为null
        List<String> previewList = new ArrayList<>();
        //打印结果
        DocketPrintResultDto docketPrintResultDto = new DocketPrintResultDto();
        //打印成功条数
        Integer successfulNum = 0;
        //打印失败条数
        Integer failedNum = 0;
        //成功长晶棒/晶段编码集合
        List<String> successfulCodeList = new ArrayList<>();
        //失败详情集合（包括失败长晶棒/晶段编码及失败描述
        List<DocketPrintFailedDetail> docketPrintFailedDetailList = new ArrayList<>();
        //打印日志
        List<PrinterLog> printerLogList = new ArrayList<>();

        for (DocketPrintDto docketPrintDto : docketPrintDtoList) {
            //打印失败详情
            DocketPrintFailedDetail docketPrintFailedDetail = new DocketPrintFailedDetail();
            //验证模板是否符合

            EnumDocketPrint.PrintModelType printModelType = EnumDocketPrint.PrintModelType.getEnum(docketPrintDto.getPrintType());
            //预览结果
            List<String> preview = new ArrayList<>();
            if (printModelType == null) {
                throw new BusinessException("打印类型为空");
            }
            try {
                switch (printModelType) {
//                    case 画线标签:
//                        preview = this.printDrawLineLabel(docketPrintDto);
//                        break;
//                    case 圆棒合格证:
//                        preview = this.printYbCrystalCertificate(docketPrintDto);
//                        break;
//                    case 合格证标签:
//                        preview = this.printCertificateLabel(docketPrintDto);
//                        break;
                    case 圆棒反切标签:
                        preview = this.printYbReCuttingLabel2(docketPrintDto);
                        break;
//                    case 圆棒初级标签:
//                        preview = this.printYbPrimaryLabel(docketPrintDto);
//                        break;
//                    case 方棒合格证:
//                        preview = this.printFbCrystalCertificate(docketPrintDto);
//                        break;
                    case 方棒反切标签:
                        preview = this.printFbReCuttingLabel(docketPrintDto);
                        break;
//                    case 方棒唛头:
//                        preview = this.printFbShippingMark(docketPrintDto);
//                        break;
                    case PDA补签:
                        preview = this.printPdaReLabel(docketPrintDto);
                        break;
                    case 晶棒划线条码:
                        preview = this.printCrystalDocumentMould(docketPrintDto);
                        break;
                    case 长晶棒头划线:
                        preview = this.printLongShippingMark(docketPrintDto);
                        break;
                    case 热场条码:
                        preview = this.printHotSpotCode(docketPrintDto);
                        break;
                    case 圆棒标签:
                        preview = this.printYBLabel(docketPrintDto);
                        break;
                    case 方棒标签:
                        preview = this.printFBLabel(docketPrintDto);
                        break;
//                    case 成品标签:
//                        preview = this.printCleanBox(docketPrintDto);
//                        break;
//                    case 成托标签:
//                        preview = this.printCleanGroup(docketPrintDto);
//                        break;
                    default:
                        throw new BusinessException("打印类型待开发");
                }

                //打印结果
                successfulCodeList.add(docketPrintDto.getCode());
                successfulNum++;

                //打印日志
                PrinterLog printerLog = this.initPrinterLog(docketPrintDto, true, JSONObject.toJSONString(docketPrintDto.getCode() + ":" + preview));
                printerLogList.add(printerLog);
                previewList.addAll(preview);
            } catch (Exception e) {
                e.printStackTrace();
                //打印结果
                failedNum++;
                docketPrintFailedDetail.setDescription(e.getMessage());
                docketPrintFailedDetail.setCode(docketPrintDto.getCode());
                docketPrintFailedDetailList.add(docketPrintFailedDetail);

                //打印日志
                PrinterLog printerLog = this.initPrinterLog(docketPrintDto, false, JSONObject.toJSONString(docketPrintFailedDetail));
                printerLogList.add(printerLog);
            }


        }

        docketPrintResultDto.setDocketPrintFailedDetailList(docketPrintFailedDetailList);
        docketPrintResultDto.setFailedNum(failedNum);
        docketPrintResultDto.setSuccessfulNum(successfulNum);
        docketPrintResultDto.setSuccessfulCodeList(successfulCodeList);
        //保存打印日志
        if (docketPrintDtoList.get(0).getIsPreview() == null || !docketPrintDtoList.get(0).getIsPreview()) {
            this.saveLog(printerLogList);

        }
        docketPrintResultDto.setPreviewList(previewList);
        return docketPrintResultDto;


    }

    private List<String> printFbTutnStoreNo(DocketPrintDto docketPrintDto) {
        Result<List<FbTurnstoreTrayItemDto>> result = fbFeignClients.listAll(docketPrintDto.getCode());
        if (result.getCode() != ResultCode.SUCCESS.getCode()) {
            throw new BusinessException("获取组拖信息失败：" + result.getMessage());
        }
        if (result.getData().size() == 0) {
            throw new BusinessException("拖内信息为空");
        }
        List<Map<String, String>> keyValues = new LinkedList<>();
        Map<String, String> trayMap = new HashMap<>();
        trayMap.put("trayNo", docketPrintDto.getCode());
        keyValues.add(trayMap);
        Map<String, String> trayMap1 = new HashMap<>();
        trayMap1.put("trayNo", docketPrintDto.getCode());
        keyValues.add(trayMap1);
        return this.doPrint(docketPrintDto.getPrintModel(), keyValues, docketPrintDto.getIsPreview());
    }

    private List<String> printFbTutnStore(DocketPrintDto docketPrintDto) {
        Result<List<FbTurnstoreTrayItemDto>> result = fbFeignClients.listAll(docketPrintDto.getCode());
        if (result.getCode() != ResultCode.SUCCESS.getCode()) {
            throw new BusinessException("获取组拖信息失败：" + result.getMessage());
        }
        if (result.getData().size() == 0) {
            throw new BusinessException("拖内信息为空");
        }
        List<DictionaryItem> productType = dictionaryItemService.findByThemeValueAndEnable("product_category", true);
        final Map<String, String> productTypeMap = productType.stream().collect(Collectors.toMap(DictionaryItem::getValue, DictionaryItem::getName, (v1, v2) -> v1));

        List<DictionaryItem> dopant = dictionaryItemService.findByThemeValueAndEnable("dopant", true);
        final Map<String, String> dopantMap = dopant.stream().collect(Collectors.toMap(DictionaryItem::getValue, DictionaryItem::getExtendValue, (v1, v2) -> v1));

        List<DictionaryItem> specification = dictionaryItemService.findByThemeValueAndEnable("specificationOption", true);
        final Map<String, String> specificationMap = specification.stream().collect(Collectors.toMap(DictionaryItem::getValue, DictionaryItem::getExtendValue, (v1, v2) -> v1));
        //边距
        String sideLengthRange = "";
        String sectionNo = result.getData().get(0).getSectionNo();
        Result<FbCheckOutData> fbCheckOutDataresult = fbFeignClients.findFbCheckOutDataByFbSectionNo(sectionNo);
        if (!fbCheckOutDataresult.getCode().equals(ResultCode.SUCCESS.getCode())) {
            throw new RuntimeException("查询方棒检验信息异常");
        }
        FbCheckOutData fbCheckOutData = fbCheckOutDataresult.getData();
        if (null == fbCheckOutData) {
            throw new RuntimeException("无方棒检验信息");
        }
        sideLengthRange = fbCheckOutData.getSideLengthRange();
        //边宽
        String multipleSideLogic = getMultipleSideLogic(sideLengthRange);
        List<String> preview;
        List<Map<String, String>> keyValues = new LinkedList<>();
        result.getData().forEach(fbTurnstoreTrayItemDto -> {
            Map<String, String> map = new HashMap<>();
            map.put("sectionNo", fbTurnstoreTrayItemDto.getSectionNo());
            map.put("multipleSideLogic", multipleSideLogic);
            map.put("length", fbTurnstoreTrayItemDto.getLength().toString());
            map.put("productType", fbTurnstoreTrayItemDto.getProductType());
            map.put("dopant", fbTurnstoreTrayItemDto.getDopant());
            map.put("specification", fbTurnstoreTrayItemDto.getSpecification());
            map.put("productTypeA", productTypeMap.get(fbTurnstoreTrayItemDto.getProductType()));
            map.put("dopantA", dopantMap.get(fbTurnstoreTrayItemDto.getDopant()));
            map.put("specificationA", specificationMap.get(fbTurnstoreTrayItemDto.getSpecification()));
            map.put("total", fbTurnstoreTrayItemDto.getProductType() + "-" + productTypeMap.get(fbTurnstoreTrayItemDto.getProductType()) + "/" + fbTurnstoreTrayItemDto.getDopant() + "-" + dopantMap.get(fbTurnstoreTrayItemDto.getDopant()) + "/" + specificationMap.get(fbTurnstoreTrayItemDto.getSpecification()) + "-" + fbTurnstoreTrayItemDto.getSpecification());
            keyValues.add(map);
        });
        preview = this.doPrint(docketPrintDto.getPrintModel(), keyValues, docketPrintDto.getIsPreview());
        return preview;
    }

    private List<String> printCrystalelOutPut(DocketPrintDto docketPrintDto) {
        RecycledMaterialManage recycleMaterialByTrayNo = recycledMaterialManageService.getRecycleMaterialByTrayNo(docketPrintDto.getCode());
        List<Map<String, String>> keyValues = new LinkedList<>();
        List<String> preview;
        if(!ObjectUtils.isEmpty(recycleMaterialByTrayNo)){
            Map<String, String> map = new HashMap<>();
            map.put("factory","5041");//工厂代码
            map.put("materialName",recycleMaterialByTrayNo.getMaterialName());//物料描述
            map.put("materialCode",recycleMaterialByTrayNo.getMaterialCode());//物料编码
            map.put("boxCode",recycleMaterialByTrayNo.getBoxNo());//箱码
            map.put("suttle",String.valueOf(recycleMaterialByTrayNo.getWeight()));//净重
            map.put("SAPBatchNo",recycleMaterialByTrayNo.getDateProduceBatchNo());//SAP批次号
            keyValues.add(map);
        }
        preview = this.doPrint(docketPrintDto.getPrintModel(), keyValues, docketPrintDto.getIsPreview());
        return preview;
    }

    private List<String> printStoreOutPut(DocketPrintDto docketPrintDto) {
        Result<WarehouseOutputBillBo> result = storeFeignClients.findWarehouseOutputBillByCode(docketPrintDto.getCode());
        List<Map<String, String>> keyValues = new LinkedList<>();
        List<String> preview;
        if(result.getCode().equals(200) && !ObjectUtils.isEmpty(result.getData())){
            WarehouseOutputBillBo data = result.getData();
            List<Double> count = data.getOutputBillDetails().stream().map(entity -> {
                return Double.valueOf(String.valueOf(entity.getRequireCount()));
            }).collect(Collectors.toList());
            double sum = count.stream().mapToDouble(Double::doubleValue).sum();
            WarehouseOutputBillDetailBo warehouseOutputBillDetailBo = data.getOutputBillDetails().get(0);
            Map<String, String> map = new HashMap<>();
            map.put("outputBillNo",docketPrintDto.getCode());//出库单号
            map.put("factory","5041");//工厂代码
            map.put("materialName",warehouseOutputBillDetailBo.getMaterialModelName());//物料描述
            map.put("materialCode",warehouseOutputBillDetailBo.getMaterialModelCode());//物料编码
            map.put("boxCode",warehouseOutputBillDetailBo.getTraceid());//箱码
            map.put("suttle",String.valueOf(sum));//净重
            map.put("SAPBatchNo",warehouseOutputBillDetailBo.getCrystalNo());//SAP批次号
            keyValues.add(map);
        }
        preview = this.doPrint(docketPrintDto.getPrintModel(), keyValues, docketPrintDto.getIsPreview());
        return preview;
    }

    private List<String> printFBLabel(DocketPrintDto docketPrintDto) {
        List<String> preview;
        List<Map<String, String>> keyValues = new LinkedList<>();
        String code = docketPrintDto.getCode();
        Result<FbCheckOutData> result = fbFeignClients.findFbCheckOutDataByFbSectionNo(code);
        if (!result.getCode().equals(ResultCode.SUCCESS.getCode())) {
            throw new RuntimeException("查询方棒检验信息异常");
        }
        FbCheckOutData fbCheckOutData = result.getData();
        if (null == fbCheckOutData) {
            throw new RuntimeException("无方棒检验信息");
        }
        String key = "";
        String fromMark = docketPrintDto.getCode().substring(SectionIndexRangeEnum.基地追溯产品类型.getBeginIndex(), SectionIndexRangeEnum.基地追溯产品类型.getEndIndex());
        if (fromMark.matches("[A-Z]+")) {
            key = docketPrintDto.getCode().substring(SectionIndexRangeEnum.产品类型.getBeginIndex(), SectionIndexRangeEnum.产品类型.getEndIndex());
        } else {
            key = docketPrintDto.getCode().substring(1, 2);
        }
        String dopant = fbCheckOutData.getDopant();
        String spec = fbCheckOutData.getSpecification();
        DictionaryItem item = dictionaryItemService.findByThemeValueAndValueAndEnable("product_category", key, true);
        DictionaryItem item1 = dictionaryItemService.findByThemeValueAndNameAndEnable("ybProductSpec", spec, true);
        DictionaryItem item2 = dictionaryItemService.findByThemeValueAndNameAndEnable("dopant", dopant, true);
        String remark;
        if (null != item && null != item1 && null != item2) {
            remark = key + "-" + item.getName() + "/" + item1.getExtendValue() + "-" + spec + "/" + dopant + "-" + item2.getExtendValue();
        } else {
            throw new RuntimeException("未配置掺杂剂或尺寸的值");
        }
        String length = String.valueOf(fbCheckOutData.getLength().intValue());
        Map<String, String> map = new HashMap<>();
        map.put("length", length);
        map.put("code", docketPrintDto.getCode());
        map.put("remark", remark);
        //边距
        String sideLengthRange = "";
        sideLengthRange = fbCheckOutData.getSideLengthRange();
        //边宽
        String multipleSideLogic = getMultipleSideLogic(sideLengthRange);
        map.put("multipleSideLogic", multipleSideLogic);

        keyValues.add(map);
        preview = this.doPrint(docketPrintDto.getPrintModel(), keyValues, docketPrintDto.getIsPreview());
        return preview;
    }

    private List<String> printYBLabel(DocketPrintDto docketPrintDto) {
        List<String> preview;
        List<Map<String, String>> keyValues = new LinkedList<>();
        ProductionPaintingLineDetail productionPaintingLineDetail = productionPaintingLineDetailService.findBySegmentNo(docketPrintDto.getCode());
        if (null == productionPaintingLineDetail) {
            throw new RuntimeException("画线详情信息不存在");
        }
        Long longCrystalId = productionPaintingLineDetail.getCrystalId();
        LongCrystal longCrystal = longCrystalService.get(longCrystalId);
        if (longCrystal == null) {
            throw new RuntimeException("长棒信息不存在");
        }
        String key = "";
        String fromMark = docketPrintDto.getCode().substring(SectionIndexRangeEnum.基地追溯产品类型.getBeginIndex(), SectionIndexRangeEnum.基地追溯产品类型.getEndIndex());
        if (fromMark.matches("[A-Z]+")) {
            key = docketPrintDto.getCode().substring(SectionIndexRangeEnum.产品类型.getBeginIndex(), SectionIndexRangeEnum.产品类型.getEndIndex());
        } else {
            key = docketPrintDto.getCode().substring(1, 2);
        }
        String dopant = longCrystal.getDopant();
        String spec = longCrystal.getSpecs();
        DictionaryItem item = dictionaryItemService.findByThemeValueAndValueAndEnable("product_category", key, true);
        DictionaryItem item1 = dictionaryItemService.findByThemeValueAndNameAndEnable("ybProductSpec", spec, true);
        DictionaryItem item2 = dictionaryItemService.findByThemeValueAndNameAndEnable("dopant", dopant, true);
        String remark;
        if (null != item && null != item1 && null != item2) {
            remark = key + "-" + item.getName() + "/" + item1.getExtendValue() + "-" + spec + "/" + dopant + "-" + item2.getExtendValue();
        } else {
            throw new RuntimeException("未配置掺杂剂或尺寸的值");
        }
        String length = String.valueOf(productionPaintingLineDetail.getLength().intValue());
        Map<String, String> map = new HashMap<>();
        map.put("length", length);
        map.put("code", docketPrintDto.getCode());
        map.put("remark", remark);
        keyValues.add(map);
        preview = this.doPrint(docketPrintDto.getPrintModel(), keyValues, docketPrintDto.getIsPreview());
        return preview;
    }

    private List<String> printHotSpotCode(DocketPrintDto docketPrintDto) {
        List<String> preview = new ArrayList<>();
        List<Map<String, String>> keyValues = new LinkedList<>();
        String code = docketPrintDto.getCode();
        Result<List<StoreInputApplyCodeDto>> result = storeFeignClients.findStoreInventoryDetailByBatchNo(code);
        if (!result.getCode().equals(ResultCode.SUCCESS.getCode())) {
            throw new BusinessException(result.getMessage());
        }
        List<StoreInputApplyCodeDto> storeInputApplyCodeDtos = result.getData();
        if (storeInputApplyCodeDtos == null || storeInputApplyCodeDtos.size() <= 0) {
            throw new BusinessException("该条码无关联信息");
        }
        for (StoreInputApplyCodeDto storeInputApplyCodeDto : storeInputApplyCodeDtos) {
            Map map = new HashMap();
            map.put("code", storeInputApplyCodeDto.getUniqueCode());
            map.put("materialName", storeInputApplyCodeDto.getMaterialModelName());
            map.put("batchNo", storeInputApplyCodeDto.getBatchNo());
            keyValues.add(map);
        }
        preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), keyValues, docketPrintDto.getIsPreview()));
        return preview;
    }

    /**
     * 合格证标签打印查询
     *
     * @param docketPrintDto
     * @return
     */
    @Override
    public DocketPrintResultDto certificateLabelFind(DocketPrintDto docketPrintDto) {
        DocketPrintResultDto docketPrintResultDto = new DocketPrintResultDto();
        List<String> successfulCodeList = new ArrayList<>();
        List<DocketPrintFailedDetail> failedDetailList = new ArrayList<>();

        //1.校验
        String code = docketPrintDto.getCode();//单晶编号
        String printType = docketPrintDto.getPrintType();//打印类型：合格证标签
        DocketPrintFailedDetail printFailedDetail = new DocketPrintFailedDetail();
        //验证编号和模板是否符合（根据加工工单类型判断，PlanProcessingOrder：加工工单）
        List<PlanProcessingOrder> planProcessingOrderList = planProcessingOrderService.findByCodeOrderByIdDesc(code);
        if (planProcessingOrderList.size() > 0) {
            PlanProcessingOrder planProcessingOrder = planProcessingOrderList.get(0);
            if (printType.equals(EnumDocketPrint.PrintModelType.长晶棒头划线.getValue())) {
                //长晶棒头划线传入的为长棒
                if (!planProcessingOrder.getOrderType().equals(EnumValuesFactory.PlanProcessingOrderOrderType.单晶.getKey())) {
                    //编码和模板不符
                    printFailedDetail.setDescription("编码和模板不符");
                    printFailedDetail.setCode(docketPrintDto.getCode());
                    failedDetailList.add(printFailedDetail);
                    throw new BusinessException("编码和模板不符");
                }
            } else {
                //其它类型模板传入的为短棒
                if (!planProcessingOrder.getOrderType().equals(EnumValuesFactory.PlanProcessingOrderOrderType.晶段.getKey())) {
                    //编码和模板不符
                    printFailedDetail.setCode(docketPrintDto.getCode());
                    printFailedDetail.setDescription("编码和模板不符");
                    failedDetailList.add(printFailedDetail);
                    throw new BusinessException("编码和模板不符");
                }
            }
        }


        //2.查询数据
        EnumDocketPrint.PrintModelType printModelType = EnumDocketPrint.PrintModelType.getEnum(printType);
        if (printModelType == null) {
            throw new BusinessException("类型为空");
        }
        //查询打印模板
        DocumentPrint documentPrint = documentMouldService.findByDocumentMould(docketPrintDto.getPrintModel());
        if (documentPrint == null) {
            throw new RuntimeException("模板【" + printModelType + "】不存在");
        }
        //查询圆棒检验信息
        YbInspectData inspectDataBase = inspectDataBaseService.findBySectionNo(code);
        if (inspectDataBase == null) {
            throw new RuntimeException("检验数据不存在");
        }

        try {
            //组装数据
            BigDecimal twRadialEdgeAvgt = null;
            CertificateLabelDto certificateLabelDto = new CertificateLabelDto();
            BeanUtil.copyBeanPropWithNumberHandler(certificateLabelDto, inspectDataBase);

            if (inspectDataBase.getTRadialEdge1() != null && inspectDataBase.getWRadialEdge1() != null) {
                BigDecimal tRadialEdge1 = inspectDataBase.getTRadialEdge1();
                BigDecimal wRadialEdge1 = inspectDataBase.getWRadialEdge1();
                twRadialEdgeAvgt = tRadialEdge1.add(wRadialEdge1).divide(new BigDecimal(2));
            }
            BigDecimal diameterMin = inspectDataBase.getDiameterMin();
            BigDecimal diameterMax = inspectDataBase.getDiameterMax();
            certificateLabelDto.setTwRadialEdgeAvg(twRadialEdgeAvgt == null ? "" : df.format(twRadialEdgeAvgt));
            certificateLabelDto.setDiameterMinMax((new BigDecimal(df.format(diameterMin)).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(diameterMin)) + "-" + (new BigDecimal(df.format(diameterMax)).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(diameterMax)));
            List<String> previewList = new ArrayList<>();
            List dataList = new ArrayList();
            dataList.add(certificateLabelDto);

            //数据渲染模板
            if (docketPrintDto.getIsPreview()) {
                PrintInfoDto printInfoDto = new PrintInfoDto();
                printInfoDto.setPrinterName(documentPrint.getPrintName());
                printInfoDto.setDocIp("10.221.236.54");
                printInfoDto.setTemplateAddress(documentPrint.getDocumentPath());
                printInfoDto.setData(JSON.toJSONString(dataList));

                Result<String> result = printService.printShow(printInfoDto);
                if (result.getCode() == ResultCode.SUCCESS.getCode()) {
                    previewList.add(result.getData());
                }
            }

            successfulCodeList.add(docketPrintDto.getCode());
            docketPrintResultDto.setDocketPrintFailedDetailList(failedDetailList);
            docketPrintResultDto.setSuccessfulCodeList(successfulCodeList);
            docketPrintResultDto.setPreviewList(previewList);
        } catch (Exception e) {
            log.error("组装合格证标签数据异常：" + e.getMessage());
            throw new RuntimeException("组装合格证标签数据异常");
        }
        return docketPrintResultDto;
    }

    @Override
    public List<String> printLoadingRecipe(DocketPrintLoadingRecipeDto dto) {
        //预览结果
        List<String> preview;
        List<LoadingTaskRecipeDto> dtos = dto.getDtos();
        if (dtos == null || dtos.size() <= 0) {
            throw new RuntimeException("无数据");
        }
        if (null == dto.getPrintModel()) {
            dto.setPrintModel("配料方案");
        }
        if (null == dto.getPrintType()) {
            dto.setPrintType("晶科配料方案");
        }
        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        //重置
        reset(map);
        List<LoadingTaskRecipeDto> dtos1 = new ArrayList<>();
        for (LoadingTaskRecipeDto entity : dtos) {
            if (entity.getSuppliesType().contains("合金")) {
                String alloy = entity.getSuppliesType();
                String alloyWeight = entity.getWeight().toString();
                map.put("alloy", alloy + ":" + alloyWeight);
            } else {
                dtos1.add(entity);
            }
        }
        Long loadingTaskId = dtos1.get(0).getLoadingTaskId();
        if (null == loadingTaskId) {
            throw new RuntimeException("无配料任务id");
        }
        dto.setPrintNum(1);
        LoadingTask task = loadingTaskService.get(loadingTaskId);
        if (task == null) {
            throw new RuntimeException("无配料任务");
        }
        String equipmentCode = task.getEquipmentCode();
        String team = BaseContextHandler.getUserTeamGroup();
        String syggHeight = dto.getSyggHeight();
        task.setCrucibleHeight(syggHeight);
        loadingTaskService.saveOrUpdate(task);
        String equipmentSize = "";
        if (syggHeight != null) {
            if (syggHeight.contains("-")) {
                String[] arr = syggHeight.split("-");
                equipmentSize = arr[0];
            }
        }
        int i = 1;
        BigDecimal weight = BigDecimal.ZERO;
        for (LoadingTaskRecipeDto entity : dtos1) {
            String name = entity.getSuppliesType();
            weight = weight.add(entity.getWeight());
            String weight1 = entity.getWeight().toString();
            map.put("material" + i, name + ":" + weight1);
            i++;
        }
        String firstRow = equipmentCode + " " + equipmentSize + " " + team + " " + "初始装料" + weight;
        map.put("firstRow", firstRow);
        list.add(map);
        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }

    private void reset(Map<String, String> map) {
        map.put("alloy", " ");
        map.put("firstRow", " ");
        for (int i = 1; i <= 8; i++) {
            map.put("material" + i, " ");
        }
    }

    @Override
    public List<String> printFillingRecipe(DocketPrintFillingRecipeDto dto) {
        //预览结果
        List<String> preview;
        List<FillingTaskRecipeDto> dtos = dto.getDtos();
        if (dtos == null || dtos.size() <= 0) {
            throw new RuntimeException("无数据");
        }
        if (null == dto.getPrintModel()) {
            dto.setPrintModel("配料方案");
        }
        if (null == dto.getPrintType()) {
            dto.setPrintType("晶科配料方案");
        }
        dto.setPrintNum(1);
        List<FillingTaskRecipeDto> dtos1 = new ArrayList<>();
        List<Map> list = new ArrayList<>();
        //Map<String, String> map = new HashMap<>();
        String alloy = null;
        String alloyWeight = null;
        for (FillingTaskRecipeDto entity : dtos) {
            if (entity.getSuppliesType().contains("合金")) {
                alloy = entity.getSuppliesType();
                alloyWeight = entity.getWeight().toString();
                //map.put("alloy",alloy+":"+alloyWeight+"g");
            } else {
                dtos1.add(entity);
            }
        }
        Long againTaskDetailId = dtos1.get(0).getAgainTaskDetailId();
        if (null == againTaskDetailId) {
            throw new RuntimeException("无配料任务id");
        }
        AgainTaskDetail task = againTaskDetailService.get(againTaskDetailId);
        if (task == null) {
            throw new RuntimeException("无罐料任务");
        }
        String equipmentCode = task.getEquipmentCode();
        String team = BaseContextHandler.getUserTeamGroup();
        String lotNo = task.getLotNo();
        List<LoadingTask> loadingTasks = loadingTaskService.findByLotNo(lotNo);
        String equipmentSize = "";
        if (loadingTasks != null && loadingTasks.size() > 0) {
            String syggHeight = loadingTasks.get(0).getCrucibleHeight();
            if (null != syggHeight) {
                //坩埚尺寸没有
                if (syggHeight.contains("-")) {
                    String[] arr = syggHeight.split("-");
                    equipmentSize = arr[0];
                }
            }
        }
        //根据桶数分组
        Map<Integer, List<FillingTaskRecipeDto>> stringListMap = dtos1.stream().collect(Collectors.groupingBy(entity -> entity.getBucketNum()));
        Set set = stringListMap.keySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            String info = "";
            Map<String, String> map = new HashMap<>();
            reset(map);
            Integer key = Integer.valueOf(iterator.next().toString());
            List<FillingTaskRecipeDto> fillingTaskRecipeDtos = stringListMap.get(key);
            info = info + "第" + key.toString() + "桶:" + fillingTaskRecipeDtos.get(0).getGross() + " ";
            int k = 1;
            for (FillingTaskRecipeDto entity : fillingTaskRecipeDtos) {
                String name = entity.getSuppliesType();
                String weight1 = entity.getWeight().toString();
                map.put("material" + k, name + ":" + weight1);
                k++;
            }
            //map.put("bucket"+k,key.toString());
            //k++;
            String firstRow = equipmentCode + " " + equipmentSize + " " + team + info;
            map.put("firstRow", firstRow);
            list.add(map);
        }
        if (list.size() > 0 && StringUtils.isNotEmpty(alloyWeight)) {
            for (int i = 0; i < list.size(); i++) {
                if (i == 0) {
                    list.get(i).put("alloy", alloy + ":" + alloyWeight);
                } else {
                    list.get(i).put("alloy", " ");
                }
            }

        }
        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }

    @Override
    public List printCleanBox(DocketPrintCleanBoxDto dto) {
        //预览结果
        List<String> preview;
        List<MaterialBrokenDownBoxDto> brokenDownDtos = dto.getDto();
        if (null == dto.getPrintModel()) {
            dto.setPrintModel("成品标签");
        }
        if (null == dto.getPrintType()) {
            dto.setPrintType("成品标签");
        }
        dto.setPrintNum(1);
        if (null == dto.getIsPreview()) {
            dto.setIsPreview(true);
        }
        //封装打印数据
        ArrayList<String> previewList = new ArrayList<>();
        List<Map<String, String>> keyvaluess = new LinkedList<>();
        for (MaterialBrokenDownBoxDto brokenDownDto : brokenDownDtos
        ) {
            //List<Map<String, String>> list = new LinkedList<>();
            Map<String, String> map = new HashMap<>();
            map.put("materialBoxNo", brokenDownDto.getMaterialBoxNo());
            map.put("productBatchNo", brokenDownDto.getProductBatchNo());
            map.put("materialCode", brokenDownDto.getMaterialCode());
            map.put("materialName", brokenDownDto.getMaterialName());
            map.put("materialLevel", brokenDownDto.getMaterialLevel());
            map.put("materialGear", brokenDownDto.getMaterialGear());
            map.put("downUser", brokenDownDto.getDownUser());
            map.put("downTime", new SimpleDateFormat("yyyy-MM-dd").format(brokenDownDto.getDownTime()));
            map.put("weight", String.valueOf(brokenDownDto.getWeight()));
            map.put("remark", null == brokenDownDto.getRemark() ? "" : brokenDownDto.getRemark());
            //list.add(map);
            keyvaluess.add(map);
            //previewList.add(preview.get(0));
        }
        previewList.addAll(this.doPrint(dto.getPrintModel(), keyvaluess, dto.getIsPreview(), dto.getPrintNum()));
        return previewList;
    }

    @Override
    public List printPaintLabel(PrintPaintLabelDto dto) {
        //预览结果
        List<String> preview;
        DrawLineDto drawLineDto = dto.getDto();
        if (null == dto.getPrintModel()) {
            dto.setPrintModel("晶棒划线标签");
        }
        if (null == dto.getPrintType()) {
            dto.setPrintType("晶棒划线标签");
        }
        dto.setPrintNum(dto.getPrintNum());
        if (null == dto.getIsPreview()) {
            dto.setIsPreview(true);
        }
        //封装打印数据
        ArrayList<String> previewList = new ArrayList<>();
        List<DrawLineDetailDto> lineDetailedDtos = drawLineDto.getLineDetailedDtos();
        List<Map> list = new ArrayList<>();
        LongCrystal longCrystal = longCrystalService.findByCrystalNo(drawLineDto.getCrystalNo());
        if (longCrystal == null) {
            throw new RuntimeException("长棒信息不存在");
        }
        String key = "";
        String fromMark = drawLineDto.getCrystalNo().substring(SectionIndexRangeEnum.基地追溯产品类型.getBeginIndex(), SectionIndexRangeEnum.基地追溯产品类型.getEndIndex());
        if (fromMark.matches("[A-Z]+")) {
            key = drawLineDto.getCrystalNo().substring(SectionIndexRangeEnum.产品类型.getBeginIndex(), SectionIndexRangeEnum.产品类型.getEndIndex());
        } else {
            key = drawLineDto.getCrystalNo().substring(1, 2);
        }
        String dopant = longCrystal.getDopant();
        String spec = longCrystal.getSpecs();
        DictionaryItem item = dictionaryItemService.findByThemeValueAndValueAndEnable("product_category", key, true);
        DictionaryItem item1 = dictionaryItemService.findByThemeValueAndNameAndEnable("ybProductSpec", spec, true);
        DictionaryItem item2 = dictionaryItemService.findByThemeValueAndNameAndEnable("dopant", dopant, true);
        String remark = "";
        if (null != item && null != item1 && null != item2) {
            remark = key + "-" + item.getName() + "/" + item1.getExtendValue() + "-" + spec + "/" + dopant + "-" + item2.getExtendValue();
        } else {
//            throw new RuntimeException("未配置掺杂剂或尺寸的值");
        }
        for (DrawLineDetailDto lineDetailedDto : lineDetailedDtos) {
            Map<String, String> map = new HashMap<>();
            map.put("code", lineDetailedDto.getSegmentNo());
            map.put("length", String.valueOf(lineDetailedDto.getLength()));
            map.put("remark", remark);
            list.add(map);
//            preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
//            previewList.add(preview.get(0));
        }
        Map<String, String> map = new HashMap<>();
        map.put("code", drawLineDto.getCrystalNo());
        map.put("length", String.valueOf(drawLineDto.getLength()));
        map.put("remark", remark);
        list.add(map);
        Map<String, String> tmap = new HashMap<>();
        tmap.put("code", drawLineDto.getCrystalNo() + "T");
        tmap.put("length", "");
        tmap.put("remark", remark);
        list.add(tmap);
        Map<String, String> wmap = new HashMap<>();
        wmap.put("code", drawLineDto.getCrystalNo() + "W");
        wmap.put("length", "");
        wmap.put("remark", remark);
        list.add(wmap);
        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        previewList.addAll(preview);
        return previewList;
    }

    @Override
    public List<String> printCleanGroup(DocketPrintCleanGroupDto dto) {
        //预览结果
        List<String> preview;
        MaterialGroupInfoDto materialGroupDto = dto.getDto();
        if (null == dto.getPrintModel()) {
            dto.setPrintModel("成品托标");
        }
        if (null == dto.getPrintType()) {
            dto.setPrintType("成品托标");
        }
        dto.setPrintNum(1);
        if (null == dto.getIsPreview()) {
            dto.setIsPreview(true);
        }
        //封装打印数据
        //字段需要与物料主数据对齐
        List<MaterialModel> materialModelList = materialModelService.findMaterialModelByCode(materialGroupDto.getMaterialCode());
        if (null == materialModelList || materialModelList.size() == 0) {
            throw new BusinessException("该料号不存在，请检查");
        }
        MaterialModel materialModel = materialModelList.get(0);

        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("directionalSign", materialModel.getDirectionalSign());
        map.put("groupNo", materialGroupDto.getGroupNo());
        map.put("productBatchNo", materialGroupDto.getProductBatchNo());
        map.put("materialCode", materialGroupDto.getMaterialCode());
        map.put("materialName", materialGroupDto.getMaterialName());
        map.put("materialLevel", materialModel.getProductLevel());
        map.put("weight", String.valueOf(materialGroupDto.getWeight()));
        map.put("specification", materialModel.getSpecification());
        map.put("suppliesGrain", materialGroupDto.getSuppliesGrain());
        map.put("materialGear", materialGroupDto.getMaterialGear());
        map.put("classNo", BaseContextHandler.getUserClassNo());
        map.put("use", "");
        map.put("createTime", new SimpleDateFormat("yyyy-MM-dd").format(materialGroupDto.getCreateTime()));
        map.put("factory", "山西太原");
        map.put("remark", null == materialGroupDto.getRemark() ? "" : materialGroupDto.getRemark());
        list.add(map);

        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }

    @Override
    public List<String> printReWorking(DocketPrintReWorkingDto dto) {

        //预览结果
        List<String> preview;
        ReworkingDto dto1 = dto.getDto();
        if (null == dto.getPrintModel()) {
            dto.setPrintModel("返工打签");
        }
        if (null == dto.getPrintType()) {
            dto.setPrintType("返工打签");
        }
        dto.setPrintNum(1);
        if (null == dto.getIsPreview()) {
            dto.setIsPreview(false);
        }
        //封装打印数据
        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("boxNo", dto1.getBoxNo());
        map.put("note", dto1.getNote());
        map.put("materialName", dto1.getMaterialName());
        map.put("reWorkWeight", dto1.getReWorkWeight());
        map.put("materialGear", dto1.getMaterialGear());
        map.put("materialLevel", dto1.getMaterialLevel());
        map.put("factory", dto1.getFactory());
        map.put("date", dto1.getDate());
        map.put("materialModel", dto1.getMaterialModel());
        map.put("source", dto1.getSource());
        list.add(map);

        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }


    @Override
    public List<String> printRecycledGroup(DocketPrintRecycledGroupDto dto) {
        //预览结果
        List<String> preview;
        RecycledGroupInfoDto materialGroupDto = dto.getDto();
        if (null == dto.getPrintModel()) {
            dto.setPrintModel("回收料余料托标");
        }
        if (null == dto.getPrintType()) {
            dto.setPrintType("回收料余料托标");
        }
        dto.setPrintNum(1);
        if (null == dto.getIsPreview()) {
            dto.setIsPreview(true);
        }
        //封装打印数据
        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("boxNo", materialGroupDto.getBoxNo());
        map.put("fromMark", materialGroupDto.getFromMark());
        map.put("materialName", materialGroupDto.getMaterialName());
        map.put("materialLevel", materialGroupDto.getMaterialLevel());
        map.put("materialGear", materialGroupDto.getMaterialGear());
        map.put("createUser", materialGroupDto.getCreateUser());
        map.put("createTime", new SimpleDateFormat("yyyy-MM-dd").format(materialGroupDto.getCreateTime()));
        map.put("weight", String.valueOf(materialGroupDto.getWeight()));
        map.put("remark", null == materialGroupDto.getRemark() ? "" : materialGroupDto.getRemark());
        list.add(map);

        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }

    @Override
    public List<String> printBoxNo(DocketPrintBoxNoDto dto) {
        //预览结果
        List<String> preview;
        BoxNoDto boxNoDto = dto.getDto();
        if (null == dto.getPrintModel()) {
            dto.setPrintModel("载具箱标签");
        }
        if (null == dto.getPrintType()) {
            dto.setPrintType("载具箱标签");
        }
        dto.setPrintNum(1);
        if (null == dto.getIsPreview()) {
            dto.setIsPreview(false);
        }
        //封装打印数据
        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("boxNo", boxNoDto.getBoxNo());
        map.put("typeName", boxNoDto.getTypeName());
        map.put("weight", String.valueOf(boxNoDto.getWeight()));
        list.add(map);

        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }

    @Override
    public List<String> printCleanFxToBox(DocketPrintCleanFxToBoxDto dto) {
        //预览结果
        List<String> preview;
        FxToBoxInfoDto boxInfoDto = dto.getDto();
        if (null == dto.getPrintModel()) {
            dto.setPrintModel("分选打印");
        }
        if (null == dto.getPrintType()) {
            dto.setPrintType("分选打印");
        }
        dto.setPrintNum(1);
        if (null == dto.getIsPreview()) {
            dto.setIsPreview(false);
        }
        //封装打印数据
        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("boxNo", boxInfoDto.getBoxNo());
        map.put("fxProductBatchNo", boxInfoDto.getFxProductBatchNo());
        map.put("productBatchNo", boxInfoDto.getProductBatchNo());
        map.put("fromMark", boxInfoDto.getFromMark());
        map.put("materialName", boxInfoDto.getMaterialName());
        map.put("materialCode", boxInfoDto.getMaterialCode());
        map.put("createTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(boxInfoDto.getCreateTime()));
        map.put("weight", String.valueOf(boxInfoDto.getWeight()));
        map.put("materialModel", boxInfoDto.getMaterialModel());
        map.put("materialGear", boxInfoDto.getMaterialGear());
        map.put("materialLevel", boxInfoDto.getMaterialLevel());
//        map.put("sourceProcess", boxInfoDto.getSourceProcess());
//        map.put("createUser", boxInfoDto.getCreateUser());
        map.put("remark", null == boxInfoDto.getRemark() ? "" : boxInfoDto.getRemark());
        map.put("classNo", BaseContextHandler.getUserClassNo());
        list.add(map);

        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }

    /**
     * 打印毛棒信息条码
     *
     * @param dto
     * @return
     */
    @Override
    public List<String> printBristleMaterial(DocketSeedCodePrintDto dto) {
        //预览打印结果
        List<String> preview;
        List<Map<String, String>> seedList = new ArrayList<>();
        Map<String, String> seedMap = new HashMap<>();
        seedMap.put("seedCode", dto.getSeedCode());
        seedList.add(seedMap);
        preview = this.doPrint(dto.getPrintModel(), seedList, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }

    @Override
    public List<String> printMasterAlloy(DocketMasterAlloyPrintDto dto) {
        List<String> preview;
        //封装打印数据
        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("workOrder", null == dto.getWorkOrderNumber() ? "" : dto.getWorkOrderNumber());
        map.put("furnaceCode", dto.getFurnaceCode());
        map.put("addTime", dto.getAddTime());
        map.put("recipeName", null == dto.getRecipeName() ? "" : dto.getRecipeName());
        map.put("createUser", BaseContextHandler.getUsername());
        map.put("motherAlloyGear", dto.getMotherAlloyGear().toString());
        map.put("motherAlloyWeight", dto.getMotherAlloyWeight().toString());
        map.put("date", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        long timestamp = System.currentTimeMillis();
        String timeLength = String.valueOf(timestamp);
        map.put("motherAlloyCode", dto.getWorkOrderNumber() + dto.getFurnaceCode() + dto.getAddTime() + timeLength.substring(timeLength.length() - 4));
        list.add(map);
        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }


    @Override
    public List<String> printIngredientList(DocketIngredientListPrintDto dto) {
        List<String> preview = null;
        if (dto.getIngredientOrFillingMaterial() == 0) {
//            打印配料任务
            LoadingTask loadingTask = loadingTaskService.get(dto.getId());
            Assert.notNull(loadingTask, "配料任务不存在");
            List<BlastFurnaceDetail> blastFurnaceDetailList = blastFurnaceDetailService.getBlastFurnaceDetailList(loadingTask.getId());
            IngredientInfoDto ingredientInfoDto = buildLoadingTaskIngredientInfoDto(loadingTask, blastFurnaceDetailList);
//            封装打印数据
            ArrayList<Map> list = new ArrayList<>();
            HashMap<String, String> map = new HashMap<>();
            map.put("furnaceCode", ingredientInfoDto.getFurnaceCode());
            map.put("againNum", ingredientInfoDto.getAgainNum().toString());
            map.put("carrierNo", ingredientInfoDto.getCarrierNo());
            map.put("barrelNumber", ingredientInfoDto.getBarrelNumber());
            map.put("totalWeight", ingredientInfoDto.getTotalWeight().toString());
            int b = 3;
            for (int i = 0; i < ingredientInfoDto.getMaterialInfoDtoList().size(); i++) {
                MaterialInfoDto materialInfoDto = ingredientInfoDto.getMaterialInfoDtoList().get(i);
                map.put("materialName" + i, materialInfoDto.getMaterialName());
                map.put("materialCode" + i, materialInfoDto.getMaterialCode());
                map.put("supplier" + i, materialInfoDto.getSupplier());
                map.put("batchNumber" + i, materialInfoDto.getBatchNumber());
                map.put("weight" + i, materialInfoDto.getWeight().toString());
                if (b == i) {
                    break;
                }
            }
            list.add(map);
            preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        } else {
            // 打印灌料任务
            AgainTaskDetail againTaskDetailDb = againTaskDetailService.get(dto.getId());
            Assert.notNull(againTaskDetailDb, "灌料任务不存在");
            IngredientInfoDto ingredientInfoDto = buildAgainTaskTaskIngredientInfoDto(againTaskDetailDb, dto);
            // 封装打印数据
            List<FeedInInfoDto> feedInInfoDtoList = ingredientInfoDto.getFeedInInfoDtoList();
            List<MaterialInfoDto> materialInfoDtoList = ingredientInfoDto.getMaterialInfoDtoList();
            Map<String, List<MaterialInfoDto>> listMap = materialInfoDtoList.stream()
                    .collect(Collectors.groupingBy(MaterialInfoDto::getBarrelNumber));
            for (FeedInInfoDto feedInInfoDto : feedInInfoDtoList) {
                ArrayList<Map> list = new ArrayList<>();
                HashMap<String, String> map = new HashMap<>();
                map.put("furnaceCode", ingredientInfoDto.getFurnaceCode());
                map.put("againNum", ingredientInfoDto.getAgainNum().toString());
                map.put("carrierNo", ingredientInfoDto.getCarrierNo());
                map.put("barrelNumber", feedInInfoDto.getBarrelNumber());
                map.put("totalWeight", feedInInfoDto.getTotalWeight().toString());
                List<MaterialInfoDto> materialInfoDtos = listMap.get(feedInInfoDto.getBarrelNumber());
                if (!CollectionUtils.isEmpty(materialInfoDtos)) {
                    int b = 3;
                    for (int i = 0; i < materialInfoDtos.size(); i++) {
                        MaterialInfoDto materialInfoDto = materialInfoDtos.get(i);
                        map.put("materialName" + i, materialInfoDto.getMaterialName());
                        map.put("materialCode" + i, materialInfoDto.getMaterialCode());
                        map.put("supplier" + i, materialInfoDto.getSupplier());
                        map.put("batchNumber" + i, materialInfoDto.getBatchNumber());
                        map.put("weight" + i, materialInfoDto.getWeight().toString());
                        if (b == i) {
                            break;
                        }
                    }
                }
                list.add(map);
                preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
            }

        }
        return preview;
    }

    /**
     * 构建灌料任务信息
     */
    private IngredientInfoDto buildAgainTaskTaskIngredientInfoDto(AgainTaskDetail againTaskDetailDb, DocketIngredientListPrintDto dto) {
//        物料详情
        ArrayList<MaterialInfoDto> materialInfoDtoArrayList = new ArrayList<>();
//        加料信息详情
        ArrayList<FeedInInfoDto> feedInInfoDtoArrayList = new ArrayList<>();
//        创建配料单对象
        IngredientInfoDto ingredientInfoDto = new IngredientInfoDto();
        ingredientInfoDto.setFurnaceCode(againTaskDetailDb.getEquipmentCode());
        ingredientInfoDto.setAgainNum(againTaskDetailDb.getAgainNum());
        ingredientInfoDto.setCarrierNo(againTaskDetailDb.getCarrierNo());

        InputFurnaceBurden burden = inputFurnaceBurdenService.findTopByAgainTaskDetailId(againTaskDetailDb.getId());
        Assert.notNull(againTaskDetailDb, "灌料记录不存在");

//        查询灌料明细
        List<InputFurnaceDetail> inputFurnaceDetailList = null;
        if (ObjectUtils.isEmpty(dto.getBucket()) || dto.getBucket() == 3){
            inputFurnaceDetailList = inputFurnaceDetailService.findByAgainTaskDetailId(againTaskDetailDb.getId());
        }else if (1 == dto.getBucket()){
            inputFurnaceDetailList = inputFurnaceDetailService.findByAgainTaskDetailIdAndBucket(againTaskDetailDb.getId(), burden.getLeftCode());
        }else if (2 == dto.getBucket()){
            inputFurnaceDetailList = inputFurnaceDetailService.findByAgainTaskDetailIdAndBucket(againTaskDetailDb.getId(), burden.getRightCode());
        }else {
            inputFurnaceDetailList = inputFurnaceDetailService.findByAgainTaskDetailId(againTaskDetailDb.getId());
        }
        if (!CollectionUtils.isEmpty(inputFurnaceDetailList)) {
//            根据桶号进行分组
            Map<String, List<InputFurnaceDetail>> listMap = inputFurnaceDetailList.stream()
                    .collect(Collectors.groupingBy(InputFurnaceDetail::getBucketNo));
            for (InputFurnaceDetail inputFurnaceDetail : inputFurnaceDetailList) {
                FeedInInfoDto feedInInfoDto = new FeedInInfoDto();
                List<InputFurnaceDetail> inputFurnaceDetailList1 = listMap.get(inputFurnaceDetail.getBucketNo());
                if (!CollectionUtils.isEmpty(inputFurnaceDetailList1)) {
                    Integer barrelCount = 0;
                    barrelCount++;
                    feedInInfoDto.setBarrelCount(barrelCount);
//                    加料重量
                    BigDecimal totalWeight = inputFurnaceDetailList1.stream()
                            .map(InputFurnaceDetail::getWeight)
                            .reduce(BigDecimal.ZERO, BigDecimal::add);
                    feedInInfoDto.setTotalWeight(totalWeight);
                    for (InputFurnaceDetail furnaceDetail : inputFurnaceDetailList1) {
                        MaterialInfoDto materialInfoDto = new MaterialInfoDto();
                        FormulaSchemeDetail schemeDetail = formulaSchemeDetailService.findByTaskAndMaterialCode(
                                againTaskDetailDb.getAgainTaskId(), againTaskDetailDb.getAgainNum(), furnaceDetail.getMaterialCode());
                        if (!ObjectUtils.isEmpty(schemeDetail)){
                            materialInfoDto.setMaterialName(schemeDetail.getMaterialClassName());
                        }
                        /*FormulaMaterialClass formulaMaterialClass = formulaMaterialClassService.findFormulaMaterialClassByMaterialCode(furnaceDetail.getMaterialCode());
                        if (Objects.nonNull(formulaMaterialClass)) {
                            materialInfoDto.setMaterialName(formulaMaterialClass.getName());
                        }*/
                        materialInfoDto.setMaterialCode(furnaceDetail.getMaterialCode());
                        materialInfoDto.setSupplier(furnaceDetail.getSupplierName());
                        materialInfoDto.setBatchNumber(furnaceDetail.getBatchNo());
                        materialInfoDto.setWeight(furnaceDetail.getWeight());
                        materialInfoDto.setBarrelNumber(furnaceDetail.getBucketNo());
                        materialInfoDtoArrayList.add(materialInfoDto);
                        feedInInfoDto.setBarrelNumber(furnaceDetail.getBucketNo());
                    }
                }
                feedInInfoDtoArrayList.add(feedInInfoDto);
            }
            ingredientInfoDto.setMaterialInfoDtoList(materialInfoDtoArrayList);
            ingredientInfoDto.setFeedInInfoDtoList(feedInInfoDtoArrayList);
        }
        return ingredientInfoDto;
    }

    /**
     * 构建配料任务
     */
    private IngredientInfoDto buildLoadingTaskIngredientInfoDto(LoadingTask loadingTask, List<BlastFurnaceDetail> blastFurnaceDetailList) {
        ArrayList<MaterialInfoDto> materialInfoDtoArrayList = new ArrayList<>();
        IngredientInfoDto ingredientInfoDto = new IngredientInfoDto();
        ingredientInfoDto.setBarrelCount(0);
        ingredientInfoDto.setCarrierNo(loadingTask.getCarrierNo());
        ingredientInfoDto.setAgainNum(0);
        ingredientInfoDto.setFurnaceCode(loadingTask.getEquipmentCode());

        if (!CollectionUtils.isEmpty(blastFurnaceDetailList)) {
            List<BlastFurnaceDetail> list = blastFurnaceDetailList.stream()
                    .filter(item -> item.getMarkCrucible() == false)
                    .collect(Collectors.toList());
//            坩埚
            List<BlastFurnaceDetail> crucibleList = blastFurnaceDetailList.stream()
                    .filter(item -> item.getMarkCrucible() == true)
                    .collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(crucibleList)) {
                BlastFurnaceDetail blastFurnaceDetail = crucibleList.get(0);
                ingredientInfoDto.setBarrelNumber(blastFurnaceDetail.getMaterialCode());
            }
            if (!CollectionUtils.isEmpty(list)) {
                BigDecimal totalWeight = list.stream()
                        .map(BlastFurnaceDetail::getWeight)
                        .reduce(BigDecimal.ZERO, BigDecimal::add);
                ingredientInfoDto.setTotalWeight(totalWeight);
                list.forEach(item -> {
                    MaterialInfoDto materialInfoDto = new MaterialInfoDto();
                    FormulaSchemeDetail schemeDetail = formulaSchemeDetailService.findByTaskAndMaterialCode(loadingTask.getId(), 0, item.getMaterialCode());
                    if (!ObjectUtils.isEmpty(schemeDetail)){
                        materialInfoDto.setMaterialName(schemeDetail.getMaterialClassName());
                    }
                    /*FormulaMaterialClass formulaMaterialClass = formulaMaterialClassService.findFormulaMaterialClassByMaterialCode(item.getMaterialCode());
                    if (Objects.nonNull(formulaMaterialClass)) {
                        materialInfoDto.setMaterialName(formulaMaterialClass.getName());
                    }*/
                    materialInfoDto.setMaterialCode(item.getMaterialCode());
                    materialInfoDto.setSupplier(item.getSupplierName());
                    materialInfoDto.setBatchNumber(item.getBatchNo());
                    materialInfoDto.setWeight(item.getWeight());
                    materialInfoDtoArrayList.add(materialInfoDto);
                });
            }
        }
        ingredientInfoDto.setMaterialInfoDtoList(materialInfoDtoArrayList);
        return ingredientInfoDto;
    }

    /**
     * 打印圆棒信息条
     * 码
     *
     * @param dto
     * @return
     */
//    @Override
//    public List<String> printPoleMaterial(DocketPolePrintDto dto) {
//        //预览打印结果
//        List<String> preview;
//        PoleMaterialPrintDto poleDto = dto.getDto();
//        if(ObjectUtils.isEmpty(dto.getPrintModel())){
//            dto.setPrintModel("毛棒物料条码");
//        }
//        if(ObjectUtils.isEmpty(dto.getPrintType())){
//            dto.setPrintType("毛棒物料条码");
//        }
//        if(ObjectUtils.isEmpty(dto.getPrintNum())){
//            dto.setPrintNum(1);
//        }
//        if(ObjectUtils.isEmpty(dto.getIsPreview())){
//            dto.setIsPreview(false);
//        }
//        List<Map<String,String>> poleList = new ArrayList<>();
//        Map<String,String> poleMap = new HashMap<>();
//        poleMap.put("code",poleDto.getCode());
//        poleMap.put("length",poleDto.getLength());
//        poleList.add(poleMap);
//        preview = this.doPrint(dto.getPrintModel(), poleList, dto.getIsPreview(), dto.getPrintNum());
//        return preview;
//    }
    @Override
    public List<String> printCleanPackagingBox(DocketPrintCleanPackingBoxDto dto) {
        //预览结果
        List<String> preview;
        PackingBoxInfoDto boxInfoDto = dto.getDto();
        if (null == dto.getPrintModel()) {
            dto.setPrintModel("拆花篮成箱标签");
        }
        if (null == dto.getPrintType()) {
            dto.setPrintType("拆花篮成箱标签");
        }
        dto.setPrintNum(1);
        if (null == dto.getIsPreview()) {
            dto.setIsPreview(false);
        }
        //封装打印数据
        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("boxNo", boxInfoDto.getBoxNo());
        map.put("currentProductBatchNo", boxInfoDto.getCurrentProductBatchNo());
        map.put("createTime", new SimpleDateFormat("yyyy-MM-dd").format(boxInfoDto.getCreateTime()));
        map.put("deviceNo", boxInfoDto.getDeviceNo());
        map.put("fromMark", boxInfoDto.getFromMark());
        map.put("classNoName", boxInfoDto.getClassNoName());
        map.put("materialName", boxInfoDto.getMaterialName());
        map.put("materialModel", boxInfoDto.getMaterialModel());
        map.put("weight", String.valueOf(boxInfoDto.getWeight()));
        map.put("materialGear", boxInfoDto.getMaterialGear());
//        map.put("materialLevel", boxInfoDto.getMaterialLevel());
//        map.put("sourceProcess", boxInfoDto.getSourceProcess());
//        map.put("createUser", boxInfoDto.getCreateUser());
        map.put("remark", null == boxInfoDto.getRemark() ? "" : boxInfoDto.getRemark());
        list.add(map);

        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }


    /**
     * 通过单晶回收料编码查询信息打印单晶余料信息
     *
     * @param dto
     * @return
     */
    private List<String> printPcSurplusInfo(DocketPrintDto dto) {
        SurplusInfo surplusInfo = surplusInfoService.queryLimitInfoBySurplusCode(dto.getCode());
        if (null == surplusInfo) {
            throw new BusinessException(dto.getCode() + "单晶余料编号不存在");
        }
        //预览结果
        List<String> preview;
        //封装打印数据
        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("deviceNo", surplusInfo.getDeviceNo());
        map.put("surplusCode", surplusInfo.getSurplusCode());
        map.put("weight", String.valueOf(surplusInfo.getWeight()));
        map.put("workOrderNo", surplusInfo.getWorkOrderNo());
        list.add(map);
        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }

    @Override
    public List<String> printSurplusInfo(DocketPrintSurplusInfoDto dto) {
        //预览结果
        List<String> preview;
        SurplusInfoDto surplusInfoDto = dto.getDto();
        if (null == dto.getPrintModel()) {
            dto.setPrintModel("单晶余料标签");
        }
        if (null == dto.getPrintType()) {
            dto.setPrintType("单晶余料标签");
        }
        dto.setPrintNum(1);
        if (null == dto.getIsPreview()) {
            dto.setIsPreview(false);
        }
        //封装打印数据
        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("deviceNo", surplusInfoDto.getDeviceNo());
        map.put("surplusCode", surplusInfoDto.getSurplusCode());
        map.put("weight", String.valueOf(surplusInfoDto.getWeight()));
        map.put("workOrderNo", surplusInfoDto.getWorkOrderNo());
        list.add(map);
        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }


    @Override
    public List<String> printRecycledMaterial(DocketPrintRecycledMaterialDto dto) {
        //预览结果
        List<String> preview;
        RecycledMaterialModelDto recycledMaterialModelDto = dto.getDto();
        if (null == dto.getPrintModel()) {
            dto.setPrintModel("回收料标签");
        }
        if (null == dto.getPrintType()) {
            dto.setPrintType("回收料标签");
        }
        dto.setPrintNum(1);
        if (null == dto.getIsPreview()) {
            dto.setIsPreview(true);
        }
        //封装打印数据
        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("trayNo", recycledMaterialModelDto.getTrayNo());
        list.add(map);

        preview = this.doPrint(dto.getPrintModel(), list, dto.getIsPreview(), dto.getPrintNum());
        return preview;
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    void saveLog(List<PrinterLog> printerLogList) {
        printerLogService.saveAll(printerLogList);
    }


    /**
     * 打印画线标签
     *
     * @param docketPrintDto
     */
    private List<String> printDrawLineLabel(DocketPrintDto docketPrintDto) {
        List<String> preview = new ArrayList<>();
        List<String> list = new ArrayList<>();
        list.add("打印画线标签测试");
        preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview()));
        return preview;
    }

    /**
     * 打印圆棒合格证
     *
     * @param docketPrintDto
     */
    private List<String> printYbCrystalCertificate(DocketPrintDto docketPrintDto) {
        List<String> preview = new ArrayList<>();
        //查询圆棒检验信息
        YbInspectData inspectDataBase = inspectDataBaseService.findBySectionNo(docketPrintDto.getCode());
        if (inspectDataBase == null) {
            log.error("检验数据不存在");
            throw new RuntimeException("检验数据不存在");
        }
        YbCrystalCertificateDto ybCrystalCertificateDto = new YbCrystalCertificateDto();
//        BeanUtils.copyProperties(inspectDataBase, ybCrystalCertificateDto);
        BeanUtil.copyBeanPropWithNumberHandler(ybCrystalCertificateDto, inspectDataBase);
        if (StringUtils.isNotBlank(ybCrystalCertificateDto.getHeadSlope())) {
            ybCrystalCertificateDto.setHeadSlope("头斜:" + ybCrystalCertificateDto.getHeadSlope() + ";");
        }
        if (StringUtils.isNotBlank(ybCrystalCertificateDto.getTailSlope())) {
            ybCrystalCertificateDto.setTailSlope("尾斜:" + ybCrystalCertificateDto.getTailSlope() + ";");
        }

        if (StringUtils.isNotBlank(ybCrystalCertificateDto.getCollapseLine())) {
            ybCrystalCertificateDto.setCollapseLine("崩晶线:" + ybCrystalCertificateDto.getCollapseLine() + ";");
        }
        if (StringUtils.isNotBlank(ybCrystalCertificateDto.getFineDiameter())) {
            ybCrystalCertificateDto.setFineDiameter("细:" + ybCrystalCertificateDto.getFineDiameter() + ";");
        }
        if (StringUtils.isNotBlank(ybCrystalCertificateDto.getFineCutLength())) {
            ybCrystalCertificateDto.setFineCutLength("细减长:" + ybCrystalCertificateDto.getFineCutLength() + ";");
        }
        if ("223".equals(inspectDataBase.getProductTypeSecond())) {
//            ybCrystalCertificateDto.setResistivityTopAvg(new BigDecimal(df.format(inspectDataBase.getTopCentreEdgeAvg())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getTopCentreEdgeAvg()));
//            ybCrystalCertificateDto.setResistivityEndAvg(new BigDecimal(df.format(inspectDataBase.getEndCentreEdgeAvg())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getEndCentreEdgeAvg()));
        } else {
//            ybCrystalCertificateDto.setResistivityEndAvg(new BigDecimal(df.format(inspectDataBase.getResistivityEndAvg())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getResistivityEndAvg()));
//            ybCrystalCertificateDto.setResistivityTopAvg(new BigDecimal(df.format(new BigDecimal(inspectDataBase.getResistivityTopAvg()))).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(new BigDecimal(inspectDataBase.getResistivityTopAvg())));
        }

        ybCrystalCertificateDto.setActualLength(new BigDecimal(df.format(inspectDataBase.getActualLength())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getActualLength()));
        if (inspectDataBase.getReduceCrystalLength() != null && inspectDataBase.getReduceCrystalLength().compareTo(BigDecimal.ZERO) != 0) {
            ybCrystalCertificateDto.setActualLength(df.format(inspectDataBase.getActualLength()) + "-" + df.format(inspectDataBase.getReduceCrystalLength()));
        }
        ybCrystalCertificateDto.setProductTypeSecond(inspectDataBase.getConductiveType() + "-" + inspectDataBase.getProductTypeSecond());
        ybCrystalCertificateDto.setDiameterMin((new BigDecimal(df.format(inspectDataBase.getDiameterMin())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getDiameterMin())) + "-" + (new BigDecimal(df.format(inspectDataBase.getDiameterMax())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getDiameterMax())));
//        ybCrystalCertificateDto.setTwRadialEdge1Avg(new BigDecimal(df2.format(inspectDataBase.getTRadialEdge1().add(inspectDataBase.getWRadialEdge1()).divide(new BigDecimal(2)))).compareTo(BigDecimal.ZERO) == 0 ? "" : df2.format(inspectDataBase.getTRadialEdge1().add(inspectDataBase.getWRadialEdge1()).divide(new BigDecimal(2))));
//        ybCrystalCertificateDto.setTTempRadialCentre(inspectDataBase.getTRadialCentre() == null ? "" : inspectDataBase.getTRadialCentre().toString());
//        ybCrystalCertificateDto.setTTempRadialEdge1(inspectDataBase.getTRadialEdge1() == null ? "" : inspectDataBase.getTRadialEdge1().toString());
//        ybCrystalCertificateDto.setWTempRadialCentre(inspectDataBase.getWRadialCentre() == null ? "" : inspectDataBase.getWRadialCentre().toString());
//        ybCrystalCertificateDto.setWTempRadialEdge1(inspectDataBase.getWRadialEdge1() == null ? "" : inspectDataBase.getWRadialEdge1().toString());
        List list = new ArrayList();
        list.add(ybCrystalCertificateDto);
        preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview()));
        return preview;
    }

    /**
     * 打印合格证标签
     *
     * @param docketPrintDto
     */
    private List<String> printCertificateLabel(DocketPrintDto docketPrintDto) {
        List<String> preview = new ArrayList<>();
        //查询圆棒检验信息
        YbInspectData inspectDataBase = inspectDataBaseService.findBySectionNo(docketPrintDto.getCode());
        if (inspectDataBase == null) {
            log.error("检验数据不存在");
            throw new RuntimeException("检验数据不存在");
        }
        CertificateLabelDto certificateLabelDto = new CertificateLabelDto();
        BeanUtil.copyBeanPropWithNumberHandler(certificateLabelDto, inspectDataBase);

        BigDecimal twRadialEdgeAvgt = null;
        if (inspectDataBase.getTRadialEdge1() != null && inspectDataBase.getWRadialEdge1() != null) {
            twRadialEdgeAvgt = inspectDataBase.getTRadialEdge1().add(inspectDataBase.getWRadialEdge1()).divide(new BigDecimal(2));
        }
        certificateLabelDto.setTwRadialEdgeAvg(twRadialEdgeAvgt == null ? "" : df.format(twRadialEdgeAvgt));
        certificateLabelDto.setDiameterMinMax((new BigDecimal(df.format(inspectDataBase.getDiameterMin())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getDiameterMin())) + "-" + (new BigDecimal(df.format(inspectDataBase.getDiameterMax())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getDiameterMax())));

        List list = new ArrayList();
        list.add(certificateLabelDto);
        preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview()));
        return preview;

    }


    /**
     * 打印圆棒反切标签 输入晶段编号，打印晶段反切详情
     *
     * @param docketPrintDto
     */
    private List<String> printYbReCuttingLabel(DocketPrintDto docketPrintDto) {
        ProductionBackCuttingRecord productionBackCuttingRecord = productionRecutService.findTopBySegmentNoOrderByIdDesc(docketPrintDto.getCode());
        if (productionBackCuttingRecord == null) {
            throw new BusinessException("打印圆棒反切标签：反切信息不存在");
        }
        YbInspectData inspectDataBase = inspectDataBaseService.findBySectionNo(docketPrintDto.getCode());
        if (inspectDataBase == null) {
            log.error("检验数据不存在");
            throw new RuntimeException("打印圆棒反切标签:检验数据不存在");
        }
        //参杂剂为G的，不查询边皮打码规则
        SideSkinCodingRule sideSkinCodingRule = null;
        if (!inspectDataBase.getDopant().equals("G")) {
            sideSkinCodingRule = sideSkinCodingRuleService.findByYbSegmentNo(docketPrintDto.getCode());
            if (sideSkinCodingRule == null) {
                throw new RuntimeException("打印圆棒反切标签：未匹配到边皮打码规则");
            }
        }
        List<Object> list = new ArrayList<>();
        //反切画线信息详情
        List<ProductionPaintingLineDetail> productionPaintingLineDetailList1 = productionPaintingLineDetailService.findByOperateReversecutDrawId(productionBackCuttingRecord.getId());
        if (productionPaintingLineDetailList1.size() <= 0) {
            throw new BusinessException("打印圆棒反切标签：反切画线详情信息不存在");
        }
        ProductionPaintingLine productionPaintingLine = productionPaintingLineService.findByCrystalNo(inspectDataBase.getCrystalNo());
        String remark;
        if (productionPaintingLineDetailList1.get(0).getSegmentNum() == null) {
            ProductionPaintingLineDetail productionPaintingLineDetail = productionPaintingLineDetailService.findByOperateDrawIdAndAndNo(productionPaintingLine.getId(), inspectDataBase.getSectionNo());
            if (productionPaintingLineDetail != null) {
                remark = "第" + productionPaintingLineDetail.getSegmentNum() + "共" + productionPaintingLine.getLineNum();
            } else {
                remark = "第" + " 共" + productionPaintingLine.getLineNum();
            }
        } else {
            remark = "第" + productionPaintingLineDetailList1.get(0).getSegmentNum() + "共" + productionPaintingLine.getLineNum();
        }
        for (ProductionPaintingLineDetail paintingLineDetail : productionPaintingLineDetailList1) {
            ReCuttingLabelDto reCuttingLabelDto = new ReCuttingLabelDto();
            //填充掺杂剂和规格
            BeanUtil.copyBeanPropWithNumberHandler(reCuttingLabelDto, inspectDataBase);
            reCuttingLabelDto.setSectionNo(paintingLineDetail.getNo());
            reCuttingLabelDto.setRemark(remark);
            reCuttingLabelDto.setSegmentType(EnumValuesServer.LineType.getText(paintingLineDetail.getType()));
            if (EnumValuesServer.LineType.孪晶回收料.getKey() == paintingLineDetail.getType() || EnumValuesServer.LineType.直径异常回收料.getKey() == paintingLineDetail.getType() || EnumValuesServer.LineType.回收料.getKey() == paintingLineDetail.getType()) {
                reCuttingLabelDto.setCause(productionBackCuttingRecord.getCause() == null ? "" : productionBackCuttingRecord.getCause());
            } else {
                reCuttingLabelDto.setCause("");
            }
            if (sideSkinCodingRule != null) {
                reCuttingLabelDto.setCodeMark(sideSkinCodingRule.getCodeMark() == null ? "" : sideSkinCodingRule.getCodeMark());
            } else {
                reCuttingLabelDto.setCodeMark("");
            }
            list.add(reCuttingLabelDto);

        }
        return this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview());

    }


    /**
     * 圆棒反切标签 调整
     */
    private List<String> printRoundReverseTangent(DocketPrintDto docketPrintDto) {
        ProductionBackCuttingRecord productionBackCuttingRecord = productionRecutService.findTopBySegmentNoOrderByIdDesc(docketPrintDto.getCode());
        if (productionBackCuttingRecord == null) {
            throw new BusinessException("打印圆棒反切标签：反切记录不存在");
        }
        YbInspectData inspectDataBase = inspectDataBaseService.findBySectionNo(docketPrintDto.getCode());
        String productTypeSecond = "";
        if (null == inspectDataBase) {
            SectionNoDetail bySectionNo = sectionNoDetailService.findBySectionNo(docketPrintDto.getCode());
            if (null != bySectionNo && null != bySectionNo.getInspectionScrap() && bySectionNo.getInspectionScrap() == 1) {
                productTypeSecond = bySectionNo.getSpecs();
            } else {
                throw new RuntimeException("打印圆棒反切标签:检验数据不存在");
            }
        } else {
            productTypeSecond = inspectDataBase.getProductTypeSecond();
        }

        //反切画线信息详情
        List<ProductionPaintingLineDetail> productionPaintingLineDetailList = productionPaintingLineDetailService.findByOperateReversecutDrawId(productionBackCuttingRecord.getId());
        if (CollectionUtils.isEmpty(productionPaintingLineDetailList)) {
            throw new BusinessException("打印圆棒反切标签：反切画线详情信息不存在");
        }
        List<Map<String, String>> printKeyValuess = new LinkedList<>();
        DictionaryItem weightRatio = null;
        //圆棒理论折算系数
        if (StringUtils.isNotBlank(productTypeSecond)) {
            weightRatio = dictionaryItemService.findByThemeValueAndNameAndEnable("WeightRatio", productTypeSecond, true);
        }

        for (ProductionPaintingLineDetail paintingLineDetail : productionPaintingLineDetailList) {
            //打印签
            Map<String, String> paintingLineDetailMap = new HashMap<>();
            String type = "";
            switch (paintingLineDetail.getType()) {
                case 0:
                    type = EnumValuesServer.LineType.晶段.getValue();
                    if (null != paintingLineDetail.getWeight()) {
                        paintingLineDetailMap.put("weight", paintingLineDetail.getWeight().intValue() + "");
                    } else {
                        if (null != weightRatio && null != paintingLineDetail.getLength()) {
                            paintingLineDetailMap.put("weight", paintingLineDetail.getLength().divide(new BigDecimal(weightRatio.getValue()), 3, BigDecimal.ROUND_HALF_UP).intValue() + "");
                        }
                    }

                    break;
                case 1:
                    type = EnumValuesServer.LineType.样片.getValue();
                    break;
                case 2:
                    type = EnumValuesServer.LineType.回收料.getValue();
                    break;
                default:
                    type = null;

            }
            paintingLineDetailMap.put("crystalType", type);
            paintingLineDetailMap.put("length", null != paintingLineDetail.getLength() ? String.valueOf(paintingLineDetail.getLength().intValue()) : null);
            paintingLineDetailMap.put("cause", productionBackCuttingRecord.getCause());
            paintingLineDetailMap.put("segmentNo", paintingLineDetail.getNo());
            printKeyValuess.add(paintingLineDetailMap);
        }
        List<String> preview = new ArrayList<>();
        if (printKeyValuess.size() != 0) {
            //打印
            preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), printKeyValuess, docketPrintDto.getIsPreview(), 1));
        }
        return preview;
    }


    /**
     * 单晶补标签
     */
    private List<String> printCrystalPatchLabel(DocketPrintDto docketPrintDto) {

        ProductionPaintingLineDetail productionPaintingLineDetail = productionPaintingLineDetailService.findBySegmentNo(docketPrintDto.getCode());
        if (null == productionPaintingLineDetail) {
            throw new BusinessException("打印单晶补标签：单晶划线明细信息不存在！");
        }
        BigDecimal weightLossCoefficient = null;
        ProductionBackCuttingRecord productionBackCuttingRecord = productionRecutService.get(productionPaintingLineDetail.getOperateReversecutDrawId());
        if (null != productionBackCuttingRecord) {
            SectionNoDetail sectionNoDetail = sectionNoDetailService.findBySectionNo(docketPrintDto.getCode());
            if (null != sectionNoDetail) {
                DictionaryItem dictionaryItem = dictionaryItemService.findByThemeValueAndNameAndEnable("WeightRatio", sectionNoDetail.getSpecs(), true);
                if (null != dictionaryItem) {
                    weightLossCoefficient = NumberUtil.Object2BigDecimal(dictionaryItem.getValue());
                }
            }
        } else {
            ReCut reCut = fbReCutService.get(productionPaintingLineDetail.getOperateReversecutDrawId());
            if (null != reCut) {
                List<DictionaryItem> dictionaryItems = dictionaryItemService.findByThemeValueAndItemName(Constants.THEORETICAL_WEIGHT_COEFFICIENTFB, reCut.getSpecs(), true);
                if (!CollectionUtils.isEmpty(dictionaryItems)) {
                    weightLossCoefficient = NumberUtil.Object2BigDecimal(dictionaryItems.get(0).getValue());
                }
            }
        }
        List<Map<String, String>> printKeyValuess = new LinkedList<>();
        //打印签
        Map<String, String> paintingLineDetailMap = new HashMap<>();
        if (null != productionPaintingLineDetail.getLength()) {
            paintingLineDetailMap.put("length", productionPaintingLineDetail.getLength().intValue() + "");
        } else {
            paintingLineDetailMap.put("length", "");
        }
        paintingLineDetailMap.put("segmentNo", productionPaintingLineDetail.getNo());
        paintingLineDetailMap.put("cause", productionPaintingLineDetail.getReason());
        if (null != productionPaintingLineDetail) {
            if (null != productionPaintingLineDetail.getWeight()) {
                BigDecimal weight = productionPaintingLineDetail.getWeight().setScale(3, BigDecimal.ROUND_HALF_UP);
                paintingLineDetailMap.put("weight", weight.toString());
            } else {
                if (null != weightLossCoefficient && null != productionPaintingLineDetail.getLength()) {
                    paintingLineDetailMap.put("weight", productionPaintingLineDetail.getLength().divide(weightLossCoefficient, 3, BigDecimal.ROUND_HALF_UP).toString());
                }
            }
            if (productionPaintingLineDetail.getType() == EnumValuesServer.LineType.样片.getKey()) {
                paintingLineDetailMap.put("crystalType", EnumValuesServer.LineType.样片.getValue());
                paintingLineDetailMap.put("weight", "");
            } else if (productionPaintingLineDetail.getType() == EnumValuesServer.LineType.回收料.getKey()) {
                paintingLineDetailMap.put("crystalType", EnumValuesServer.LineType.回收料.getValue());
            } else if (productionPaintingLineDetail.getType() == EnumValuesServer.LineType.晶段.getKey()) {
                paintingLineDetailMap.put("crystalType", EnumValuesServer.LineType.晶段.getValue());
            }
        }
        printKeyValuess.add(paintingLineDetailMap);
        List<String> preview = new ArrayList<>();
        if (printKeyValuess.size() != 0) {
            //打印
            preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), printKeyValuess, docketPrintDto.getIsPreview(), 1));
        }
        return preview;
    }

    /**
     * 打印圆棒反切标签 输入晶段编号，打印晶段反切详情
     * zhaoyayun
     *
     * @param docketPrintDto
     */
    private List<String> printYbReCuttingLabel2(DocketPrintDto docketPrintDto) {
        ProductionBackCuttingRecord productionBackCuttingRecord = productionRecutService.findTopBySegmentNoOrderByIdDesc(docketPrintDto.getCode());
        if (productionBackCuttingRecord == null) {
            throw new BusinessException("打印圆棒反切标签：反切信息不存在");
        }
        YbInspectData inspectDataBase = inspectDataBaseService.findBySectionNo(docketPrintDto.getCode());
        if (inspectDataBase == null) {
            log.error("检验数据不存在");
            throw new RuntimeException("打印圆棒反切标签:检验数据不存在");
        }
        //边距
        String sideLengthRange = "";
        sideLengthRange = inspectDataBase.getSideLengthRange();
        //边宽
        String multipleSideLogic = getMultipleSideLogic(sideLengthRange);
        //参杂剂为G的，不查询边皮打码规则
//        SideSkinCodingRule sideSkinCodingRule = null;
//        if (!inspectDataBase.getDopant().equals("G")) {
//            sideSkinCodingRule = sideSkinCodingRuleService.findByYbSegmentNo(docketPrintDto.getCode());
//            if (sideSkinCodingRule == null) {
//                throw new RuntimeException("打印圆棒反切标签：未匹配到边皮打码规则");
//            }
//        }
        List<Object> list = new ArrayList<>();
        //反切画线信息详情
        List<ProductionPaintingLineDetail> productionPaintingLineDetailList1 = productionPaintingLineDetailService.findByOperateReversecutDrawId(productionBackCuttingRecord.getId());
        if (productionPaintingLineDetailList1.size() <= 0) {
            throw new BusinessException("打印圆棒反切标签：反切画线详情信息不存在");
        }
        ProductionPaintingLine productionPaintingLine = productionPaintingLineService.findByCrystalNo(inspectDataBase.getCrystalNo());
        //       String remark;
//        if (productionPaintingLineDetailList1.get(0).getSegmentNum() == null) {
//            ProductionPaintingLineDetail productionPaintingLineDetail = productionPaintingLineDetailService.findByOperateDrawIdAndAndNo(productionPaintingLine.getId(), inspectDataBase.getSectionNo());
//            if (productionPaintingLineDetail != null) {
//                remark = "第" + productionPaintingLineDetail.getSegmentNum() + "共" + productionPaintingLine.getLineNum();
//            } else {
//                remark = "第" + " 共" + productionPaintingLine.getLineNum();
//            }
//        } else {
//            remark = "第" + productionPaintingLineDetailList1.get(0).getSegmentNum() + "共" + productionPaintingLine.getLineNum();
//        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (ProductionPaintingLineDetail paintingLineDetail : productionPaintingLineDetailList1) {
            if ((null == docketPrintDto.getIsPrint() || !docketPrintDto.getIsPrint()) && paintingLineDetail.getType().equals(EnumValuesServer.LineType.回收料.getKey())) {
                continue;
            }
            ReCuttingLabelDto reCuttingLabelDto = new ReCuttingLabelDto();
            //填充掺杂剂和规格
            BeanUtil.copyBeanPropWithNumberHandler(reCuttingLabelDto, inspectDataBase);
            reCuttingLabelDto.setProductLevel("");
            reCuttingLabelDto.setSectionNo(paintingLineDetail.getNo());//编号
            reCuttingLabelDto.setMultipleSideLogic(multipleSideLogic);
            //划线时间
            reCuttingLabelDto.setEndTime(simpleDateFormat.format(productionBackCuttingRecord.getLineEndTime()));
            //reCuttingLabelDto.setRemark(remark);
            //晶段类型（晶段、回收料）
            reCuttingLabelDto.setSegmentType(EnumValuesServer.LineType.getText(paintingLineDetail.getType()));
            //等级(只有回收料的数据里放评级)
            if (paintingLineDetail.getType() == EnumValuesServer.LineType.valueOf("回收料").getKey()) {
                reCuttingLabelDto.setProductLevel(inspectDataBase.getProductLevel());
            }
            //todo 长度保留一位小数(四舍五入)
            BigDecimal number = paintingLineDetail.getLength().setScale(1, BigDecimal.ROUND_HALF_UP);
            reCuttingLabelDto.setLength(number);
            //产品类别，去数据字典查
            String fromMark = paintingLineDetail.getNo().substring(SectionIndexRangeEnum.基地追溯产品类型.getBeginIndex(), SectionIndexRangeEnum.基地追溯产品类型.getEndIndex());
            String productType = "";
            if (fromMark.matches("[A-Z]+")) {
                productType = paintingLineDetail.getNo().substring(SectionIndexRangeEnum.产品类型.getBeginIndex(), SectionIndexRangeEnum.产品类型.getEndIndex());
            } else {
                productType = paintingLineDetail.getNo().substring(1, 2);
            }
            List<DictionaryItem> productCategorys = dictionaryItemService.findByThemeNamAndItemValue("产品类别", productType, true);
            if (productCategorys.size() > 0) {
                reCuttingLabelDto.setProductCategory(productCategorys.get(0).getName());
            }

//            if (EnumValuesServer.LineType.孪晶回收料.getKey() == paintingLineDetail.getType() || EnumValuesServer.LineType.直径异常回收料.getKey() == paintingLineDetail.getType() || EnumValuesServer.LineType.回收料.getKey() == paintingLineDetail.getType()) {
//                reCuttingLabelDto.setCause(productionBackCuttingRecord.getCause() == null ? "" : productionBackCuttingRecord.getCause());
//            } else {
//                reCuttingLabelDto.setCause("");
//            }

            //打码标识
//            if (sideSkinCodingRule != null) {
//                reCuttingLabelDto.setCodeMark(sideSkinCodingRule.getCodeMark() == null ? "" : sideSkinCodingRule.getCodeMark());
//            } else {
//                reCuttingLabelDto.setCodeMark("");
//            }
            list.add(reCuttingLabelDto);

        }

        return this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview(), 2);

    }


    /**
     * 打印圆棒初级标签
     *
     * @param docketPrintDto
     */
    private List<String> printYbPrimaryLabel(DocketPrintDto docketPrintDto) {
        List<String> preview = new ArrayList<>();
        List list = new ArrayList();
        Map<String, String> printMap = new HashMap<>();
        printMap.put("sectionNo", docketPrintDto.getCode());
        list.add(printMap);
        preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview()));
        return preview;
    }

    /**
     * 打印长晶棒头划线
     *
     * @param docketPrintDto
     */
    private List<String> printLongShippingMark(DocketPrintDto docketPrintDto) {
        List<String> preview = new ArrayList<>();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        LongCrystal longCrystal = longCrystalService.findByCrystalNo(docketPrintDto.getCode());
        if (longCrystal == null) {
            throw new RuntimeException("长棒信息不存在");
        }
        ProductionPaintingLine productionPaintingLine = productionPaintingLineService.findByCrystalNo(docketPrintDto.getCode());
        if (productionPaintingLine == null) {
            throw new RuntimeException("画线信息不存在");
        }
        List<ProductionPaintingLineDetail> productionPaintingLineDetailList = productionPaintingLineDetailService.findByOperateDrawId(productionPaintingLine.getId());
        if (productionPaintingLineDetailList.size() <= 0) {
            throw new RuntimeException("画线详情信息不存在");
        }
        //docketPrintDto.setPrintNum(2);
        //需要打印的信息
        List<Map<String, String>> keyvaluess = new LinkedList<>();
        //组装长晶棒
        Map<String, String> longMapData = new HashMap<>();
        longMapData.put("length", longCrystal.getLength().toString());
        longMapData.put("code", docketPrintDto.getCode());
        longMapData.put("weight", longCrystal.getWeight().toString());
        //添加冷却结束时间
        if (null != longCrystal.getGmtCreate()) {
            Date coolingEndTime = DateUtil.addHour(longCrystal.getGmtCreate(), 9);
            longMapData.put("coolingEndTime", simpleDateFormat.format(coolingEndTime));
        } else {
            longMapData.put("coolingEndTime", null);
        }
        longMapData.put("type", "长晶棒");
        Map<String, String> longMapData1 = new HashMap<>(longMapData);
        keyvaluess.add(longMapData);
        keyvaluess.add(longMapData1);
        //关联打印
        if (docketPrintDto.getIsAssociated() == null || docketPrintDto.getIsAssociated()) {
            //组装晶段
            productionPaintingLineDetailList.stream().forEach(productionPaintingLineDetail -> {
                Map<String, String> mapData = new HashMap<>();
                String length = String.valueOf(productionPaintingLineDetail.getLength().intValue());
                String code = productionPaintingLineDetail.getNo();
                String weight;
                if (productionPaintingLineDetail.getWeight() == null) {
                    weight = "";
                } else {
                    weight = productionPaintingLineDetail.getWeight().toString();
                }
                mapData.put("length", length);
                mapData.put("code", code);
                mapData.put("weight", weight);
                if (null == productionPaintingLineDetail.getType()) {
                    mapData.put("type", "");
                } else {
                    switch (productionPaintingLineDetail.getType()) {
                        case 0:
                            mapData.put("type", "晶段");
                            break;
                        case 1:
                            mapData.put("type", "样片");
                            break;
                        case 2:
                            mapData.put("type", "回收料");
                            break;
                        default:
                            mapData.put("type", "");
                            return;
                    }
                }
                keyvaluess.add(mapData);
            });
        }
        if (keyvaluess.size() > 0) {
            //打印
            preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), keyvaluess, docketPrintDto.getIsPreview(), 1));
        }
        return preview;
    }


    /**
     * 打印晶棒划线条码
     *
     * @param docketPrintDto
     */
    private List<String> printCrystalDocumentMould(DocketPrintDto docketPrintDto) {
        List<String> preview = new ArrayList<>();
        ProductionPaintingLineDetail productionPaintingLineDetail = productionPaintingLineDetailService.findBySegmentNo(docketPrintDto.getCode());
        if (productionPaintingLineDetail == null) {
            throw new RuntimeException("画线详情信息不存在");
        }
        LongCrystal longCrystal = longCrystalService.get(productionPaintingLineDetail.getCrystalId());
        if (longCrystal == null) {
            throw new RuntimeException("长棒信息不存在");
        }
        ProductionPaintingLine productionPaintingLine = productionPaintingLineService.findByCrystalNo(longCrystal.getCrystalNo());
        if (productionPaintingLine == null) {
            throw new RuntimeException("画线信息不存在");
        }
        List<ProductionPaintingLineDetail> productionPaintingLineDetailList = productionPaintingLineDetailService.findByOperateDrawId(productionPaintingLineDetail.getOperateDrawId());

        DictionaryItem weightRatio = null;
        //圆棒理论折算系数
        if (StringUtils.isNotBlank(longCrystal.getSpecs())) {
            weightRatio = dictionaryItemService.findByThemeValueAndNameAndEnable("WeightRatio", longCrystal.getSpecs(), true);
        }
        //装载短棒信息
        List<Map<String, String>> keyvaluess = new ArrayList<>();
//        if (docketPrintDto.getIsAssociated() == null || docketPrintDto.getIsAssociated()) {

        Map<String, String> mapData = new HashMap<>();
        mapData.put("no", productionPaintingLineDetail.getNo());
        mapData.put("dopant", longCrystal.getDopant());
        mapData.put("specification", longCrystal.getSpecs());
        mapData.put("length", String.valueOf(productionPaintingLineDetail.getLength().intValue()));
        //头
        if (productionPaintingLineDetail.getSequence() == 0) {
            mapData.put("length", "");
            mapData.put("remarks1", "单晶头");
            mapData.put("remarks2", "");
            keyvaluess.add(mapData);

            //尾
        } else if (productionPaintingLineDetail.getSequence() == productionPaintingLineDetailList.size() - 1) {
            mapData.put("length", "");
            mapData.put("remarks1", "单晶尾");
            mapData.put("remarks2", "");
            keyvaluess.add(mapData);
        } else {
            //region 装载中间段打印数据
            if (productionPaintingLineDetail.getType() == EnumValuesServer.LineType.晶段.getKey()) {
                mapData.put("remarks1", "");
                //添加理论重量
                if (null != productionPaintingLineDetail.getWeight()) {
                    mapData.put("weight", productionPaintingLineDetail.getWeight().intValue() + "");
                } else {
                    if (null != weightRatio && null != productionPaintingLineDetail.getLength()) {
                        mapData.put("weight", productionPaintingLineDetail.getLength().divide(new BigDecimal(weightRatio.getValue()), 3, BigDecimal.ROUND_HALF_UP).intValue() + "");
                    }
                }
                mapData.put("remarks2", "第" + productionPaintingLineDetail.getSegmentNum() + "共" + productionPaintingLine.getLineNum());
                keyvaluess.add(mapData);
            } else if (productionPaintingLineDetail.getType() == EnumValuesServer.LineType.样片.getKey()) {
                mapData.put("remarks1", EnumValuesServer.SampleType.getText(productionPaintingLineDetail.getSampleType()));
                mapData.put("remarks2", "");
                keyvaluess.add(mapData);
            } else if (productionPaintingLineDetail.getType() == EnumValuesServer.LineType.直径异常回收料.getKey() || productionPaintingLineDetail.getType() == EnumValuesServer.LineType.孪晶回收料.getKey()) {
                mapData.put("remarks1", "回收料");
                mapData.put("remarks2", "");
                keyvaluess.add(mapData);
            }

        }


//        }


        if (keyvaluess.size() > 0) {
            //打印晶棒划线条码
            preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), keyvaluess, docketPrintDto.getIsPreview()));

        }

        return preview;

    }

    /**
     * 打印晶棒划线条码
     *
     * @param docketPrintDto
     */
    private List<String> printPdaReLabel(DocketPrintDto docketPrintDto) {
        List<String> preview = new ArrayList<>();

        //装载短棒信息
        List<Map<String, String>> keyvaluess = new ArrayList<>();
        Map<String, String> mapData = new HashMap<>();
        List<WipStorage> byProcessingByOrderCode = wipStorageService.findByProcessingByOrderCode(docketPrintDto.getCode());
        if (CollectionUtils.isEmpty(byProcessingByOrderCode)) {
            throw new BusinessException("在制品记录中不包含此颗晶棒");
        }
        String processName = byProcessingByOrderCode.get(0).getProcessName();
        Integer status = byProcessingByOrderCode.get(0).getStatus();
        if (status == 0) {
            processName = processName + "待进站";
        } else {
            processName = processName + "已进站";
        }
        String specs = "";
        String dopant1 = "";
        String productType1 = "";
        String sideLengthRange = "";
        String fromMark = docketPrintDto.getCode().substring(SectionIndexRangeEnum.基地追溯产品类型.getBeginIndex(), SectionIndexRangeEnum.基地追溯产品类型.getEndIndex());
        LongCrystal byCrystalNo = null;
        if (fromMark.matches("[A-Z]+")) {
            byCrystalNo = longCrystalService.findByCrystalNo(docketPrintDto.getCode().substring(SectionIndexRangeEnum.毛棒范围.getBeginIndex(), SectionIndexRangeEnum.毛棒范围.getEndIndex()));
        } else {
            byCrystalNo = longCrystalService.findByCrystalNo(docketPrintDto.getCode().substring(0, 12));
        }
        if (null == byCrystalNo) {
            throw new BusinessException("长晶棒记录中不包含此颗晶棒");
        }
        if (null == byCrystalNo) {
            List<YbOemData> bySectionNo = ybOemDataDao.findBySectionNo(docketPrintDto.getCode());
            if (docketPrintDto.getCode().startsWith("B") && !CollectionUtils.isEmpty(bySectionNo)) {
                YbOemData ybOemData = bySectionNo.get(0);
                specs = ybOemData.getProductTypeSecond();
                dopant1 = ybOemData.getDopant();
                productType1 = ybOemData.getProductType();
                sideLengthRange = ybOemData.getSideLengthRange();
            }
        } else {
            specs = byCrystalNo.getSpecs();
            dopant1 = byCrystalNo.getDopant();
            productType1 = byCrystalNo.getProductType();
            sideLengthRange = byCrystalNo.getSideLengthRange();
        }

        List<DictionaryItem> productType = dictionaryItemService.findByThemeValueAndEnable("product_category", true);
        final Map<String, String> productTypeMap = productType.stream().collect(Collectors.toMap(DictionaryItem::getValue, DictionaryItem::getName, (v1, v2) -> v1));

        List<DictionaryItem> dopant = dictionaryItemService.findByThemeValueAndEnable("dopant", true);
        final Map<String, String> dopantMap = dopant.stream().collect(Collectors.toMap(DictionaryItem::getValue, DictionaryItem::getExtendValue, (v1, v2) -> v1));

        List<DictionaryItem> specification = dictionaryItemService.findByThemeValueAndEnable("specificationOption", true);
        final Map<String, String> specificationMap = specification.stream().collect(Collectors.toMap(DictionaryItem::getValue, DictionaryItem::getExtendValue, (v1, v2) -> v1));

        //边宽
        String multipleSideLogic = getMultipleSideLogic(sideLengthRange);
        mapData.put("total", productType1 + "-" + productTypeMap.get(productType1) + "/" + dopant1 + "-" + dopantMap.get(dopant1) + "/" + specificationMap.get(specs) + "-" + specs);
        mapData.put("point", processName);
        mapData.put("multipleSideLogic", multipleSideLogic);
        mapData.put("fbNo", docketPrintDto.getCode());
        keyvaluess.add(mapData);
        if (keyvaluess.size() > 0) {
            //打印晶棒划线条码
            preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), keyvaluess, docketPrintDto.getIsPreview()));
        }
        return preview;
    }

    //region 打印方棒合格证（拼棒两张）

    /**
     * 打印方棒合格证（拼棒两张）
     *
     * @param docketPrintDto
     */
    private List<String> printFbCrystalCertificate(DocketPrintDto docketPrintDto) {
        List<String> preview = new ArrayList<>();
        Result dataByFbSectionNo = fbFeignClients.findDataByFbSectionNo(docketPrintDto.getCode());
        if (dataByFbSectionNo.getCode() != 200) {
            throw new RuntimeException(dataByFbSectionNo.getMessage());
        }

        FbCheckOutDataDto fbCheckOutDataDto = JSONObject.parseObject(JSONObject.toJSONString(dataByFbSectionNo.getData()), FbCheckOutDataDto.class);
        if (fbCheckOutDataDto == null) {
            throw new RuntimeException("未查询到方棒检验数据");
        }

        //扫码单晶的检验数据
        FbCheckOutDataDto fbCheckOutDataDtoFrist = fbCheckOutDataDto;

        //单晶集合
        List<String> listSectionNo = new ArrayList<>();
        //拼棒打印两颗单晶数据
        if (fbCheckOutDataDto.getSticksCount() != null && fbCheckOutDataDto.getSticksCount() > 1) {
            if (fbCheckOutDataDto.getSectionCompose() == null) {
                throw new RuntimeException("拼棒组合信息不存在！");
            }
            listSectionNo = Arrays.asList(fbCheckOutDataDto.getSectionCompose().split(","));
        } else {
            listSectionNo.add(docketPrintDto.getCode());
        }

        List list = new ArrayList();
        for (String sectionNo : listSectionNo) {
            if (sectionNo != fbCheckOutDataDto.getFbSectionNo()) {
                dataByFbSectionNo = fbFeignClients.findDataByFbSectionNo(sectionNo);
                if (dataByFbSectionNo.getCode() != 200) {
                    throw new RuntimeException(dataByFbSectionNo.getMessage());
                }
                fbCheckOutDataDto = JSONObject.parseObject(JSONObject.toJSONString(dataByFbSectionNo.getData()), FbCheckOutDataDto.class);
                if (fbCheckOutDataDto == null) {
                    throw new RuntimeException("未查询到方棒检验数据");
                }
            } else {
                //扫码单晶
                fbCheckOutDataDto = fbCheckOutDataDtoFrist;
            }

            FbCrystalCertificateDto fbCrystalCertificateDto = new FbCrystalCertificateDto();
            BeanUtil.copyBeanPropWithNumberHandler(fbCrystalCertificateDto, fbCheckOutDataDto);
            //"方棒长度-异常总和"
            fbCrystalCertificateDto.setLength(new BigDecimal(df.format(fbCheckOutDataDto.getLength())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(fbCheckOutDataDto.getLength()));
            if (fbCheckOutDataDto.getProductLevelFb() != null && "正常".equals(fbCheckOutDataDto.getProductLevelFb()) && fbCheckOutDataDto.getAbnormalSum() != null && fbCheckOutDataDto.getAbnormalSum().compareTo(BigDecimal.ZERO) != 0) {
                fbCrystalCertificateDto.setLength((new BigDecimal(df.format(fbCheckOutDataDto.getLength())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(fbCheckOutDataDto.getLength())) + "-" + (new BigDecimal(df.format(fbCheckOutDataDto.getAbnormalSum())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(fbCheckOutDataDto.getAbnormalSum())));
            }
            if (new BigDecimal(df.format(fbCheckOutDataDto.getCrackWidth())).compareTo(BigDecimal.ZERO) == 0) {
                fbCrystalCertificateDto.setCrackWidth("");
            } else {
                fbCrystalCertificateDto.setCrackWidth("缝宽" + df.format(fbCheckOutDataDto.getCrackWidth()) + "mm");
            }
            if (fbCheckOutDataDto.getSticksCount() == null || fbCheckOutDataDto.getSticksCount() <= 1) {
                fbCrystalCertificateDto.setSticksCount("");
                fbCrystalCertificateDto.setCrackWidth("");
                fbCrystalCertificateDto.setSpellBarLengthFb("");
            } else {
                fbCrystalCertificateDto.setSticksCount(fbCheckOutDataDto.getSticksCount() + "拼");
                fbCrystalCertificateDto.setSpellBarLengthFb(fbCheckOutDataDto.getSpellBarLength().setScale(0, BigDecimal.ROUND_DOWN).toString());
            }
            fbCrystalCertificateDto.setHeadSlopeFb(fbCheckOutDataDto.getHeadSlope() == null || new BigDecimal(df.format(fbCheckOutDataDto.getHeadSlope())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(fbCheckOutDataDto.getHeadSlope()));
            fbCrystalCertificateDto.setTailSlopeFb(fbCheckOutDataDto.getTailSlope() == null || new BigDecimal(df.format(fbCheckOutDataDto.getTailSlope())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(fbCheckOutDataDto.getTailSlope()));
            fbCrystalCertificateDto.setLengthSlope(fbCheckOutDataDto.getLengthSlope() == null || new BigDecimal(df.format(fbCheckOutDataDto.getLengthSlope())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(fbCheckOutDataDto.getLengthSlope()));

            YbInspectData inspectDataBase = inspectDataBaseService.findBySectionNo(fbCheckOutDataDto.getYbSectionNo());
            if (inspectDataBase == null) {
                throw new RuntimeException("圆棒检验数据不存在");
            }
            BeanUtil.copyBeanPropWithNumberHandler(fbCrystalCertificateDto, inspectDataBase);
//            fbCrystalCertificateDto.setHeadSlope(inspectDataBase.getHeadSlope() == null || new BigDecimal(df.format(inspectDataBase.getHeadSlope())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getHeadSlope()));
//            fbCrystalCertificateDto.setTailSlope(inspectDataBase.getTailSlope() == null || new BigDecimal(df.format(inspectDataBase.getTailSlope())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getTailSlope()));
            if (inspectDataBase.getProductTypeSecond().equals("233")) {
//                fbCrystalCertificateDto.setResistivityTopAvg(new BigDecimal(df.format(inspectDataBase.getTopCentreEdgeAvg())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getTopCentreEdgeAvg()));
//                fbCrystalCertificateDto.setResistivityEndAvg(new BigDecimal(df.format(inspectDataBase.getEndCentreEdgeAvg())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getEndCentreEdgeAvg()));
            }
            //
            fbCrystalCertificateDto.setExperiLevel(fbCheckOutDataDto.getYbExperiLevel() == null ? "" : fbCheckOutDataDto.getYbExperiLevel());
            FbProductCard bySpecification = fbProductCardService.findBySpecification(fbCheckOutDataDto.getSpecification());
            if (bySpecification == null) {
                throw new RuntimeException("未查寻到产品标准卡信息");
            }
            BeanUtil.copyBeanPropWithNumberHandler(fbCrystalCertificateDto, bySpecification);
//            if (inspectDataBase.getTRadialEdge1() != null && inspectDataBase.getWRadialEdge1() != null) {
//                fbCrystalCertificateDto.setTwRadialEdge1Avg(new BigDecimal(df2.format(inspectDataBase.getTRadialEdge1().add(inspectDataBase.getWRadialEdge1()).divide(new BigDecimal(2)))).compareTo(BigDecimal.ZERO) == 0 ? "" : df2.format(inspectDataBase.getTRadialEdge1().add(inspectDataBase.getWRadialEdge1()).divide(new BigDecimal(2))));
//            } else {
//                fbCrystalCertificateDto.setTwRadialEdge1Avg("");
//            }
            if ("正常".equals(fbCheckOutDataDto.getProductLevelFb())) {
                fbCrystalCertificateDto.setProductLevelFb("");
            } else {
                fbCrystalCertificateDto.setProductLevelFb(fbCheckOutDataDto.getProductLevelFb());
            }
            fbCrystalCertificateDto.setAppearanceException(this.getProductLevelFb(fbCheckOutDataDto));
            fbCrystalCertificateDto.setSpecificationYb(inspectDataBase.getProductTypeSecond() == null ? "" : inspectDataBase.getProductTypeSecond());
            fbCrystalCertificateDto.setActualLength(inspectDataBase.getActualLength() == null ? "" : (new BigDecimal(df.format(inspectDataBase.getActualLength())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getActualLength())));
            String specification = fbCheckOutDataDto.getSpecification();
            if (specification != null) {
                String[] split = specification.split("\\*");
                if (split != null && split.length > 0) {
                    specification = split[0];
                }
            }
            fbCrystalCertificateDto.setSpecification(fbCheckOutDataDto.getConductionType() + "-" + specification);
            fbCrystalCertificateDto.setDiameterMinMax((new BigDecimal(df.format(inspectDataBase.getDiameterMin())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getDiameterMin())) + "-" + (new BigDecimal(df.format(inspectDataBase.getDiameterMax())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getDiameterMax())));
            fbCrystalCertificateDto.setDeviceNo(fbCheckOutDataDto.getDeviceNo() == null ? "" : fbCheckOutDataDto.getDeviceNo());
            if (StringUtils.isNotBlank(fbCrystalCertificateDto.getHeadSlopeFb())) {
                fbCrystalCertificateDto.setHeadSlopeFb("头斜：" + fbCrystalCertificateDto.getHeadSlopeFb());
            }
            if (StringUtils.isNotBlank(fbCrystalCertificateDto.getTailSlopeFb())) {
                fbCrystalCertificateDto.setTailSlopeFb("尾斜：" + fbCrystalCertificateDto.getTailSlopeFb());
            }
            if (StringUtils.isNotBlank(fbCrystalCertificateDto.getLengthSlope())) {
                fbCrystalCertificateDto.setLengthSlope("长度斜：" + fbCrystalCertificateDto.getLengthSlope());
            }
            if (StringUtils.isNotBlank(fbCrystalCertificateDto.getHeadSlope())) {
                fbCrystalCertificateDto.setHeadSlope("头斜：" + fbCrystalCertificateDto.getHeadSlope());
            }
            if (StringUtils.isNotBlank(fbCrystalCertificateDto.getTailSlope())) {
                fbCrystalCertificateDto.setTailSlope("尾斜：" + fbCrystalCertificateDto.getTailSlope());
            }
            if (StringUtils.isNotBlank(fbCrystalCertificateDto.getEdgeBark())) {
                fbCrystalCertificateDto.setEdgeBark("崩边长度：" + fbCrystalCertificateDto.getEdgeBark());
            }
            if (StringUtils.isNotBlank(fbCrystalCertificateDto.getCollapseLine())) {
                fbCrystalCertificateDto.setCollapseLine("崩晶线：" + fbCrystalCertificateDto.getCollapseLine());
            }
            if (StringUtils.isNotBlank(fbCrystalCertificateDto.getFineCutLength())) {
                fbCrystalCertificateDto.setFineCutLength("细减长：" + fbCrystalCertificateDto.getFineCutLength());
            }
            if (StringUtils.isNotBlank(fbCrystalCertificateDto.getFineDiameter())) {
                fbCrystalCertificateDto.setFineDiameter("细：" + fbCrystalCertificateDto.getFineDiameter());
            }
            if (StringUtils.isNotBlank(fbCrystalCertificateDto.getAnomaly())) {
                fbCrystalCertificateDto.setAnomaly("异常汇总：" + fbCrystalCertificateDto.getAnomaly());
            }

            list.add(fbCrystalCertificateDto);
        }

        preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview()));
        return preview;
    }
    //endregion

    //region  打印方棒合格证（打印一张，拼棒信息融合）
    /**
     * 打印方棒合格证（打印长棒）
     *
     * @param docketPrintDto
     */
//    private List<String> printFbCrystalCertificate(DocketPrintDto docketPrintDto) {
//        List<String> preview = new ArrayList<>();
//
//        //查询方棒检验数据
//        Result dataByFbSectionNo = fbFeignService.findDataByFbSectionNo(docketPrintDto.getCode());
//        if (dataByFbSectionNo.getCode() != 200) {
//            throw new RuntimeException(dataByFbSectionNo.getMessage());
//        }
//
//        FbCheckOutDataDto fbCheckOutDataDto = JSONObject.parseObject(JSONObject.toJSONString(dataByFbSectionNo.getData()), FbCheckOutDataDto.class);
//        if (fbCheckOutDataDto == null) {
//            throw new RuntimeException("未查询到方棒检验数据");
//        }
//
//        //单晶集合
//        List<FbCheckOutDataDto> fbCheckOutDataDtoList = new ArrayList<>();
//        //拼棒打印两颗单晶数据
//        if(fbCheckOutDataDto.getSticksCount() != null && fbCheckOutDataDto.getSticksCount() > 1){
//            //查询拼棒组合信息
//            if (fbCheckOutDataDto.getSectionCompose() == null){
//                throw new RuntimeException("拼棒组合信息不存在！");
//            }
//            List<String> listSectionNo = Arrays.asList(fbCheckOutDataDto.getSectionCompose().split(","));
//
//            //查询拼棒方棒检验数据
//            Result result = fbFeignService.findDataByFbSectionNoList(listSectionNo);
//            if (result.getCode() != 200) {
//                throw new RuntimeException(result.getMessage());
//            }
//
//            fbCheckOutDataDtoList = JSONObject.parseArray(JSONObject.toJSONString(result.getData()), FbCheckOutDataDto.class);
//            if (fbCheckOutDataDtoList == null || fbCheckOutDataDtoList.size() <= 0) {
//                throw new RuntimeException("未查询到拼棒方棒检验数据");
//            }
//
//            fbCheckOutDataDto = fbCheckOutDataDtoList.get(0);
//        }else{
//            fbCheckOutDataDtoList.add(fbCheckOutDataDto);
//        }
//
//        FbCrystalCertificateDto fbCrystalCertificateDto = new FbCrystalCertificateDto();
//        NumberBeanUtils.copyBeanProp(fbCrystalCertificateDto, fbCheckOutDataDto);
//        //"方棒长度-异常总和"
//        fbCrystalCertificateDto.setLength(new BigDecimal(df.format(fbCheckOutDataDto.getLength())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(fbCheckOutDataDto.getLength()));
//        if (fbCheckOutDataDto.getProductLevelFb() != null && "正常".equals(fbCheckOutDataDto.getProductLevelFb()) && fbCheckOutDataDto.getAbnormalSum() != null && fbCheckOutDataDto.getAbnormalSum().compareTo(BigDecimal.ZERO) != 0) {
//            fbCrystalCertificateDto.setLength((new BigDecimal(df.format(fbCheckOutDataDto.getLength())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(fbCheckOutDataDto.getLength())) + "-" + (new BigDecimal(df.format(fbCheckOutDataDto.getAbnormalSum())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(fbCheckOutDataDto.getAbnormalSum())));
//        }
//
//        if (new BigDecimal(df.format(fbCheckOutDataDto.getCrackWidth())).compareTo(BigDecimal.ZERO) == 0) {
//            fbCrystalCertificateDto.setCrackWidth("");
//        } else {
//            fbCrystalCertificateDto.setCrackWidth("缝宽" + df.format(fbCheckOutDataDto.getCrackWidth()) + "mm");
//        }
//
//        if (fbCheckOutDataDto.getSticksCount() == null || fbCheckOutDataDto.getSticksCount() <= 1) {
//            fbCrystalCertificateDto.setSticksCount("");
//            fbCrystalCertificateDto.setCrackWidth("");
//            fbCrystalCertificateDto.setSpellBarLengthFb("");
//        } else {
//            fbCrystalCertificateDto.setSticksCount(fbCheckOutDataDto.getSticksCount() + "拼");
//            fbCrystalCertificateDto.setSpellBarLengthFb(fbCheckOutDataDto.getSpellBarLength().toString());
//        }
//
//        InspectDataBase inspectDataBase = inspectDataBaseService.findBySectionNo(fbCheckOutDataDto.getYbSectionNo());
//        if (inspectDataBase == null) {
//            throw new RuntimeException("圆棒检验数据不存在");
//        }
//        NumberBeanUtils.copyBeanProp(fbCrystalCertificateDto, inspectDataBase);
//        if (inspectDataBase.getProductTypeSecond().equals("233")) {
//            fbCrystalCertificateDto.setResistivityTopAvg(new BigDecimal(df.format(inspectDataBase.getTopCentreEdgeAvg())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getTopCentreEdgeAvg()));
//            fbCrystalCertificateDto.setResistivityEndAvg(new BigDecimal(df.format(inspectDataBase.getEndCentreEdgeAvg())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getEndCentreEdgeAvg()));
//        }
//        FbProductCard bySpecification = fbProductCardService.findBySpecification(fbCheckOutDataDto.getSpecification());
//        if (bySpecification == null) {
//            throw new RuntimeException("未查寻到产品标准卡信息");
//        }
//        NumberBeanUtils.copyBeanProp(fbCrystalCertificateDto, bySpecification);
//        fbCrystalCertificateDto.setTwRadialEdge1Avg(new BigDecimal(df2.format(inspectDataBase.getTRadialEdge1().add(inspectDataBase.getWRadialEdge1()).divide(new BigDecimal(2)))).compareTo(BigDecimal.ZERO) == 0 ? "" : df2.format(inspectDataBase.getTRadialEdge1().add(inspectDataBase.getWRadialEdge1()).divide(new BigDecimal(2))));
//
//        fbCrystalCertificateDto.setAppearanceException(this.getProductLevelFb(fbCheckOutDataDto));
//        fbCrystalCertificateDto.setSpecificationYb(inspectDataBase.getProductTypeSecond() == null ? "" : inspectDataBase.getProductTypeSecond());
//        fbCrystalCertificateDto.setActualLength(inspectDataBase.getActualLength() == null ? "" : (new BigDecimal(df.format(inspectDataBase.getActualLength())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getActualLength())));
//        String specification = fbCheckOutDataDto.getSpecification();
//        if(specification != null){
//            String[] split = specification.split("\\*");
//                if(split != null && split.length > 0){
//                specification = split[0];
//            }
//        }
//        fbCrystalCertificateDto.setSpecification(fbCheckOutDataDto.getConductionType() + "-" + specification);
//        fbCrystalCertificateDto.setDiameterMinMax((new BigDecimal(df.format(inspectDataBase.getDiameterMin())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getDiameterMin())) + "-" + (new BigDecimal(df.format(inspectDataBase.getDiameterMax())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(inspectDataBase.getDiameterMax())));
//        fbCrystalCertificateDto.setDeviceNo(fbCheckOutDataDto.getDeviceNo() == null ? "" : fbCheckOutDataDto.getDeviceNo());
//
//        //初始赋值空字符串防止打印机缓存
//        fbCrystalCertificateDto.setHeadSlope("");
//        fbCrystalCertificateDto.setTailSlope("");
//        fbCrystalCertificateDto.setEdgeBark("");
//        fbCrystalCertificateDto.setCollapseLine("");
//        fbCrystalCertificateDto.setFineCutLength("");
//        fbCrystalCertificateDto.setFineDiameter("");
//        fbCrystalCertificateDto.setAnomaly("");
//
//        if (StringUtils.isNotBlank(fbCrystalCertificateDto.getHeadSlope())) {
//            fbCrystalCertificateDto.setHeadSlope("头斜：" + fbCrystalCertificateDto.getHeadSlope());
//        }
//        if (StringUtils.isNotBlank(fbCrystalCertificateDto.getTailSlope())) {
//            fbCrystalCertificateDto.setTailSlope("尾斜：" + fbCrystalCertificateDto.getTailSlope());
//        }
//        if (StringUtils.isNotBlank(fbCrystalCertificateDto.getEdgeBark())) {
//            fbCrystalCertificateDto.setEdgeBark("崩边长度：" + fbCrystalCertificateDto.getEdgeBark());
//        }
//        if (StringUtils.isNotBlank(fbCrystalCertificateDto.getCollapseLine())) {
//            fbCrystalCertificateDto.setCollapseLine("崩晶线：" + fbCrystalCertificateDto.getCollapseLine());
//        }
//        if (StringUtils.isNotBlank(fbCrystalCertificateDto.getFineCutLength())) {
//            fbCrystalCertificateDto.setFineCutLength("细减长：" + fbCrystalCertificateDto.getFineCutLength());
//        }
//        if (StringUtils.isNotBlank(fbCrystalCertificateDto.getFineDiameter())) {
//            fbCrystalCertificateDto.setFineDiameter("细：" + fbCrystalCertificateDto.getFineDiameter());
//        }
//        if (StringUtils.isNotBlank(fbCrystalCertificateDto.getAnomaly())) {
//            fbCrystalCertificateDto.setAnomaly("异常汇总：" + fbCrystalCertificateDto.getAnomaly());
//        }
//
//        //拼棒数据集
//        List<String> lengthList = new ArrayList<>();//除主棒外的其他单晶的长度组合
//        List<String> sectionList = new ArrayList<>();//单晶组合
//        List<String> squareRodRemarkList = new ArrayList<>();//除主棒外的其他方棒备注
//        List<String> headSlopeList = new ArrayList<>();//除主棒外头斜
//        List<String> tailSlopeList = new ArrayList<>();//除主棒外尾斜
//        List<String> edgeBarkList = new ArrayList<>();//除主棒外崩边长度
//        List<String> collapseLineList = new ArrayList<>();//除主棒外崩晶线
//        List<String> fineCutLengthList = new ArrayList<>();//除主棒外细减长
//        List<String> fineDiameterList = new ArrayList<>();//除主棒外细
//        List<String> anomalyList = new ArrayList<>();//除主棒外异常汇总
//        List<String> appearanceExceptionList = new ArrayList<>();//除主棒外外观异常汇总
//
//        //标记拼棒是否有二类
//        boolean hasTwo = false;
//        //标记拼棒是否有反切
//        boolean hasCutBack = false;
//        for (FbCheckOutDataDto fbCheckOutDataNew : fbCheckOutDataDtoList) {
//            if ("反切".equals(fbCheckOutDataNew.getProductLevelFb())){
//                hasCutBack = true;
//            }
//            if ("二类".equals(fbCheckOutDataNew.getProductLevelFb())){
//                hasTwo = true;
//            }
//            sectionList.add(fbCheckOutDataNew.getFbSectionNo());
//            if (!fbCheckOutDataNew.getFbSectionNo().equals(fbCrystalCertificateDto.getFbSectionNo())){
//                FbCrystalCertificateDto fbCrystalCertificateDtoNew = new FbCrystalCertificateDto();
//                //赋值
//                NumberBeanUtils.copyBeanProp(fbCrystalCertificateDtoNew, fbCheckOutDataNew);
//                //其他单晶检验数据
//                InspectDataBase inspectDataBaseNew = inspectDataBaseService.findBySectionNo(fbCheckOutDataNew.getYbSectionNo());
//                if (inspectDataBaseNew != null) {
//                    NumberBeanUtils.copyBeanProp(fbCrystalCertificateDtoNew, inspectDataBaseNew);
//                }
//                //其他单晶产品标准卡信息
//                FbProductCard bySpecificationNew = fbProductCardService.findBySpecification(fbCheckOutDataNew.getSpecification());
//                if (bySpecificationNew != null) {
//                    //todo 会将规格重置为298*247
//                    NumberBeanUtils.copyBeanProp(fbCrystalCertificateDtoNew, bySpecificationNew);
//                }
//
//                //"方棒长度-异常总和"
//                fbCrystalCertificateDtoNew.setLength(new BigDecimal(df.format(fbCheckOutDataNew.getLength())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(fbCheckOutDataNew.getLength()));
//                if (fbCheckOutDataNew.getProductLevelFb() != null && "正常".equals(fbCheckOutDataNew.getProductLevelFb()) && fbCheckOutDataNew.getAbnormalSum() != null && fbCheckOutDataNew.getAbnormalSum().compareTo(BigDecimal.ZERO) != 0) {
//                    fbCrystalCertificateDtoNew.setLength((new BigDecimal(df.format(fbCheckOutDataNew.getLength())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(fbCheckOutDataNew.getLength())) + "-" + (new BigDecimal(df.format(fbCheckOutDataNew.getAbnormalSum())).compareTo(BigDecimal.ZERO) == 0 ? "" : df.format(fbCheckOutDataNew.getAbnormalSum())));
//                }
//                appearanceExceptionList.add(getProductLevelFb(fbCheckOutDataNew));
//                lengthList.add(fbCrystalCertificateDtoNew.getLength());
//                if (StringUtils.isNotBlank(fbCrystalCertificateDtoNew.getSquareRodRemark())){
//                    squareRodRemarkList.add(fbCrystalCertificateDtoNew.getSquareRodRemark());
//                }
//                if (StringUtils.isNotBlank(fbCrystalCertificateDtoNew.getHeadSlope())) {
//                    headSlopeList.add(fbCrystalCertificateDtoNew.getHeadSlope());
//                }
//                if (StringUtils.isNotBlank(fbCrystalCertificateDtoNew.getTailSlope())) {
//                    tailSlopeList.add(fbCrystalCertificateDtoNew.getTailSlope());
//                }
//                if (StringUtils.isNotBlank(fbCrystalCertificateDtoNew.getEdgeBark())) {
//                    edgeBarkList.add(fbCrystalCertificateDtoNew.getEdgeBark());
//                }
//                if (StringUtils.isNotBlank(fbCrystalCertificateDtoNew.getCollapseLine())) {
//                    collapseLineList.add(fbCrystalCertificateDtoNew.getCollapseLine());
//                }
//                if (StringUtils.isNotBlank(fbCrystalCertificateDtoNew.getFineCutLength())) {
//                    fineCutLengthList.add(fbCrystalCertificateDtoNew.getFineCutLength());
//                }
//                if (StringUtils.isNotBlank(fbCrystalCertificateDtoNew.getFineDiameter())) {
//                    fineDiameterList.add(fbCrystalCertificateDtoNew.getFineDiameter());
//                }
//                if (StringUtils.isNotBlank(fbCrystalCertificateDtoNew.getAnomaly())) {
//                    anomalyList.add(fbCrystalCertificateDtoNew.getAnomaly());
//                }
//            }
//        }
//
//        /**
//         * 非拼棒：
//         *   正常不显示，其他类型显示当前值；
//         * 拼棒：
//         *   都是正常，不显示
//         *   都是二类，显示二类
//         *   有正常，有二类，显示二类
//         *   都是反切，显示反切
//         *   有二类有反切，显示 反切
//         *   有正常 有二类 有返切，显示 反切
//         *   也就说，各种组合关系里，优先级最高的是反切 ，其次是二类
//         */
//        if(fbCheckOutDataDtoList.size() > 1){
//            if(hasCutBack){
//                fbCrystalCertificateDto.setProductLevelFb("反切");
//            }else if(hasTwo){
//                fbCrystalCertificateDto.setProductLevelFb("二类");
//            }else{
//                fbCrystalCertificateDto.setProductLevelFb("");
//            }
//        }else{
//            if ("正常".equals(fbCheckOutDataDto.getProductLevelFb())) {
//                fbCrystalCertificateDto.setProductLevelFb("");
//            } else {
//                fbCrystalCertificateDto.setProductLevelFb(fbCheckOutDataDto.getProductLevelFb());
//            }
//        }
//
//
//        //初始赋值空字符串防止打印机缓存
//        fbCrystalCertificateDto.setLengthList("");
//        fbCrystalCertificateDto.setSquareRodRemarkList("");
//        fbCrystalCertificateDto.setSectionList("");
//        fbCrystalCertificateDto.setAppearanceExceptionList("");
//        fbCrystalCertificateDto.setHeadSlopeList("");
//        fbCrystalCertificateDto.setTailSlopeList("");
//        fbCrystalCertificateDto.setEdgeBarkList("");
//        fbCrystalCertificateDto.setCollapseLineList("");
//        fbCrystalCertificateDto.setFineCutLengthList("");
//        fbCrystalCertificateDto.setAnomalyList("");
//        fbCrystalCertificateDto.setFineDiameterList("");
//
//        if (lengthList != null && lengthList.size() > 0) {
//            fbCrystalCertificateDto.setLengthList("拼棒：" + String.join(",",lengthList));
//        }
//        if (squareRodRemarkList != null && squareRodRemarkList.size() > 0) {
//            fbCrystalCertificateDto.setSquareRodRemarkList("拼棒：" +String.join(",",squareRodRemarkList));
//        }
//        if (sectionList != null && sectionList.size() > 1) {
//            fbCrystalCertificateDto.setSectionList(String.join(",",sectionList));
//        }
//        if (appearanceExceptionList != null && appearanceExceptionList.size() > 0) {
//            fbCrystalCertificateDto.setAppearanceExceptionList("拼棒：" + String.join(",",appearanceExceptionList));
//        }
//        if (headSlopeList != null && headSlopeList.size() > 0) {
//            fbCrystalCertificateDto.setHeadSlopeList("头斜：" + String.join(",",headSlopeList));
//        }
//        if (tailSlopeList != null && tailSlopeList.size() > 0) {
//            fbCrystalCertificateDto.setTailSlopeList("尾斜：" + String.join(",",tailSlopeList));
//        }
//        if (edgeBarkList != null && edgeBarkList.size() > 0) {
//            fbCrystalCertificateDto.setEdgeBarkList("崩边长度：" + String.join(",",edgeBarkList));
//        }
//        if (collapseLineList != null && collapseLineList.size() > 0) {
//            fbCrystalCertificateDto.setCollapseLineList("崩晶线：" + String.join(",",collapseLineList));
//        }
//        if (fineCutLengthList != null && fineCutLengthList.size() > 0) {
//            fbCrystalCertificateDto.setFineCutLengthList("细减长：" + String.join(",",fineCutLengthList));
//        }
//        if (fineDiameterList != null && fineDiameterList.size() > 0) {
//            fbCrystalCertificateDto.setFineDiameterList("细：" + String.join(",",fineDiameterList));
//        }
//        if (anomalyList != null && anomalyList.size() > 0) {
//            fbCrystalCertificateDto.setAnomalyList("异常汇总：" + String.join(",",anomalyList));
//        }
//
//
//        List list = new ArrayList();
//        list.add(fbCrystalCertificateDto);
//
//
//        preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview()));
//        return preview;
//    }
    //endregion

    /**
     * 打印方棒反切标签
     *
     * @param docketPrintDto
     */
    private List<String> printFbReCuttingLabel(DocketPrintDto docketPrintDto) {
        List<String> preview = new ArrayList<>();
        //查询方棒检验信息
        Result dataByFbSectionNo = fbFeignClients.findDataByFbSectionNo(docketPrintDto.getCode());
        if (dataByFbSectionNo.getCode() != 200) {
            throw new RuntimeException("请求方棒服务失败");
        }
        //       FbCheckOutDataDto fbCheckOutDataDto = JSONObject.parseObject(JSONObject.toJSONString(dataByFbSectionNo.getData()), FbCheckOutDataDto.class);

        //方棒晶段信息
        //       RecutDetail recutDetail = recutDetailService.findBySectionNoFb(docketPrintDto.getCode());
//        List<ProductionPaintingLineDetail> productionPaintingLineDetailList = productionPaintingLineDetailService.findByCrystalId(recutDetail.getCrystalId());

        List<Map<String, String>> printKeyValuess = new LinkedList<>();
        //反切划线信息
        ReCut reCut = fbReCutService.findReCutInfoBySectionNo(docketPrintDto.getCode());
        //反切划线信息详情
        List<ProductionPaintingLineDetail> productionPaintingLineDetailList1 = productionPaintingLineDetailService.findByOperateRecutDrawIdFb(reCut.getId());

        BigDecimal weightRatio = null;
        //圆棒理论折算系数
        if (StringUtils.isNotBlank(reCut.getSpecs())) {
            List<DictionaryItem> dictionaryItems = dictionaryItemService.findByThemeValueAndItemName(Constants.THEORETICAL_WEIGHT_COEFFICIENTFB, reCut.getSpecs(), true);
            weightRatio = NumberUtil.Object2BigDecimal(dictionaryItems.get(0).getValue());
        }
        for (ProductionPaintingLineDetail paintingLineDetail : productionPaintingLineDetailList1) {
//            if ((null == docketPrintDto.getIsPrint() || !docketPrintDto.getIsPrint()) && paintingLineDetail.getType().equals(EnumValuesServer.LineType.回收料.getKey())) {
//                continue;
//            }
            Map<String, String> map = new HashMap<>();
            if (null == paintingLineDetail.getLength()) {
                map.put("length", "0");
            } else {
                map.put("length", df.format(paintingLineDetail.getLength()));
            }
            map.put("fbNo", paintingLineDetail.getNo());
            map.put("reason", paintingLineDetail.getReason());
            if (paintingLineDetail.getType() == null) {
                map.put("type", " ");
            } else if (paintingLineDetail.getType() == EnumValuesServer.LineType.回收料.getKey()) {
                map.put("type", "回收料");
            } else if (paintingLineDetail.getType() == EnumValuesServer.LineType.晶段.getKey()) {

                if (null != paintingLineDetail.getWeight()) {
                    map.put("weight", paintingLineDetail.getWeight().intValue() + "");
                } else {
                    if (null != paintingLineDetail.getLength() && null != weightRatio) {
                        map.put("weight", paintingLineDetail.getLength().divide(weightRatio, 3, BigDecimal.ROUND_HALF_UP).intValue() + "");
                    }
                }
                map.put("type", "晶段");
            } else if (paintingLineDetail.getType() == EnumValuesServer.LineType.样片.getKey()) {
                map.put("type", "样片");
            }

            printKeyValuess.add(map);
        }

        preview.addAll(this.doPrint(docketPrintDto.getPrintModel(), printKeyValuess, docketPrintDto.getIsPreview(), 1));
        return preview;

    }


    @Override
    public Map<String, List<String>> crystallonPrint(List<DocketPrintDto> docketPrintDtoList) {
        //打印日志
        List<PrinterLog> printerLogList = new ArrayList<>();
        Map<String, List<String>> stringListMap = new HashMap<>();
        // 存放不同单晶下籽晶
        if (docketPrintDtoList.size() > 0) {
            for (DocketPrintDto docketPrintDto : docketPrintDtoList) {
                // 存放同一个单晶编号下的籽晶

                CrystallonData crystallonData = crystallonDataService.findByCrystallonNo(docketPrintDto.getCode());
                if (null != crystallonData) {
                    SinglePrinter(crystallonData, stringListMap, docketPrintDto, printerLogList);
                } else {
                    throw new BusinessException("无籽晶信息：" + docketPrintDto.getCode());
                }
            }
        }
        this.saveLog(printerLogList);

        return stringListMap;
    }

    public List<String> crystallonSinglePrint(DocketPrintDto docketPrintDto) {
        List<CrystallonData> crystallonDataList = crystallonDataService.findByCrystalNo(docketPrintDto.getCode());
        List<String> preview = new ArrayList<>();
        if (null != crystallonDataList && crystallonDataList.size() > 0) {
            for (CrystallonData crystallonData : crystallonDataList) {
                List<Map<String, String>> list = new ArrayList<>();
                Map<String, String> map = new HashMap<>();
                // 籽晶编号
                String crystallonNo = crystallonData.getCrystallonNo();
                map.put("crystallonNo", crystallonNo);
                // 籽晶长度
                map.put("crystallonLength", crystallonData.getCrystallonLength().toString());
                list.add(map);
                /**
                 * docketPrintDto.getPrintModel() 打印模板
                 * list                             打印数据
                 * docketPrintDto.getIsPreview()    是否预览
                 * docketPrintDto.getPrintNum()     数量
                 */
                List<String> list1 = this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview(), docketPrintDto.getPrintNum());
                preview.addAll(list1);

            }
        } else {
            throw new BusinessException("该单晶无籽晶信息：" + docketPrintDto.getCode());
        }
        return preview;
    }


    /**
     * 打印单条籽晶
     *
     * @param crystallonData
     * @param stringListMap
     * @param docketPrintDto
     * @param printerLogList
     */
    private void SinglePrinter(CrystallonData crystallonData, Map<String, List<String>> stringListMap, DocketPrintDto docketPrintDto, List<PrinterLog> printerLogList) {
        try {
            List<Map<String, String>> list = new ArrayList<>();
            Map<String, String> map = new HashMap<>();
            // 籽晶编号
            String crystallonNo = crystallonData.getCrystallonNo();
            map.put("crystallonNo", crystallonNo);
            // 籽晶长度
            map.put("crystallonLength", crystallonData.getCrystallonLength().toString());
            list.add(map);
            /**
             * docketPrintDto.getPrintModel() 打印模板
             * list                             打印数据
             * docketPrintDto.getIsPreview()    是否预览
             * docketPrintDto.getPrintNum()     数量
             */
            List<String> preview = this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview(), docketPrintDto.getPrintNum());
            stringListMap.put(crystallonData.getCrystallonNo(), preview);

        } catch (Exception e) {
            log.error(" 籽晶打印异常： " + crystallonData + " 异常信息：" + e.getMessage());
        }
        //打印日志
        PrinterLog printerLog = this.initPrinterLog(docketPrintDto, false, JSONObject.toJSONString(crystallonData));
        printerLogList.add(printerLog);
    }

    /**
     * 打印方棒唛头
     *
     * @param docketPrintDto
     */
    private List<String> printFbShippingMark(DocketPrintDto docketPrintDto) {
        // TODO: 2022/1/21 取消开发
        return null;
    }


    /**
     * 通过托号获取清洗组托信息
     * 打印清洗硅料-无尘组托
     *
     * @param docketPrintDto
     * @return
     */
    public List<String> cleanGroupPrint(DocketPrintDto docketPrintDto) {
        Result cleanGroupNo = cleanFeignClients.findDataByCleanGroupNo(docketPrintDto.getCode());
        if (cleanGroupNo.getCode() != 200) {
            throw new RuntimeException(cleanGroupNo.getMessage());
        }
        MaterialGroupInfoDto materialGroupDto = JSONObject.parseObject(JSONObject.toJSONString(cleanGroupNo.getData()), MaterialGroupInfoDto.class);

        List<String> preview = new ArrayList<>();
        //封装打印数据
        //字段需要与物料主数据对齐
        List<MaterialModel> materialModelList = materialModelService.findMaterialModelByCode(materialGroupDto.getMaterialCode());
        if (null == materialModelList || materialModelList.size() == 0) {
            throw new BusinessException("该料号不存在，请检查");
        }
        MaterialModel materialModel = materialModelList.get(0);

        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("directionalSign", materialModel.getDirectionalSign());
        map.put("groupNo", materialGroupDto.getGroupNo());
        map.put("productBatchNo", materialGroupDto.getProductBatchNo());
        map.put("materialCode", materialGroupDto.getMaterialCode());
        map.put("materialName", materialGroupDto.getMaterialName());
        map.put("materialLevel", materialModel.getProductLevel());
        map.put("weight", String.valueOf(materialGroupDto.getWeight()));
        map.put("specification", materialModel.getSpecification());
        map.put("suppliesGrain", materialGroupDto.getSuppliesGrain());
        map.put("materialGear", materialGroupDto.getMaterialGear());
        map.put("classNo", BaseContextHandler.getUserClassNo());
        map.put("use", "");
        map.put("createTime", new SimpleDateFormat("yyyy-MM-dd").format(materialGroupDto.getCreateTime()));
        map.put("warehousingTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(materialGroupDto.getWarehousingTime()));
        map.put("factory", "山西太原");
        map.put("remark", null == materialGroupDto.getRemark() ? "" : materialGroupDto.getRemark());
        list.add(map);

        preview = this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview(), docketPrintDto.getPrintNum());
        return preview;
    }

    /**
     * 通过分选pp号获取分选信息
     * 打印清洗硅料-分选信息
     *
     * @param docketPrintDto
     * @return
     */
    private List<String> cleanUnpackingPrint(DocketPrintDto docketPrintDto) {
        Result result = cleanFeignClients.getInfoByFxProductBatchNo(docketPrintDto.getCode());
        if (result.getCode() != 200) {
            throw new RuntimeException(result.getMessage());
        }
        FxToBoxInfoDto boxInfoDto = JSONObject.parseObject(JSONObject.toJSONString(result.getData()), FxToBoxInfoDto.class);

        List<String> preview = new ArrayList<>();
        //封装打印数据
        //字段需要与物料主数据对齐
        List<MaterialModel> materialModelList = materialModelService.findMaterialModelByCode(boxInfoDto.getMaterialCode());
        if (null == materialModelList || materialModelList.size() == 0) {
            throw new BusinessException("该料号不存在，请检查");
        }
        MaterialModel materialModel = materialModelList.get(0);

        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("boxNo", boxInfoDto.getBoxNo());
        map.put("fxProductBatchNo", boxInfoDto.getFxProductBatchNo());
        map.put("productBatchNo", boxInfoDto.getProductBatchNo());
        map.put("fromMark", boxInfoDto.getFromMark());
        map.put("materialName", boxInfoDto.getMaterialName());
        map.put("materialCode", boxInfoDto.getMaterialCode());
        map.put("createTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(boxInfoDto.getCreateTime()));
        map.put("weight", String.valueOf(boxInfoDto.getWeight()));
        map.put("materialModel", boxInfoDto.getMaterialModel());
        map.put("materialGear", boxInfoDto.getMaterialGear());
        map.put("materialLevel", boxInfoDto.getMaterialLevel());
        map.put("remark", null == boxInfoDto.getRemark() ? "" : boxInfoDto.getRemark());
        map.put("classNo", BaseContextHandler.getUserClassNo());
        list.add(map);

        preview = this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview(), docketPrintDto.getPrintNum());
        return preview;
    }


    /**
     * 通过返工批次号获取返工信息
     * * 打印清洗硅料-返工信息
     *
     * @param docketPrintDto
     * @return
     */
    private List<String> cleanReworkPrint(DocketPrintDto docketPrintDto) {

        Result result = cleanFeignClients.findDataByProductBatchNo(docketPrintDto.getCode());
        if (result.getCode() != 200) {
            throw new RuntimeException(result.getMessage());
        }
        List<String> preview = new ArrayList<>();
        //封装打印数据
        CleanReworkingDto cleanReworkingDto = JSONObject.parseObject(JSONObject.toJSONString(result.getData()), CleanReworkingDto.class);

        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("boxNo", cleanReworkingDto.getMaterialBoxNo());
        map.put("productBatchNo", cleanReworkingDto.getProductBatchNo());
        map.put("materialName", cleanReworkingDto.getMaterialName());
        map.put("materialCode", cleanReworkingDto.getMaterialCode());
        map.put("createTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cleanReworkingDto.getCreateDate()));
        map.put("weight", String.valueOf(cleanReworkingDto.getWeight()));
        map.put("materialGear", cleanReworkingDto.getMaterialGear());
        map.put("materialLevel", cleanReworkingDto.getMaterialLevel());
        map.put("workOrderNo", cleanReworkingDto.getWorkOrderNo());
        map.put("remark", "");
        map.put("classNo", BaseContextHandler.getUserClassNo());
        map.put("createUser", BaseContextHandler.getUsername());
        list.add(map);

        preview = this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview(), docketPrintDto.getPrintNum());
        return preview;
    }

    /**
     * 通过回收料批号查询信息
     * 打印余料组托信息
     *
     * @param docketPrintDto
     * @return
     */
    private List<String> recycledGroupPrint(DocketPrintDto docketPrintDto) {
        RecycledMaterialManage materialManage = recycledMaterialManageService.getByProduceBatchNo(docketPrintDto.getCode());

        List<String> preview = new ArrayList<>();
        //封装打印数据

        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("boxNo", materialManage.getBoxNo());
        map.put("productBatchNo", materialManage.getProduceBatchNo());
        map.put("dateProductBatchNo", materialManage.getDateProduceBatchNo());
        map.put("materialName", materialManage.getMaterialName());
        map.put("materialCode", materialManage.getMaterialCode());
        map.put("createTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(materialManage.getCreateTime()));
        map.put("weight", String.valueOf(materialManage.getWeight()));
        map.put("materialGear", materialManage.getGear());
        map.put("materialLevel", materialManage.getGrade());
        map.put("workOrderNo", materialManage.getWorkOrderNo());
        if ("2".equals(materialManage.getKostl())) {
            map.put("workOrderNo", "");
        }
        map.put("remark", "");
        map.put("classNo", BaseContextHandler.getUserClassNo());
        map.put("createUser", BaseContextHandler.getUsername());
        list.add(map);

        preview = this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview(), docketPrintDto.getPrintNum());
        return preview;
    }

    /**
     * 通过回收料批号查询信息
     * 打印余料组托信息
     * pda
     *
     * @param docketPrintDto
     * @return
     */
    @Override
    public List<String> recycledGroupPrint(DocketPrintRecycledInfoDto docketPrintDto) {
        RecycledMaterialManage materialManage = recycledMaterialManageService.getByProduceBatchNo(docketPrintDto.getCode());
        List<String> preview;
        //封装打印数据
        List<Map> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("boxNo", materialManage.getBoxNo());
        map.put("productBatchNo", materialManage.getProduceBatchNo());
        map.put("dateProductBatchNo", materialManage.getDateProduceBatchNo());
        map.put("materialName", materialManage.getMaterialName());
        map.put("materialCode", materialManage.getMaterialCode());
        map.put("createTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(materialManage.getCreateTime()));
        map.put("weight", String.valueOf(materialManage.getWeight()));
        map.put("materialGear", materialManage.getGear());
        map.put("materialLevel", materialManage.getGrade());
        map.put("workOrderNo", materialManage.getWorkOrderNo());
        if ("2".equals(materialManage.getKostl())) {
            map.put("workOrderNo", "");
        }
        map.put("remark", "");
        map.put("classNo", BaseContextHandler.getUserClassNo());
        map.put("createUser", BaseContextHandler.getUsername());
        list.add(map);
        preview = this.doPrint(docketPrintDto.getPrintModel(), list, docketPrintDto.getIsPreview(), docketPrintDto.getPrintNum());
        return preview;
    }


    //打印
    private List<String> doPrint(String printModelType, List dataList, Boolean isPreview) {
        List<String> previews = new ArrayList<>();
        if (isPreview == null) {
            isPreview = false;
        }
        //查询打印模板
        DocumentPrint documentPrint = documentMouldService.findByDocumentMould(printModelType);
        if (documentPrint == null) {
            throw new RuntimeException("打印模板【" + printModelType + "】不存在");
        }
        //填充打印信息
        PrintInfoDto printInfoDto = new PrintInfoDto();
        printInfoDto.setPrinterName(documentPrint.getPrintName());
        printInfoDto.setTemplateAddress(documentPrint.getDocumentPath());
        printInfoDto.setDocIp(documentPrint.getPrintIp());
        printInfoDto.setData(JSON.toJSONString(dataList));
        //执行打印
        Result<String> print;
        if (isPreview) {
            //printInfoDto.setDocIp("10.221.236.54");
            print = printService.printShow(printInfoDto);
            if (print.getCode() == ResultCode.SUCCESS.getCode()) {
                if (print.getData().contains("[")) {
                    previews.addAll(JSON.parseArray(print.getData(), String.class));
                } else {
                    previews.add(print.getData());
                }
            }
        } else {
            print = printService.print(printInfoDto);
            previews.add(printInfoDto.getData());
        }
        if (print == null) {
            throw new RuntimeException("请求打印机失败:" + "返回结果为null");
        }
        if (print.getCode() != ResultCode.SUCCESS.getCode()) {
            throw new RuntimeException("请求打印机失败:" + print.getMessage());
        }
        return previews;
    }

    //打印多张
    private List<String> doPrint(String printModelType, List dataList, Boolean isPreview, Integer printNum) {
        List<String> previews = new ArrayList<>();
        if (isPreview == null) {
            isPreview = false;
        }
        //查询打印模板
        DocumentPrint documentPrint = documentMouldService.findByDocumentMould(printModelType);
        if (documentPrint == null) {
            throw new RuntimeException("打印模板【" + printModelType + "】不存在");
        }
        //填充打印信息
        PrintInfoDto printInfoDto = new PrintInfoDto();
        printInfoDto.setPrinterName(documentPrint.getPrintName());
        printInfoDto.setTemplateAddress(documentPrint.getDocumentPath());
        printInfoDto.setDocIp(documentPrint.getPrintIp());
        printInfoDto.setData(JSON.toJSONString(dataList));
        printInfoDto.setPrintNum(printNum);
        //执行打印
        Result<String> print;
        if (isPreview) {
            //printInfoDto.setDocIp("10.221.236.54");
            print = printService.printShow(printInfoDto);
            if (print.getCode() == ResultCode.SUCCESS.getCode()) {
                if (print.getData().contains("[")) {
                    previews.addAll(JSON.parseArray(print.getData(), String.class));
                } else {
                    previews.add(print.getData());
                }
            }
        } else {
            print = printService.print(printInfoDto);
            previews.add(printInfoDto.getData());
        }
        if (print == null) {
            throw new RuntimeException("请求打印机失败:" + "返回结果为null");
        }
        if (print.getCode() != ResultCode.SUCCESS.getCode()) {
            throw new RuntimeException("请求打印机失败:" + print.getMessage());
        }
        return previews;
    }

    /**
     * 初始化打印日志
     *
     * @param docketPrintDto
     * @param isSuccessful   是否打印成功
     * @return
     */
    private PrinterLog initPrinterLog(DocketPrintDto docketPrintDto, boolean isSuccessful, String detail) {
        PrinterLog printerLog = new PrinterLog();
        printerLog.setCode(docketPrintDto.getCode());
        printerLog.setIsDelete(false);
        printerLog.setCreateTime(new Date());
        printerLog.setCreateUser(BaseContextHandler.getUsername());
        printerLog.setCreateUserId(BaseContextHandler.getUserID());
        printerLog.setModel(docketPrintDto.getPrintModel());
        printerLog.setType(docketPrintDto.getPrintType());
        printerLog.setIsSuccessful(isSuccessful);
        printerLog.setDetail(detail);
        if (detail != null && detail.length() > 2000) {
            printerLog.setDetail(detail.substring(0, 2000));
        }
        return printerLog;

    }

    /**
     * 获取外观异常项
     *
     * @param fbCheckOutDataDto
     * @return
     */
    private String getProductLevelFb(FbCheckOutDataDto fbCheckOutDataDto) {
        StringBuilder s = new StringBuilder();
        if (!this.isNullOrZ(fbCheckOutDataDto.getLineScratch())) {
            s.append("线痕:-" + df.format(fbCheckOutDataDto.getLineScratch()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getScratch())) {
            s.append("划痕:-" + df.format(fbCheckOutDataDto.getScratch()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getKnifeScratch())) {
            s.append("刀痕:-" + df.format(fbCheckOutDataDto.getKnifeScratch()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getCollapseLoss())) {
            s.append("崩损:-" + df.format(fbCheckOutDataDto.getCollapseLoss()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getDamageGreyHideEdge())) {
            s.append("崩损灰皮边缘:-" + df.format(fbCheckOutDataDto.getDamageGreyHideEdge()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getBrokenGreyNoEdge())) {
            s.append("崩损灰皮非边缘:-" + df.format(fbCheckOutDataDto.getBrokenGreyNoEdge()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getNoFriction())) {
            s.append("未磨到:-" + df.format(fbCheckOutDataDto.getNoFriction()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getCrystalGrayness())) {
            s.append("晶体灰皮:-" + df.format(fbCheckOutDataDto.getCrystalGrayness()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getSquareRodGrayness())) {
            s.append("方棒灰皮:-" + df.format(fbCheckOutDataDto.getSquareRodGrayness()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getGreyHideEdge())) {
            s.append("灰皮边缘:-" + df.format(fbCheckOutDataDto.getGreyHideEdge()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getGreyHideCenter())) {
            s.append("灰皮非边缘:-" + df.format(fbCheckOutDataDto.getGreyHideCenter()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getCrack())) {
            s.append("裂纹:-" + df.format(fbCheckOutDataDto.getCrack()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getSizeException())) {
            s.append("尺寸异常:-" + df.format(fbCheckOutDataDto.getSizeException()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getWaterMark())) {
            s.append("水印:-" + df.format(fbCheckOutDataDto.getWaterMark()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getHotSpot())) {
            s.append("亮斑:-" + df.format(fbCheckOutDataDto.getHotSpot()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getRidgeBroken())) {
            s.append("棱崩:-" + df.format(fbCheckOutDataDto.getRidgeBroken()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getYinYangFace())) {
            s.append("阴阳面:-" + df.format(fbCheckOutDataDto.getYinYangFace()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getWheelHighLights())) {
            s.append("砂轮亮点:-" + df.format(fbCheckOutDataDto.getWheelHighLights()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getRoundHandle())) {
            s.append("外圆手感:-" + df.format(fbCheckOutDataDto.getRoundHandle()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getFlatHandle())) {
            s.append("平面手感:-" + df.format(fbCheckOutDataDto.getFlatHandle()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getWheelMark())) {
            s.append("砂轮印:-" + df.format(fbCheckOutDataDto.getWheelMark()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getColourDifference())) {
            s.append("色差:-" + df.format(fbCheckOutDataDto.getColourDifference()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getCollapse())) {
            s.append("塌边:-" + df.format(fbCheckOutDataDto.getCollapse()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getRollerPrint())) {
            s.append("滚轮印:-" + df.format(fbCheckOutDataDto.getRollerPrint()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getHeadSlope())) {
            s.append("头斜:-" + df.format(fbCheckOutDataDto.getHeadSlope()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getTailSlope())) {
            s.append("尾斜:-" + df.format(fbCheckOutDataDto.getTailSlope()) + "mm;");
        }
        if (!this.isNullOrZ(fbCheckOutDataDto.getLengthSlope())) {
            s.append("长度斜:-" + df.format(fbCheckOutDataDto.getLengthSlope()) + "mm;");
        }

        return s.toString();
    }

    public Boolean isNullOrZ(BigDecimal b) {
        if (b == null) {
            return true;
        }
        if (new BigDecimal(df.format(b)).compareTo(BigDecimal.ZERO) == 0) {
            return true;
        }
        return false;
    }

    /**
     * 通过边距获得字典中的边宽
     *
     * @param sideLengthRange
     * @return
     */
    private String getMultipleSideLogic(String sideLengthRange) {
        //边宽
        String multipleSideLogic = "";
        if (StringUtils.isNotBlank(sideLengthRange)) {
//            multipleSideLogic = dictionaryItemService.findExtendValue1ByThemeValueAndItemName("multipleSideLogic", sideLengthRange);
            List<String> list = dictionaryItemService.findExtendValue1ByThemeValueAndItemNameV2("multipleSideLogic", sideLengthRange);
            if (!list.isEmpty()) {
                return list.get(0);
            }
        }
        return multipleSideLogic;
    }

}
