package com.bonus.canteen.core.nutrition.service.impl;

import cn.hutool.core.util.StrUtil;
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.nutrition.common.dto.HealthChronicDto;
import com.bonus.canteen.core.nutrition.mapper.HealthChronicMapper2;
import com.bonus.canteen.core.nutrition.common.model.HealthChronic;
import com.bonus.canteen.core.nutrition.service.HealthChronicService2;
import com.bonus.canteen.core.nutrition.common.vo.HealthChronicVo;
import com.bonus.common.houqin.constant.DelFlagEnum;
import com.bonus.common.houqin.utils.LeBeanUtil;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HealthChronicServiceImpl2 extends ServiceImpl<HealthChronicMapper2, HealthChronic> implements HealthChronicService2 {

   public List<HealthChronicVo> dictHealthChronic(HealthChronicDto content) {
      LambdaQueryWrapper<HealthChronic> queryWrapper = Wrappers.lambdaQuery(HealthChronic.class)
              .eq(StrUtil.isNotBlank(content.getChronicName()), HealthChronic::getChronicName, content.getChronicName())
              .eq(HealthChronic::getDelFlag, DelFlagEnum.DEL_FALSE.key())
              .orderByDesc(HealthChronic::getCreateTime);
      List<HealthChronic> list = this.list(queryWrapper);
      return LeBeanUtil.copyCreateList(list, HealthChronicVo.class);
   }

   public String selectNameById(Long chronicId) {
      return ((HealthChronicMapper2)this.baseMapper).selectNameById(chronicId);
   }

}
