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

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.sw.mes.base.system.entity.DictionaryItem;
import com.sw.mes.base.system.entity.InventoryManageLog;
import com.sw.mes.base.system.service.DictionaryItemService;
import com.sw.mes.base.workinprocess.dao.PlanProcessingOrderDao;
import com.sw.mes.base.workinprocess.dto.WipProcessDetailedInfoDto;
import com.sw.mes.base.workinprocess.service.PlanProcessingOrderService;
import com.sw.mes.base.workinprocess.service.WipStorageService;
import com.sw.mes.core.dto.sap.ReportSapChargItemDto;
import com.sw.mes.core.dto.sap.ReportSapGoodsmvtDto;
import com.sw.mes.core.entity.SearchFilter;
import com.sw.mes.core.enums.EnumValuesFactory;
import com.sw.mes.core.response.ResponsePage;
import com.sw.mes.core.utils.DynamicSpecifications;
import com.sw.mes.core.utils.PageUtil;
import com.sw.mes.core.utils.RequestPage;
import com.sw.mes.sap.entity.ReportSapGoodsmvt;
import com.sw.mes.sap.service.ReportSapGoodsmvtService;
import com.sw.mes.yb.plan.entity.ProductionOrder;
import com.sw.mes.yb.plan.service.ProductionOrderService;
import com.sw.mes.yb.production.entity.AgainTaskDetail;
import com.sw.mes.yb.production.entity.BlastFurnaceDetail;
import com.sw.mes.yb.production.entity.InputFurnaceDetail;
import com.sw.mes.yb.production.entity.LoadingTask;
import com.sw.mes.yb.production.service.*;
import com.sw.mes.yb.report.dto.WorkOrderProgressReportDto;
import com.sw.mes.yb.report.service.WorkOrderProgressReportService;
import javafx.scene.layout.BackgroundImage;
import org.apache.commons.lang3.StringUtils;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.ServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author JS107742
 */
@Service
@Transactional
public class WorkOrderProgressReportServiceImpl implements WorkOrderProgressReportService {

    @Autowired
    ModelMapper modelMapper;

    @Autowired
    private ReportSapGoodsmvtService reportSapGoodsmvtService;

    @Autowired
    private ProductionOrderService productionOrderService;

    @Autowired
    private DictionaryItemService dictionaryItemService;

    @Autowired
    private PlanProcessingOrderService planProcessingOrderService;

    @Autowired
    private WipStorageService wipStorageService;

