package com.jsh.erp.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.jsh.erp.datasource.entities.DepotItem;
import com.jsh.erp.datasource.entities.MaterialBatch;
import com.jsh.erp.datasource.entities.MaterialExtend;
import com.jsh.erp.datasource.entities.MaterialVo4Unit;
import com.jsh.erp.datasource.vo.TaskStocktakingItemVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

public interface MaterialBatchService extends IService<MaterialBatch> {


    /**
     * 根据单据子表id生成商品批次数据
     * @param depotItem 单据子表id
     */
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    void generateMaterialBatchByDepotItemId(DepotItem depotItem, Long supplierId) throws Exception;

    /**
     * 根据单据子表id处理商品批次数据
     * @param diId 单据子表id
     */
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    void handleMaterialBatchByDepotItemId(Long diId) throws Exception;

    /**
     * 修改商品批次库存
     * @param type 操作记录
     * @param diId 单据子表id
     * @param materialBatch 商品批次信息
     */
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    void updateInventory(String type, Long diId, MaterialBatch materialBatch) throws Exception;

    /**
     * 根据仓库id和商品id查询商品批次库存
     * @param depotList 仓库id
     * @param mid   商品id
     */
    BigDecimal getInventorySumByDepotAndMid(List<Long> depotList, Long mid);

    /**
     * 获取批次号字符
     */
    List<MaterialVo4Unit> findBySelectWithBarCode(Long categoryId, String q, String standardOrModel, String color,
                                                  String brand, String mfrs, String enableSerialNumber, String enableBatchNumber,
                                                  Integer offset, Integer rows, Long depotId) throws Exception;

    /**
     * 根据商品条码获取商品批次信息
     * @param barCodes 商品条码字符集合
     */
    List<MaterialBatch> findBySelectWithBarCode(String barCodes,Long depotId);

    /**
     * 根据批次号数组查询商品批次信息
     * @param batchNumbers 批次号数组
     */
    List<TaskStocktakingItemVO> getMaterialByBatchNumber(String [] batchNumbers);

}
