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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hmit.common.page.PageData;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.common.utils.SubListForPageUtil;
import io.hmit.modules.serviceOrder.dao.EnrollDao;
import io.hmit.modules.serviceOrder.dto.EnrollDTO;
import io.hmit.modules.serviceOrder.entity.EnrollEntity;
import io.hmit.modules.serviceOrder.service.EnrollService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 报名表
 *
 * @author Shen Yuanfeng syf0412@vip.qq.com
 * @since 1.0.0 2021-05-12
 */
@Service
public class EnrollServiceImpl extends CrudServiceImpl<EnrollDao, EnrollEntity, EnrollDTO> implements EnrollService {

    @Autowired
    private EnrollDao enrollDao;

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

        QueryWrapper<EnrollEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }

    @Override
    public PageData<EnrollDTO> getOrgEnroll(Map<String, Object> params) {
        List<EnrollDTO> list = enrollDao.getEnrollByOrgId(Long.parseLong(params.get("orgId").toString()));
        return getPageData(SubListForPageUtil.getSubList(params, list), list.size(), EnrollDTO.class);
    }

}