    @Override
    public List<WorkOrderProgressReportDto> findOrderProgress(WorkOrderProgressReportDto workOrderProgressReportDto){

        List<WorkOrderProgressReportDto> totalWorkOrderProgressReportDtoList = new ArrayList<>();
        List<WorkOrderProgressReportDto> receiptOfGoods = new ArrayList<>();
        List<WorkOrderProgressReportDto> consumptionWorks = new ArrayList<>();
        List<WorkOrderProgressReportDto> byProductWorkOrder = new ArrayList<>();
        EnumValuesFactory.OrderProgress orderProgress = EnumValuesFactory.OrderProgress.getOrderProgress(workOrderProgressReportDto.getField4());

        List<DictionaryItem> factoryWorkType = dictionaryItemService.findByThemeValueAndEnable("factoryWorkType", true);
        Map<String, String> collect = factoryWorkType.stream().collect(Collectors.toMap(DictionaryItem::getName, DictionaryItem::getValue));

        List<String> consumeOrderTypeBwarts = new ArrayList<>();
        List<String> reciveOrderTypeBwarts = new ArrayList<>();
        List<String> byOrderTypeBwarts = new ArrayList<>();
        consumeOrderTypeBwarts.add("261");
        consumeOrderTypeBwarts.add("262");
        reciveOrderTypeBwarts.add("101");
        reciveOrderTypeBwarts.add("102");
        byOrderTypeBwarts.add("531");
        byOrderTypeBwarts.add("532");

        //查询方棒检验数据库
        switch (orderProgress) {
            case 单晶:
                Integer integer = Integer.valueOf(collect.get(EnumValuesFactory.OrderProgress.拉晶.getValue()));
                List<ProductionOrder> byWorkTypeAndTime = productionOrderService.findByWorkTypeAndTimeAndStatus(integer, workOrderProgressReportDto.getGstrp(), workOrderProgressReportDto.getGltrp(), workOrderProgressReportDto.getStatus());
                receiptOfGoods = encapsulatedData(workOrderProgressReportDto, EnumValuesFactory.OrderProgress.拉晶.getValue(), EnumValuesFactory.OrderProgress.单晶收货.getValue(), EnumValuesFactory.OrderProgress.拉晶余料.getValue(), byWorkTypeAndTime, consumeOrderTypeBwarts, reciveOrderTypeBwarts, byOrderTypeBwarts);
                break;
            case 截断:
                Integer jdType = Integer.valueOf(collect.get(EnumValuesFactory.OrderProgress.截断.getValue()));
                List<ProductionOrder> jdOrderNo = productionOrderService.findByWorkTypeAndTimeAndStatus(jdType, workOrderProgressReportDto.getGstrp(), workOrderProgressReportDto.getGltrp(), workOrderProgressReportDto.getStatus());
                receiptOfGoods = encapsulatedData(workOrderProgressReportDto, EnumValuesFactory.OrderProgress.截断消耗.getValue(), EnumValuesFactory.OrderProgress.截断收货.getValue(), EnumValuesFactory.OrderProgress.截断余料.getValue(), jdOrderNo, consumeOrderTypeBwarts, reciveOrderTypeBwarts, byOrderTypeBwarts);
                break;
            case 刀剖:
                Integer dpType = Integer.valueOf(collect.get(EnumValuesFactory.OrderProgress.刀剖.getValue()));
                List<ProductionOrder> dpOrderNo = productionOrderService.findByWorkTypeAndTimeAndStatus(dpType, workOrderProgressReportDto.getGstrp(), workOrderProgressReportDto.getGltrp(), workOrderProgressReportDto.getStatus());
                receiptOfGoods = encapsulatedData(workOrderProgressReportDto, EnumValuesFactory.OrderProgress.刀剖消耗.getValue(), EnumValuesFactory.OrderProgress.刀剖收货.getValue(), EnumValuesFactory.OrderProgress.刀剖余料.getValue(), dpOrderNo, consumeOrderTypeBwarts, reciveOrderTypeBwarts, byOrderTypeBwarts);
                break;
            case 籽晶:
                Integer zjType = Integer.valueOf(collect.get(EnumValuesFactory.OrderProgress.籽晶.getValue()));
                List<ProductionOrder> zjOrderNo = productionOrderService.findByWorkTypeAndTimeAndStatus(zjType, workOrderProgressReportDto.getGstrp(), workOrderProgressReportDto.getGltrp(), workOrderProgressReportDto.getStatus());
                receiptOfGoods = encapsulatedData(workOrderProgressReportDto, EnumValuesFactory.OrderProgress.籽晶消耗.getValue(), EnumValuesFactory.OrderProgress.籽晶收货.getValue(), EnumValuesFactory.OrderProgress.籽晶余料.getValue(), zjOrderNo, consumeOrderTypeBwarts, reciveOrderTypeBwarts, byOrderTypeBwarts);
                break;
            case 硅料:
                Integer glType = Integer.valueOf(collect.get(EnumValuesFactory.OrderProgress.硅料清洗.getValue()));
                List<ProductionOrder> glOrderNo = productionOrderService.findByWorkTypeAndTimeAndStatus(glType, workOrderProgressReportDto.getGstrp(), workOrderProgressReportDto.getGltrp(), workOrderProgressReportDto.getStatus());
                receiptOfGoods = encapsulatedData(workOrderProgressReportDto, EnumValuesFactory.OrderProgress.硅料清洗分选.getValue(), EnumValuesFactory.OrderProgress.硅料收货.getValue(), EnumValuesFactory.OrderProgress.硅料余料.getValue(), glOrderNo, consumeOrderTypeBwarts, reciveOrderTypeBwarts, byOrderTypeBwarts);
                break;
        }

        if(null != receiptOfGoods && receiptOfGoods.size() > 0){
            totalWorkOrderProgressReportDtoList.addAll(receiptOfGoods);
        }
        if(null != consumptionWorks && consumptionWorks.size() > 0){
            totalWorkOrderProgressReportDtoList.addAll(consumptionWorks);
        }
        if(null != byProductWorkOrder && byProductWorkOrder.size() > 0){
            totalWorkOrderProgressReportDtoList.addAll(byProductWorkOrder);
        }

        return totalWorkOrderProgressReportDtoList;
    }
//
//    @Override
//    public List<WorkOrderProgressReportDto> findOrderProgress1(ServletRequest request, RequestPage requestPage){
//
//        List<WorkOrderProgressReportDto> totalWorkOrderProgressReportDtoList = new ArrayList<>();
//        List<WorkOrderProgressReportDto> receiptOfGoods = new ArrayList<>();
//        List<WorkOrderProgressReportDto> consumptionWorks = new ArrayList<>();
//        List<WorkOrderProgressReportDto> byProductWorkOrder = new ArrayList<>();
//        EnumValuesFactory.OrderProgress orderProgress = EnumValuesFactory.OrderProgress.getOrderProgress(request.getParameter("search_EQ_workType"));
//
//        List<DictionaryItem> factoryWorkType = dictionaryItemService.findByThemeValueAndEnable("factoryWorkType", true);
//        Map<String, String> collect = factoryWorkType.stream().collect(Collectors.toMap(DictionaryItem::getName, DictionaryItem::getValue));
//
//        List<String> consumeOrderTypeBwarts = new ArrayList<>();
//        List<String> reciveOrderTypeBwarts = new ArrayList<>();
//        List<String> byOrderTypeBwarts = new ArrayList<>();
//        consumeOrderTypeBwarts.add("261");
//        consumeOrderTypeBwarts.add("262");
//        reciveOrderTypeBwarts.add("101");
//        reciveOrderTypeBwarts.add("102");
//        byOrderTypeBwarts.add("531");
//        byOrderTypeBwarts.add("532");
//
//        String search_eq_workType = request.getParameter("search_EQ_workType");
//        String search_EQ_status = request.getParameter("search_EQ_status");
//        String search_LT_gstrp = request.getParameter("search_LT_gstrp");
//        String search_GT_gstrp = request.getParameter("search_GT_gstrp");
//
//        Set<SearchFilter> searchSet = new HashSet<>(4);
//        searchSet.add(new SearchFilter("status", SearchFilter.Operator.EQ, search_EQ_status));
//        searchSet.add(new SearchFilter("gstrp", SearchFilter.Operator.GTE, search_LT_gstrp));
//        searchSet.add(new SearchFilter("gstrp", SearchFilter.Operator.LTE, search_GT_gstrp));
//
//
//
//        //查询方棒检验数据库
//        switch (orderProgress) {
//            case 单晶:
//                Integer integer = Integer.valueOf(collect.get(EnumValuesFactory.OrderProgress.拉晶.getValue()));
//                searchSet.add(new SearchFilter("workType", SearchFilter.Operator.EQ, integer));
//                Specification<ProductionOrder> specification = DynamicSpecifications.bySearchFilter(ProductionOrder.class, searchSet);
//                Page<ProductionOrder> byExample = productionOrderService.findByExample(specification, PageUtil.createPageable(requestPage));
//                List<ProductionOrder> content = byExample.getContent();
//                receiptOfGoods = encapsulatedData(null, EnumValuesFactory.OrderProgress.拉晶.getValue(), EnumValuesFactory.OrderProgress.单晶收货.getValue(), EnumValuesFactory.OrderProgress.拉晶余料.getValue(), content, consumeOrderTypeBwarts, reciveOrderTypeBwarts, byOrderTypeBwarts);
//                break;
//            case 截断:
//                Integer jdType = Integer.valueOf(collect.get(EnumValuesFactory.OrderProgress.截断.getValue()));
//                searchSet.add(new SearchFilter("workType", SearchFilter.Operator.EQ, jdType));
//                Specification<ProductionOrder> specification1 = DynamicSpecifications.bySearchFilter(ProductionOrder.class, searchSet);
//                Page<ProductionOrder> byExample1 = productionOrderService.findByExample(specification1, PageUtil.createPageable(requestPage));
//                List<ProductionOrder> content1 = byExample1.getContent();
//                receiptOfGoods = encapsulatedData(null, EnumValuesFactory.OrderProgress.截断消耗.getValue(), EnumValuesFactory.OrderProgress.截断收货.getValue(), EnumValuesFactory.OrderProgress.截断余料.getValue(), content1, consumeOrderTypeBwarts, reciveOrderTypeBwarts, byOrderTypeBwarts);
//                break;
//            case 刀剖:
//                Integer dpType = Integer.valueOf(collect.get(EnumValuesFactory.OrderProgress.刀剖.getValue()));
//                searchSet.add(new SearchFilter("workType", SearchFilter.Operator.EQ, dpType));
//                Specification<ProductionOrder> specification2 = DynamicSpecifications.bySearchFilter(ProductionOrder.class, searchSet);
//                Page<ProductionOrder> byExample2 = productionOrderService.findByExample(specification2, PageUtil.createPageable(requestPage));
//                List<ProductionOrder> content2 = byExample2.getContent();
//                receiptOfGoods = encapsulatedData(null, EnumValuesFactory.OrderProgress.刀剖消耗.getValue(), EnumValuesFactory.OrderProgress.刀剖收货.getValue(), EnumValuesFactory.OrderProgress.刀剖余料.getValue(), content2, consumeOrderTypeBwarts, reciveOrderTypeBwarts, byOrderTypeBwarts);
//                break;
//            case 籽晶:
//                Integer zjType = Integer.valueOf(collect.get(EnumValuesFactory.OrderProgress.籽晶.getValue()));
//                searchSet.add(new SearchFilter("workType", SearchFilter.Operator.EQ, zjType));
//                Specification<ProductionOrder> specification3 = DynamicSpecifications.bySearchFilter(ProductionOrder.class, searchSet);
//                Page<ProductionOrder> byExample3 = productionOrderService.findByExample(specification3, PageUtil.createPageable(requestPage));
//                List<ProductionOrder> content3 = byExample3.getContent();
//                receiptOfGoods = encapsulatedData(null, EnumValuesFactory.OrderProgress.籽晶消耗.getValue(), EnumValuesFactory.OrderProgress.籽晶收货.getValue(), EnumValuesFactory.OrderProgress.籽晶余料.getValue(), content3, consumeOrderTypeBwarts, reciveOrderTypeBwarts, byOrderTypeBwarts);
//                break;
//            case 硅料:
//                Integer glType = Integer.valueOf(collect.get(EnumValuesFactory.OrderProgress.硅料清洗.getValue()));
//                searchSet.add(new SearchFilter("workType", SearchFilter.Operator.EQ, glType));
//                Specification<ProductionOrder> specification4 = DynamicSpecifications.bySearchFilter(ProductionOrder.class, searchSet);
//                Page<ProductionOrder> byExample4 = productionOrderService.findByExample(specification4, PageUtil.createPageable(requestPage));
//                List<ProductionOrder> content4 = byExample4.getContent();
//                receiptOfGoods = encapsulatedData(null, EnumValuesFactory.OrderProgress.硅料清洗分选.getValue(), EnumValuesFactory.OrderProgress.硅料收货.getValue(), EnumValuesFactory.OrderProgress.硅料余料.getValue(), content4, consumeOrderTypeBwarts, reciveOrderTypeBwarts, byOrderTypeBwarts);
//                break;
//        }
//
//        if(null != receiptOfGoods && receiptOfGoods.size() > 0){
//            totalWorkOrderProgressReportDtoList.addAll(receiptOfGoods);
//        }
//        if(null != consumptionWorks && consumptionWorks.size() > 0){
//            totalWorkOrderProgressReportDtoList.addAll(consumptionWorks);
//        }
//        if(null != byProductWorkOrder && byProductWorkOrder.size() > 0){
//            totalWorkOrderProgressReportDtoList.addAll(byProductWorkOrder);
//        }
//
//        return totalWorkOrderProgressReportDtoList;
//    }

