package com.bonus.canteen.core.allocation.advise.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.canteen.core.allocation.advise.dto.EvaluateAddDTO;
import com.bonus.canteen.core.allocation.advise.mapper.BasicsCanteenEvaluateMapper;
import com.bonus.canteen.core.allocation.advise.model.BasicsCanteenEvaluate;
import com.bonus.canteen.core.allocation.advise.service.BasicsCanteenEvaluateService;
import com.bonus.common.houqin.utils.id.Id;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.ApiModelProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.lang.invoke.SerializedLambda;
import java.time.LocalDate;
import java.util.Iterator;
import java.util.List;

@Service
public class BasicsCanteenEvaluateServiceImpl extends ServiceImpl<BasicsCanteenEvaluateMapper, BasicsCanteenEvaluate> implements BasicsCanteenEvaluateService {
   private static final Logger log = LoggerFactory.getLogger(BasicsCanteenEvaluateServiceImpl.class);
//   @Autowired
//   @Lazy
//   private AllocPageDecorationService allocPageDecorationService;
//   @ApiModelProperty
//   @Autowired
//   private AllocCanteenApi allocCanteenApi;

//   public PageVO<EvaluateQueryVO> queryEvaluateByPage(EvaluateQueryDTO evaluateQueryDTO) {
//      if (CollUtil.isNotEmpty(evaluateQueryDTO.getAreaIdList()) && ObjectUtil.isEmpty(evaluateQueryDTO.getCanteenIdList())) {
//         evaluateQueryDTO.setCanteenIdList(this.allocCanteenApi.getCanteenIdListByAreaIdList((List)evaluateQueryDTO.getAreaIdList()));
//      }
//
//      PageHelper.startPage(evaluateQueryDTO);
//      List<EvaluateQueryVO> resultList = ((BasicsCanteenEvaluateMapper)this.baseMapper).queryEvaluateByPage(evaluateQueryDTO);
//      return PageVO.of(resultList);
//   }
//
//   public CanteenEvaluateDetailModel getEvaluateDetail(Long evaluateId) {
//      BasicsCanteenEvaluate canteenEvaluate = (BasicsCanteenEvaluate)this.getOne((Wrapper)Wrappers.lambdaQuery(BasicsCanteenEvaluate.class).eq(BasicsCanteenEvaluate::getEvaluateId, evaluateId));
//      List<AllocPageDecorationModel> decorationList = this.allocPageDecorationService.queryPageDecoration(CanteenConstants.PAGE_CANTEEN_EVALUATE);
//      CanteenEvaluateDetailModel detailModel = new CanteenEvaluateDetailModel();
//      detailModel.convertTitle(decorationList);
//      detailModel.convertData(canteenEvaluate);
//      return detailModel;
//   }
//
//   public CanteenEvaluateCountModel pageEvaluateCount(EvaluateQueryDTO pageDTO) {
//      if (CollUtil.isNotEmpty(pageDTO.getAreaIdList()) && ObjectUtil.isEmpty(pageDTO.getCanteenIdList())) {
//         List<Long> canteenIdListByAreaIdList = this.allocCanteenApi.getCanteenIdListByAreaIdList((List)pageDTO.getAreaIdList());
//         if (ObjectUtil.isEmpty(canteenIdListByAreaIdList)) {
//            return null;
//         }
//
//         pageDTO.setCanteenIdList(this.allocCanteenApi.getCanteenIdListByAreaIdList((List)pageDTO.getAreaIdList()));
//      }
//
//      Page page = new Page(pageDTO.getCurrent(), pageDTO.getSize());
//      Page<CanteenEvaluateCountVO> countVOPage = ((BasicsCanteenEvaluateMapper)this.baseMapper).pageEvaluateCount(page, pageDTO);
//      CanteenEvaluateCountModel countModel = new CanteenEvaluateCountModel();
//      if (CollUtil.isEmpty(countVOPage.getRecords())) {
//         return countModel;
//      } else {
//         List<AllocPageDecorationModel> decorationList = this.allocPageDecorationService.queryPageDecoration(CanteenConstants.PAGE_CANTEEN_EVALUATE);
//         Iterator<AllocPageDecorationModel> it = decorationList.iterator();
//
//         while(it.hasNext()) {
//            AllocPageDecorationModel decorationModel = (AllocPageDecorationModel)it.next();
//            if (LeConstants.COMMON_NO.equals(decorationModel.getContentType())) {
//               it.remove();
//            }
//         }
//
//         countModel.convertTitle(decorationList);
//         countModel.convertData(countVOPage);
//         return countModel;
//      }
//   }

   public void addEvaluate(EvaluateAddDTO addDTO) {
      BasicsCanteenEvaluate basicsCanteenEvaluate = new BasicsCanteenEvaluate();
      BeanUtils.copyProperties(addDTO, basicsCanteenEvaluate);
      basicsCanteenEvaluate.setEvaluateId(Id.next());
      basicsCanteenEvaluate.setEvaluateDate(LocalDate.now());
      addDTO.convertData(basicsCanteenEvaluate);
      this.save(basicsCanteenEvaluate);
   }

   // $FF: synthetic method
//   private static Object $deserializeLambda$(SerializedLambda lambda) {
//      switch (lambda.getImplMethodName()) {
//         case "getEvaluateId":
//            if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("net/xnzn/core/allocation/advise/model/BasicsCanteenEvaluate") && lambda.getImplMethodSignature().equals("()Ljava/lang/Long;")) {
//               return BasicsCanteenEvaluate::getEvaluateId;
//            }
//         default:
//            throw new IllegalArgumentException("Invalid lambda deserialization");
//      }
//   }
}
