package com.qxgmat.service.inline;

import com.github.pagehelper.Page;
import com.nuliji.tools.AbstractService;
import com.nuliji.tools.exception.ParameterException;
import com.nuliji.tools.exception.SystemException;
import com.qxgmat.data.dao.UserFeedbackErrorMapper;
import com.qxgmat.data.dao.entity.UserFeedbackError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

@Service
public class UserFeedbackErrorService extends AbstractService {
    private static final Logger logger = LoggerFactory.getLogger(UserFeedbackErrorService.class);

    @Resource
    private UserFeedbackErrorMapper userFeedbackErrorMapper;

    public UserFeedbackError add(UserFeedbackError feedbackError){
        int result = insert(userFeedbackErrorMapper, feedbackError);
        feedbackError = one(userFeedbackErrorMapper, feedbackError.getId());
        if(feedbackError == null){
            throw new SystemException("勘误添加失败");
        }
        return feedbackError;
    }

    public UserFeedbackError edit(UserFeedbackError feedbackError){
        UserFeedbackError in = one(userFeedbackErrorMapper, feedbackError.getId());
        if(in == null){
            throw new ParameterException("勘误不存在");
        }
        int result = update(userFeedbackErrorMapper, feedbackError);
        return feedbackError;
    }

    public boolean delete(Number id){
        UserFeedbackError in = one(userFeedbackErrorMapper, id);
        if(in == null){
            throw new ParameterException("勘误不存在");
        }
        int result = delete(userFeedbackErrorMapper, id);
        return result > 0;
    }

    public UserFeedbackError get(Number id){
        UserFeedbackError in = one(userFeedbackErrorMapper, id);

        if(in == null){
            throw new ParameterException("勘误不存在");
        }
        return in;
    }

    public Page<UserFeedbackError> select(int page, int pageSize){
        return select(userFeedbackErrorMapper, page, pageSize);
    }

    public List<UserFeedbackError> select(Collection ids){
        return select(userFeedbackErrorMapper, ids);
    }

}