    private List<WorkOrderProgressReportDto> encapsulatedData(WorkOrderProgressReportDto workOrderProgressReportDto, String consumeOrderType, String reciveOrderType, String byOrderType, List<ProductionOrder> productionOrderList, List<String> consumeOrderTypeBwarts, List<String> reciveOrderTypeBwarts, List<String> byOrderTypeBwarts){

        //根据工单查询报工情况
        List<WorkOrderProgressReportDto> workOrderProgressReportDtos = new ArrayList<>();
        List<ReportSapGoodsmvt> consumeReportSapGoodsmvtList;
        List<ReportSapGoodsmvt> reportSapGoodsmvtList;
        List<ReportSapGoodsmvt> byReportSapGoodsmvtList;



        if(null != productionOrderList && productionOrderList.size() > 0){
            for (ProductionOrder productionOrder : productionOrderList) {

                WorkOrderProgressReportDto workOrderProgressReportDto1 = new WorkOrderProgressReportDto();
                workOrderProgressReportDto1.setAufnr(productionOrder.getAufnr());
                workOrderProgressReportDto1.setGstrp(productionOrder.getGstrp());
                workOrderProgressReportDto1.setGltrp(productionOrder.getGltrp());
                workOrderProgressReportDto1.setStatus(workOrderProgressReportDto.getStatus());
                workOrderProgressReportDto1.setField4(workOrderProgressReportDto.getField4());

                if(null != workOrderProgressReportDto.getAufnr() && !productionOrder.getAufnr().equals(workOrderProgressReportDto.getAufnr())){
                    continue;
                }

                consumeReportSapGoodsmvtList = reportSapGoodsmvtService.findByProcNameAndOrderNoAndBwart(consumeOrderType, productionOrder.getAufnr(), consumeOrderTypeBwarts);
                reportSapGoodsmvtList = reportSapGoodsmvtService.findByProcNameAndOrderNoAndBwart(reciveOrderType, productionOrder.getAufnr(), reciveOrderTypeBwarts);
                byReportSapGoodsmvtList = reportSapGoodsmvtService.findByProcNameAndOrderNoAndBwart(byOrderType, productionOrder.getAufnr(), byOrderTypeBwarts);

                if(null != consumeReportSapGoodsmvtList && consumeReportSapGoodsmvtList.size() > 0){
                    BigDecimal reduce = consumeReportSapGoodsmvtList.stream().map(e -> e.getMenge() == null ? new BigDecimal(0) :
                            new BigDecimal(e.getMenge())).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //投料量
                    workOrderProgressReportDto1.setFeedWeight(reduce);
                }

                if(null != reportSapGoodsmvtList && reportSapGoodsmvtList.size() > 0){
                    Map<Boolean, List<ReportSapGoodsmvt>> collect = reportSapGoodsmvtList.stream().collect(Collectors.groupingBy(ReportSapGoodsmvt::getStatus));
                    //主产品
                    calWeightAndDetail(workOrderProgressReportDto1, collect, reportSapGoodsmvtList, "主产品");
                }

                if(null != byReportSapGoodsmvtList && byReportSapGoodsmvtList.size() > 0){
                    //副产品
                    Map<Boolean, List<ReportSapGoodsmvt>> byCollect = byReportSapGoodsmvtList.stream().collect(Collectors.groupingBy(ReportSapGoodsmvt::getStatus));
                    calWeightAndDetail(workOrderProgressReportDto1, byCollect, byReportSapGoodsmvtList, "副产品");
                }

                if(null == workOrderProgressReportDto1.getFeedWeight()){
                    continue;
                }
                if(null == workOrderProgressReportDto1.getByProductionReportedWeight() ){
                    workOrderProgressReportDto1.setByProductionReportedWeight(new BigDecimal(0));
                }
                if(null == workOrderProgressReportDto1.getByProductionUnReportedWeight()){
                    workOrderProgressReportDto1.setByProductionUnReportedWeight(new BigDecimal(0));
                }
                if(null == workOrderProgressReportDto1.getProductionReportedWeight()){
                    workOrderProgressReportDto1.setProductionReportedWeight(new BigDecimal(0));
                }
                if(null == workOrderProgressReportDto1.getProductionUnReportedWeight()){
                    workOrderProgressReportDto1.setProductionUnReportedWeight(new BigDecimal(0));
                }
                //投入产出比
                BigDecimal product = new BigDecimal(0);
                BigDecimal feedWeight =  new BigDecimal(0);
                if(EnumValuesFactory.OrderProgress.籽晶收货.getValue().equals(reciveOrderType)){
                    //todo 后面的长度需要根据长度进行取值，此处紧急处理后续优化
                    product =  workOrderProgressReportDto1.getByProductionReportedWeight().add(workOrderProgressReportDto1.getByProductionUnReportedWeight()).
                            add(workOrderProgressReportDto1.getProductionReportedWeight().multiply(new BigDecimal(0.17))).
                            add(workOrderProgressReportDto1.getProductionUnReportedWeight().multiply(new BigDecimal(0.17)));
                    feedWeight = workOrderProgressReportDto1.getFeedWeight();
                }else {
                    product =  workOrderProgressReportDto1.getByProductionReportedWeight().add(workOrderProgressReportDto1.getByProductionUnReportedWeight()).
                            add(workOrderProgressReportDto1.getProductionReportedWeight()).
                            add(workOrderProgressReportDto1.getProductionUnReportedWeight());
                    feedWeight = workOrderProgressReportDto1.getFeedWeight();
                }
                if(null == feedWeight || feedWeight.compareTo(new BigDecimal(0)) <= 0){
                    workOrderProgressReportDto1.setInputOutputRatio("0.00" + "%");
                } else {
                    workOrderProgressReportDto1.setInputOutputRatio(product.multiply(new BigDecimal(100)).divide(feedWeight,3, RoundingMode.HALF_UP).setScale(2, BigDecimal.ROUND_HALF_UP).toString() + "%");
                }
                RequestPage requestPage = new RequestPage();
                requestPage.setRows(1);
                requestPage.setPage(10);
                ResponsePage<List<WipProcessDetailedInfoDto>> responsePage = wipStorageService.getProcessInfoPage1(productionOrder.getAufnr(), PageUtil.createPageable(requestPage));
                //在制数量   截断、刀剖有这个值，其他的不要
                if(reciveOrderType.contains(EnumValuesFactory.OrderProgress.截断.getValue())){
                    //截断在制品：圆棒检验、圆棒反切、毛棒截断进站
                    workOrderProgressReportDto1.setCount(new BigDecimal(responsePage.getTotal()));
                }
                if(reciveOrderType.contains(EnumValuesFactory.OrderProgress.刀剖.getValue())){
                    //刀剖在制品：磨削、方棒检验、方棒反切的、刀剖进站
                    workOrderProgressReportDto1.setCount(new BigDecimal(responsePage.getTotal()));
                }
                workOrderProgressReportDto1.setStatus(productionOrder.getStatus());
                workOrderProgressReportDtos.add(workOrderProgressReportDto1);
            }
        }

        return workOrderProgressReportDtos;
    }

