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.AssFatherDao;
import com.hchyun.test.entity.AssFather;
import com.hchyun.test.service.AssFatherService;

/**
 * 关联查询父Service业务层处理
 *
 * @author hchyun
 * @date 2021-02-10
 */
@Service
public class AssFatherServiceImpl implements AssFatherService {
    private Logger logger = LoggerFactory.getLogger(AssFatherServiceImpl.class);

    @Autowired
    private AssFatherDao assFatherDao;

    /**
     * 查询关联查询父
     *
     * @param id 关联查询父ID
     * @return 关联查询父
     */
    @Override
    public ServerResult<AssFather> selectAssFatherById(Long id) {
        try {
            AssFather assFather = assFatherDao.selectAssFatherById(id);
            if (assFather != null) {
                return new ServerResult<AssFather>(true, assFather);
            } else {
                return new ServerResult<AssFather>(false, ReturnConstants.RESULT_EMPTY);
            }
        } catch (RuntimeException e) {
            logger.error(e.getMessage());
            return new ServerResult<AssFather>(false, ReturnConstants.DB_EX);
        }
    }

    /**
     * 查询关联查询父列表
     *
     * @param assFather 关联查询父
     * @return 关联查询父
     */
    @Override
    public ServerResult<List<AssFather>> selectAssFatherList(AssFather assFather) {
        try {
            List<AssFather> assFatherList = assFatherDao.selectAssFatherList(assFather);
            if (assFatherList.size() > 0) {
                return new ServerResult<List<AssFather>>(true, assFatherList);
            } else {
                return new ServerResult<List<AssFather>>(false, ReturnConstants.RESULT_EMPTY);
            }
        } catch (RuntimeException e) {
            logger.error(e.getMessage());
            return new ServerResult<List<AssFather>>(false, ReturnConstants.DB_EX);
        }
    }

    /**
     * 新增关联查询父
     *
     * @param assFather 关联查询父
     * @return 结果
     */
    @Override
    public ServerResult<Integer> insertAssFather(AssFather assFather) {
        try {
            Integer renewal = assFatherDao.insertAssFather(assFather);
            if (renewal > 0) {
                return new ServerResult<Integer>(true, renewal);
            } else {
                return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
            }
        } catch (RuntimeException e) {
            logger.error(e.getMessage());
            return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
        }
    }

    /**
     * 修改关联查询父
     *
     * @param assFather 关联查询父
     * @return 结果
     */
    @Override
    public ServerResult<Integer> updateAssFather(AssFather assFather) {
        try {
            Integer renewal = assFatherDao.updateAssFather(assFather);
            if (renewal > 0) {
                return new ServerResult<Integer>(true, renewal);
            } else {
                return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
            }
        } catch (RuntimeException e) {
            logger.error(e.getMessage());
            return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
        }
    }

    /**
     * 批量删除关联查询父
     *
     * @param ids 需要删除的关联查询父ID
     * @return 结果
     */
    @Override
    public ServerResult<Integer> deleteAssFatherByIds(Long[] ids) {
        try {
            Integer renewal = assFatherDao.deleteAssFatherByIds(ids);
            if (renewal > 0) {
                return new ServerResult<Integer>(true, renewal);
            } else {
                return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
            }
        } catch (RuntimeException e) {
            logger.error(e.getMessage());
            return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
        }
    }

    /**
     * 删除关联查询父信息
     *
     * @param id 关联查询父ID
     * @return 结果
     */
    @Override
    public ServerResult<Integer> deleteAssFatherById(Long id) {
        try {
            Integer renewal = assFatherDao.deleteAssFatherById(id);
            if (renewal > 0) {
                return new ServerResult<Integer>(true, renewal);
            } else {
                return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
            }
        } catch (RuntimeException e) {
            logger.error(e.getMessage());
            return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
        }
    }
}
