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

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.canteen.core.common.redis.RedisUtil;
import com.bonus.canteen.core.common.utils.TenantContextHolder;
import com.bonus.canteen.core.menu.entity.MenuDishesStepDetail;
import com.bonus.canteen.core.menu.mapper.MenuDishesStepDetailMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;


@Service
public class MenuDishesStepDetailService extends ServiceImpl<MenuDishesStepDetailMapper, MenuDishesStepDetail> {
   private static final Logger log = LoggerFactory.getLogger(MenuDishesStepDetailService.class);
//   @Autowired
//   private MenuDishesStepMapper menuDishesStepMapper;
//
//   public List<MenuDishesStepDetailVo> getByStepIds(List<Long> stepIds) {
//      return (List)(ObjectUtil.isNotEmpty(stepIds) ? ((MenuDishesStepDetailMapper)this.baseMapper).getByStepIds(stepIds) : new ArrayList());
//   }
//
//   public List<MenuDishesStepDetailVo> getMenuDishesStepDetail(Long baseDishesId, Integer stepType, Long materialId) {
//      log.info("baseDishesId:{},stepType:{},materialId:{}", new Object[]{baseDishesId, stepType, materialId});
//      String redisKey = String.format("yst:%s:dishes:%s:step:material:%s:detail:type:%s", TenantContextHolder.getTenantId(), baseDishesId, materialId, stepType);
//      Object value = RedisUtil.getObj(redisKey);
//      if (value instanceof List) {
//         return (List)value;
//      } else {
//         MenuDishesStep menuDishesStep = (MenuDishesStep)this.menuDishesStepMapper.selectOne((Wrapper)((LambdaQueryWrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(MenuDishesStep.class).eq(MenuDishesStep::getStepType, stepType)).eq(MenuDishesStep::getMaterialId, materialId)).eq(MenuDishesStep::getBaseDishesId, baseDishesId));
//         if (ObjectUtil.isNotEmpty(menuDishesStep)) {
//            Long stepId = menuDishesStep.getStepId();
//            List<MenuDishesStepDetailVo> byStepIds = this.getByStepIds(Collections.singletonList(stepId));
//            if (ObjectUtil.isNotEmpty(byStepIds)) {
//               RedisUtil.setObj(redisKey, byStepIds, 86400L);
//            }
//
//            return byStepIds;
//         } else {
//            return null;
//         }
//      }
//   }

}
