package com.bonus.canteen.core.menu.mapper;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bonus.canteen.core.drp.dto.AndroidCategoryDTO;
import com.bonus.canteen.core.drp.dto.AndroidMenuMaterialSyncDTO;
import com.bonus.canteen.core.drp.po.CategoryMaterialNumModel;
import com.bonus.canteen.core.drp.v2.po.MaterialListBean;
import com.bonus.canteen.core.drp.vo.AndroidMaterialPageVO;
import com.bonus.canteen.core.drp.vo.AndroidMenuMaterialSyncVO;
import com.bonus.canteen.core.drp.vo.DrpAppAllMaterialTypesVO;
import com.bonus.canteen.core.drp.vo.MenuMaterialUnitVO;
import com.bonus.canteen.core.menu.dto.AndroidMaterialPageDTO;
import com.bonus.canteen.core.menu.dto.MenuMaterialListDTO;
import com.bonus.canteen.core.menu.dto.MenuMaterialPageDTO;
import com.bonus.canteen.core.menu.entity.MenuMaterial;
import com.bonus.canteen.core.menu.entity.MenuMaterialDishes;
import com.bonus.canteen.core.menu.po.ImportCheckMaterialModel;
import com.bonus.canteen.core.menu.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MenuMaterialMapper extends BaseMapper<MenuMaterial> {
    List<MenuMaterialPageVO> selectAllList(@Param("delFlag") Integer delFlag, @Param("content") MenuMaterialPageDTO content, @Param("categoryIdList") List<Long> categoryIdList);

    List<MenuMaterialDishesPageVO> selectListByDishesId(MenuMaterialDishes materialDishes);

    @Select({"select nutrition_id, nutrition_code materialCode, big_type, little_type, nutrition_name materialName from menu_nutrition"})
    List<MenuMaterialInitVO> selectMaterialNameList();

    List<String> selectMaterialList(@Param("delFlag") Integer delFlag);

    void insertMaterialBatch(List<MenuMaterial> materialList);

    @Select({"select mm.material_id, mm.material_name, mmd.weight, mmd.material_type from menu_material mm left join menu_material_dishes mmd on mm.material_id = mmd.material_id where mm.del_flag = 2 and mmd.dishes_id = #{dishesId}"})
    List<MenuMaterialDishesPageVO> selectMaterialByDishesId(@Param("dishesId") Long dishesId);

    @Select({"select mm.id, mn.nutrition_code, mm.material_code, mn.big_type, mn.little_type from menu_material mm left join menu_nutrition mn on mm.nutrition_id = mn.nutrition_id where mm.del_flag = #{delFlag}"})
    List<MenuRepairMaterialVO> selectAllRepairMaterialList(Integer delFlag);

    @Select({"select a.material_id,a.material_name,a.material_type,a.bar_code,a.unit_id,b.unit_name from menu_material a LEFT JOIN drp_unit b on a.unit_id = b.unit_id where a.del_flag = #{delFlag}"})
    List<ImportCheckMaterialModel> selectMaterialListByWrapper(Integer delFlag);

    @Select({"select material_id from menu_material ${ew.customSqlSegment}"})
    Long selectMaterialIdByWrapper(@Param("ew") Wrapper<MenuMaterial> wrapper);

    MaterialSomeInfoVO getMaterialByName(@Param("materialName") String materialName, @Param("unitName") String unitName, @Param("delFlag") Integer delFlag);

    List<AndroidMaterialPageVO> pageAndroidMaterial(@Param("content") AndroidMaterialPageDTO content, @Param("delFlag") Integer delFlag);

    @Select({"select MAX(material_code) from menu_material where LENGTH(material_code ) = #{materialCodeLength} and del_flag = #{delFlag}"})
    String selectMaxMaterialCodeByCategoryNum(@Param("materialCodeLength") Integer materialCodeLength, @Param("delFlag") Integer delFlag);

    Long checkMaterialNameAndUnit(@Param("materialName") String materialName, @Param("unitName") String unitName, @Param("areaId") Long areaId);

    MenuMaterial getMaterialByNameAndUnit(@Param("materialName") String materialName, @Param("unitName") String unitName, @Param("delFlag") Integer delFlag, @Param("areaId") Long areaId);

    List<DrpAppAllMaterialTypesVO> getAllTypes();

    MenuMaterialVO getMaterialByMaterialId(@Param("materialId") Long materialId);

    List<MenuMaterialListVO> listMaterial(@Param("content") MenuMaterialListDTO content, @Param("delFlag") Integer delFlag);

    List<MenuMaterialUnitVO> getMenuMaterialAndUnitByMaterialIdList(@Param("materialIdList") List<Long> materialIdList);

    List<CategoryMaterialNumModel> countCategoryMaterialNum(@Param("delFlag") Integer delFlag, @Param("categoryIdList") List<Long> categoryIdList, @Param("content") AndroidCategoryDTO content);

    List<AndroidMenuMaterialSyncVO> syncMenuMaterial(@Param("content") AndroidMenuMaterialSyncDTO content);

    List<MaterialListBean> listCollectNotRegisterMaterial(@Param("delFlag") Integer delFlag);

    List<DrpImportMaterialVO> getMaterialByExcel(@Param("materialCodeList") List<String> materialCodeList);
}
