package io.hmit.modules.fhjw.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.fhjw.dao.UserCaseDao;
import io.hmit.modules.fhjw.dto.UserCaseDTO;
import io.hmit.modules.fhjw.entity.UserCaseEntity;
import io.hmit.modules.fhjw.service.UserCaseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 用户案件对应
 *
 * @author zsh 408538940@qq.com
 * @since 1.0.0 2021-06-16
 */
@Service
public class UserCaseServiceImpl extends CrudServiceImpl<UserCaseDao, UserCaseEntity, UserCaseDTO> implements UserCaseService {

    @Override
    public QueryWrapper<UserCaseEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");
        String caseId = params.get("caseId")==null?"":params.get("caseId").toString();
        String userId = params.get("userId")==null?"":params.get("userId").toString();

        QueryWrapper<UserCaseEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);
        wrapper.eq(StringUtils.isNotBlank(caseId), "case_id", caseId);
        wrapper.eq(StringUtils.isNotBlank(userId), "user_id", userId);

        return wrapper;
    }


    @Override
    public UserCaseDTO getByUserACase(Long userId, Long caseId) {
        UserCaseEntity entity = baseDao.selectOne(new QueryWrapper<UserCaseEntity>()
                .eq("case_id",caseId).eq("user_id",userId));
        return ConvertUtils.sourceToTarget(entity, UserCaseDTO.class);
    }
}
