package com.hchyun.test.service.impl;

import java.util.List;

import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.common.utils.DateUtils;
import com.hchyun.common.utils.ServerResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hchyun.test.dao.RelADao;
import com.hchyun.test.entity.RelA;
import com.hchyun.test.service.RelAService;

/**
 * 测试aService业务层处理
 * 
 * @author hchyun
 * @date 2021-02-26
 */
@Service
public class RelAServiceImpl implements RelAService {
    private Logger logger = LoggerFactory.getLogger(RelAServiceImpl.class);

    @Autowired
    private RelADao relADao;

    /**
     * 查询测试a
     * 
     * @param aid 测试aID
     * @return 测试a
     */
    @Override
    public ServerResult<RelA> selectRelAById(Long aid) {
        try {
            RelA relA = relADao.selectRelAById(aid);
            if (relA != null){
                return new ServerResult<RelA>(true,relA);
            }else {
                return new ServerResult<RelA>(false, ReturnConstants.RESULT_EMPTY);
            }
        }catch (RuntimeException e){
            logger.error(e.getMessage());
            return new ServerResult<RelA>(false,ReturnConstants.DB_EX);
        }
    }

    /**
     * 查询测试a列表
     * 
     * @param relA 测试a
     * @return 测试a
     */
    @Override
    public ServerResult<List<RelA>> selectRelAList(RelA relA) {
        try {
            List<RelA> relAList = relADao.selectRelAList(relA);
            if (relAList.size()>0){
                return new ServerResult<List<RelA>>(true,relAList);
            }else {
                return new ServerResult<List<RelA>>(false,ReturnConstants.RESULT_EMPTY);
            }
        }catch (RuntimeException e){
            logger.error(e.getMessage());
            return new ServerResult<List<RelA>>(false,ReturnConstants.DB_EX);
        }
    }

    /**
     * 新增测试a
     * 
     * @param relA 测试a
     * @return 结果
     */
    @Override
    public ServerResult<Integer> insertRelA(RelA relA) {
        try {
            Integer renewal = relADao.insertRelA(relA);
            if (renewal >0){
                return new ServerResult<>(true,renewal);
            }else {
                return new ServerResult<>(false,ReturnConstants.SYS_FAILL);
            }
        }catch (RuntimeException e){
            logger.error(e.getMessage());
            return new ServerResult<>(false,ReturnConstants.DB_EX);
        }
    }

    /**
     * 修改测试a
     * 
     * @param relA 测试a
     * @return 结果
     */
    @Override
    public ServerResult<Integer> updateRelA(RelA relA) {
        try {
            Integer renewal = relADao.updateRelA(relA);
            if (renewal >0){
                return new ServerResult<>(true,renewal);
            }else {
                return new ServerResult<>(false,ReturnConstants.SYS_FAILL);
            }
        }catch (RuntimeException e){
            logger.error(e.getMessage());
            return new ServerResult<>(false,ReturnConstants.DB_EX);
        }
    }

    /**
     * 批量删除测试a
     * 
     * @param aids 需要删除的测试aID
     * @return 结果
     */
    @Override
    public ServerResult<Integer> deleteRelAByIds(Long[] aids) {
        try {
            Integer renewal = relADao.deleteRelAByIds(aids);
            if (renewal >0){
                return new ServerResult<>(true,renewal);
            }else {
                return new ServerResult<>(false,ReturnConstants.SYS_FAILL);
            }
        }catch (RuntimeException e){
            logger.error(e.getMessage());
            return new ServerResult<>(false,ReturnConstants.DB_EX);
        }
    }

    /**
     * 删除测试a信息
     * 
     * @param aid 测试aID
     * @return 结果
     */
    @Override
    public ServerResult<Integer> deleteRelAById(Long aid) {
        try {
            Integer renewal = relADao.deleteRelAById(aid);
            if (renewal >0){
                return new ServerResult<>(true,renewal);
            }else {
                return new ServerResult<>(false,ReturnConstants.SYS_FAILL);
            }
        }catch (RuntimeException e){
            logger.error(e.getMessage());
            return new ServerResult<>(false,ReturnConstants.DB_EX);
        }
    }
}
