package io.hmit.modules.competition.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.modules.activiti.dto.HistoryDetailDTO;
import io.hmit.modules.competition.dao.WlUploadInfoDao;
import io.hmit.modules.competition.dto.WlUploadInfoDTO;
import io.hmit.modules.competition.entity.WlUploadInfoEntity;
import io.hmit.modules.competition.service.WlUploadInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
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 2020-07-16
 */
@Service
public class WlUploadInfoServiceImpl extends CrudServiceImpl<WlUploadInfoDao, WlUploadInfoEntity, WlUploadInfoDTO> implements WlUploadInfoService {

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

        QueryWrapper<WlUploadInfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);
        wrapper.or();
        wrapper.like(StringUtils.isNotBlank(name), "name", name);

        return wrapper;
    }


    @Override
    public List<WlUploadInfoDTO> selectInfo(String name) {
       List<WlUploadInfoEntity> wlList =baseDao.selectByName(name);
       List<WlUploadInfoDTO> finallist =new ArrayList<>();
//       ConvertUtils.sourceToTarget(wlList,WlUploadInfoEntity.class);
       for(WlUploadInfoEntity wlUploadInfoEntity:wlList){
           WlUploadInfoDTO wlInfo = new WlUploadInfoDTO();
           BeanUtils.copyProperties(wlUploadInfoEntity,wlInfo);
           finallist.add(wlInfo);
       }
        return finallist;
    }

    @Override
    public boolean isName(String name) {
        int count = baseDao.isName(name);
        System.out.println(name+"信息已存在！");
        if(count==0){
            return true;
        }else {
            return false;
        }
    }
}
