package com.sw.mes.fb.turnstore.service;

import com.sw.mes.base.factory.inspect.dto.ProductRuleValidateDto;
import com.sw.mes.core.base.BaseService;
import com.sw.mes.core.dto.WmsToFbReceiveDto;
import com.sw.mes.core.entity.FbCheckOutData;
import com.sw.mes.core.response.Result;
import com.sw.mes.base.factory.inspect.dto.ProductRuleDto;
import com.sw.mes.base.factory.inspect.entity.ProductAssemblyRule;
import com.sw.mes.fb.turnstore.dto.*;
import com.sw.mes.fb.turnstore.dto.vo.FbTurnstoreTrayItemVo;
import com.sw.mes.fb.turnstore.entity.FbTurnstoreTray;
import com.sw.mes.fb.turnstore.entity.FbTurnstoreTrayItem;

import java.util.List;
import java.util.Map;

/**
 * @Author
 * @Description：
 * @Date:
 * @Modified By:
 */
public interface FbTurnstoreTrayService extends BaseService<FbTurnstoreTray> {


    /**
     * 根据方棒编号获取对应圆棒的相关信息（pda的定制接口）
     *
     * @param fbSectionNo
     * @return
     */
    Result<FbInfoDto> getInfoByFbSectionNo(String fbSectionNo);


    /**
     * 创建成品组托
     *
     * @param productRule
     * @param turnstoreTray
     * @param items
     */
    void createTray(ProductAssemblyRule productRule, FbTurnstoreTray turnstoreTray, List<FbTurnstoreTrayItem> items);

    /**
     * 更新成品组托
     *
     * @param turnstoreTray
     * @param items
     */
    void updateTray(FbTurnstoreTray turnstoreTray, List<FbTurnstoreTrayItem> items);

    Result lengthCheck(ProductRuleDto ruleDto);

    FbTurnstoreTray getFbTray(String trayNo);

    String validateRules(ProductRuleDto ruleDto, FbCheckOutData checkOut);

    FbTurnstoreTray findByTrayNo(String trayNo);

    /**
     * key：trayNo
     * value: FbTurnstoreTray
     *
     * @param trayNoList
     * @return
     */
    Map<String, FbTurnstoreTray> findByTrayNoList(List<String> trayNoList);

    List<FbTurnstoreTray> findByTime(String startTime, String endTime);

    void updateItem(FbTurnstoreTray turnstoreTray, List<FbTurnstoreTrayItem> turnstoreTrayItemList);

    Result initiateReceipt(FbTurnstoreTray turnstoreTray, List<FbTurnstoreTrayItem> turnstoreTrayItemList);

    void updateTrayItemState(WmsToFbReceiveDto receiveDto, FbTurnstoreTray turnstoreTray, List<FbTurnstoreTrayItem> trayItemList);

    List<FbTurnstoreTrayItem> groupItemList(FbCheckOutData checkOut);

    FbTurnstoreTrayItem groupItem(FbCheckOutData checkOut);

    Result validateRuleAndData(ProductRuleDto ruleDto, FbCheckOutData checkOutData, String state);

    void updateTurnstoreTrayStateById(WmsToFbReceiveDto receiveDto, FbTurnstoreTray turnstoreTray);

    void createTrayNoMk(FbTurnstoreTray fbTurnstoreTray, ProductAssemblyRule productRule);

    Result reportedErp(FbTurnstoreTray turnstoreTray, List<FbTurnstoreTrayItem> turnstoreTrayItemList);


    /**
     * @param ruleDto
     * @param isComposeSection 是否是拼棒
     * @return
     */
    Result validateRuleNew(ProductRuleValidateDto ruleDto, boolean isComposeSection);

    void updateStateByTrayNo(UpdateStateByTrayNoDto dto);

    /**
     * 切片mes发起入库
     */
    Result sectionMesInitiateReceipt(FbTurnstoreTray turnstoreTray, List<FbTurnstoreTrayItem> turnstoreTrayItemList);

    /**
     * 根据托盘id修改方棒组托状态
     *
     * @param dto 托盘信息
     */
    void updateStateByTrayId(UpdateStateByTrayIdDto dto);


    /**
     * 获取打签明细信息
     *
     * @param id
     * @return
     */
    FbTurnstoreTrayPrintDto getPrintInfo(Integer id);

    /**
     * 切片mes收货之后修改状态
     *
     * @param turnstoreTray 组托表
     * @param trayItemList  明细表
     */
    void updateSectionMesTrayItemState(FbTurnstoreTray turnstoreTray, List<FbTurnstoreTrayItem> trayItemList);


    void fbWriteOffAccounts(List<FbTurnstoreTrayItem> items);

    void pushSap(List<FbTurnstoreTrayItem> items);

    /**
     * 根据晶编号修改方棒组托明细信息
     *
     * @param state     状态
     * @param sectionNo 晶编号
     */
    void updateSectionMesTrayItemStateBySectionNo(String state, String sectionNo);

    /**
     * 根据晶编号查询组托明细信息
     *
     * @param sectionNo 晶编号
     * @return 组托明细信息
     */
    FbTurnstoreTrayItem findBySectionNo(String sectionNo);

    /**
     * 自动组托规则校验
     * @param crystalNo 单晶编号
     * @param isComposeSection 是否是拼棒
     * @return 方棒组托信息
     */
    FbTurnstoreTrayItemVo validateRule(String crystalNo , boolean isComposeSection);
}