    private void calWeightAndDetail(WorkOrderProgressReportDto workOrderProgressReportDto1, Map<Boolean, List<ReportSapGoodsmvt>> byCollect, List<ReportSapGoodsmvt> reportSapGoodsmvtList, String type) {
        for (Map.Entry<Boolean, List<ReportSapGoodsmvt>> booleanListEntry : byCollect.entrySet()) {
            Boolean key = booleanListEntry.getKey();
            List<ReportSapGoodsmvt> value = booleanListEntry.getValue();
            BigDecimal reduce = value.stream().map(e -> e.getMenge() == null ? new BigDecimal(0) :
                    new BigDecimal(e.getMenge())).reduce(BigDecimal.ZERO, BigDecimal::add);
            if(key){
                //已报
                if(type.equals("主产品")){
                    workOrderProgressReportDto1.setProductionReportedWeight(reduce);
                    if(null == workOrderProgressReportDto1.getProductionUnReportedWeight()){
                        workOrderProgressReportDto1.setProductionUnReportedWeight(new BigDecimal(0));
                    }
                } else {
                    workOrderProgressReportDto1.setByProductionReportedWeight(reduce);
                    if(null == workOrderProgressReportDto1.getByProductionUnReportedWeight()){
                        workOrderProgressReportDto1.setByProductionUnReportedWeight(new BigDecimal(0));
                    }
                }
            } else {
                //未报
                if(type.equals("主产品")){
                    workOrderProgressReportDto1.setProductionUnReportedWeight(reduce);
                    if(null == workOrderProgressReportDto1.getProductionReportedWeight()){
                        workOrderProgressReportDto1.setProductionReportedWeight(new BigDecimal(0));
                    }
                } else {
                    workOrderProgressReportDto1.setByProductionUnReportedWeight(reduce);
                    if(null == workOrderProgressReportDto1.getByProductionReportedWeight()){
                        workOrderProgressReportDto1.setByProductionReportedWeight(new BigDecimal(0));
                    }
                }
            }
        }
    }

    public ReportSapGoodsmvtDto toLazyDto(ReportSapGoodsmvt entity) {
        ReportSapGoodsmvtDto dto = modelMapper.map(entity, ReportSapGoodsmvtDto.class);
        dto.setChargItems(new Gson().fromJson(entity.getChargItem(), new TypeToken<List<ReportSapChargItemDto>>() {
        }.getType()));
        return dto;
    }

}
