package com.sw.mes.yb.pad.service;

import com.alibaba.fastjson.JSONObject;
import com.sw.mes.base.factory.inspect.entity.DefaultCrystalAttrs;
import com.sw.mes.core.base.BaseService;
import com.sw.mes.core.response.Result;
import com.sw.mes.inspect.entity.YbInspectData;
import com.sw.mes.yb.pad.dto.ProductionBackCuttingRecordDto;
import com.sw.mes.yb.pad.dto.RecordSegmentNoInfoDto;
import com.sw.mes.yb.pad.dto.RecutInfoDetailInfo;
import com.sw.mes.yb.pad.entity.ProductionBackCuttingRecord;
import com.sw.mes.yb.pad.entity.SectionNoDetail;

import java.math.BigDecimal;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @Author
 * @Description： 圆棒反切
 * @Date:
 * @Modified By:
 */
public interface ProductionRecutService extends BaseService<ProductionBackCuttingRecord> {


    // 获取晶段信息
    Result findSegmentNoInfo(String trayNo);


    List<Map<String,Object>> findInformationBySegmentNo(String segmentNo);

    Result<LinkedList<RecordSegmentNoInfoDto>> findSegmentNoInfoV2(String trayNo);

    // 获取晶段信息
    Result findSegmentNoInfoBySectionNo(String sectionNo);

    Result<LinkedList<RecordSegmentNoInfoDto>> findSegmentNoInfoBySectionNoV2(String segmentNo);

    //业务调整，适配现场未检验数据进行返切
    Result<LinkedList<RecordSegmentNoInfoDto>> findSegmentNoInfoBySectionNoV2New(String segmentNo);

    void getSegmentNoV2(List<ProductionBackCuttingRecordDto> backCuttingRecordDto);

    String handleSampleNo(Date date, String segmentNo, Integer sampleCount, Boolean isTailFlag);

    // 通过晶段编号获取反切后生成的晶段编号
    Result<List<RecutInfoDetailInfo>> getSegmentNo(ProductionBackCuttingRecordDto backCuttingRecordDto);


    /**
     * 保存反切画线信息
     *
     * @param backCuttingRecordDto   划线信息
     * @param weightLossCoefficient  这种系数
     * @param defaultCrystalAttrList 单晶属性集合
     * @param isInheritSample        是否继承样片编号
     */
    void createBackCuttingRecord(ProductionBackCuttingRecordDto backCuttingRecordDto, BigDecimal weightLossCoefficient, DefaultCrystalAttrs defaultCrystalAttrList, boolean isInheritSample);

    /**
     * 保存反切画线信息
     *
     * @param backCuttingRecordDto   划线信息
     * @param weightLossCoefficient  这种系数
     * @param defaultCrystalAttrList 单晶属性集合
     * @param isInheritSample        是否继承样片编号
     */
    void createBackCuttingRecord(ProductionBackCuttingRecordDto backCuttingRecordDto, BigDecimal weightLossCoefficient, DefaultCrystalAttrs defaultCrystalAttrList, boolean isInheritSample, boolean auto,Boolean waitFlag);


    List<SectionNoDetail> savePieceAndSectionNoDetail(ProductionBackCuttingRecord productionBackCuttingRecord, SectionNoDetail sectionNoDetail);

    /**
     * 删除晶段详情表中对应的晶段信息
     *
     * @param reversecutDrawId
     */
    void deleteBackInfoDetail(Long reversecutDrawId);

    List<ProductionBackCuttingRecord> findByUuid(String uuid);

    /**
     * 根据晶段编号获取返切画线记录
     *
     * @param crystalNo
     * @return
     */
    ProductionBackCuttingRecord findBySegmentNo(String crystalNo);

    List<ProductionBackCuttingRecord> findAllBySegmentNo(String crystalNo);

    List<ProductionBackCuttingRecord> findAllBySegmentNo1(String crystalNo);

    /**
     * 获取最新反切划线记录
     *
     * @param code
     * @return
     */
    ProductionBackCuttingRecord findTopBySegmentNoOrderByIdDesc(String code);

    /**
     * 根据编号和截断状态获取反切划线信息
     *
     * @param code
     * @param status
     * @return
     */
    ProductionBackCuttingRecord findTopBySegmentNoAndStatusOrderByIdDesc(String code, boolean status);

    ProductionBackCuttingRecord findOneBySegmentNoAndStatusOrderByIdDesc(String code, boolean status);

    void createBackCuttingRecordV2(List<ProductionBackCuttingRecordDto> productionBackCuttingRecordDtos, BigDecimal weightLossCoefficient, DefaultCrystalAttrs defaultCrystalAttrList, boolean b);

    void createBackCuttingRecordV2New(List<ProductionBackCuttingRecordDto> productionBackCuttingRecordDtos, BigDecimal weightLossCoefficient, DefaultCrystalAttrs defaultCrystalAttrList, boolean isInheritSample);

    void autoCreateAppearanceCut(JSONObject text, BigDecimal weightLossCoefficient, DefaultCrystalAttrs defaultCrystalAttrList, SectionNoDetail sectionNoDetail, boolean isInheritSample);

    Result<String> execProductionBackCuttingRecord(YbInspectData ybInspectData);


    ProductionBackCuttingRecord findBySectionNo(String segmentNo);
}
