package io.hmit.modules.serviceOrder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.common.utils.TreeUtils;
import io.hmit.modules.serviceOrder.dao.PensionServiceDao;
import io.hmit.modules.serviceOrder.dto.PensionServiceDTO;
import io.hmit.modules.serviceOrder.entity.PensionServiceEntity;
import io.hmit.modules.serviceOrder.service.PensionServiceService;
import io.hmit.modules.sys.dto.SysMenuDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 服务表
 *
 * @author zsh 408538940@qq.com
 * @since 1.0.0 2021-01-26
 */
@Service
public class PensionServiceServiceImpl extends CrudServiceImpl<PensionServiceDao, PensionServiceEntity, PensionServiceDTO> implements PensionServiceService {

    @Autowired
    private PensionServiceService pensionServiceService;

    @Autowired
    private PensionServiceDao pensionServiceDao;

    @Override
    public QueryWrapper<PensionServiceEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");
        String keyword = (String)params.get("keyword");



        QueryWrapper<PensionServiceEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);
        wrapper.like(StringUtils.isNotBlank(keyword), "service_name", keyword);



        return wrapper;
    }


    @Override
    public List<PensionServiceDTO> getServiceTree(Map<String, Object> params) {
        List<PensionServiceEntity> list = baseDao.selectList(getWrapper(params));
        List<PensionServiceDTO> dtos = ConvertUtils.sourceToTarget(list,PensionServiceDTO.class);

        return  TreeUtils.build(dtos);
    }

    @Override
    public List<PensionServiceDTO> getAllService() {
        return ConvertUtils.sourceToTarget(pensionServiceDao.getAllService(), PensionServiceDTO.class);
    }
}
