package com.izouma.awesomeadmin.service.impl;

import com.izouma.awesomeadmin.constant.AppConstant;
import com.izouma.awesomeadmin.dao.ImageUploadLogMapper;
import com.izouma.awesomeadmin.dto.Page;
import com.izouma.awesomeadmin.model.ImageUploadLog;
import com.izouma.awesomeadmin.service.ImageUploadLogService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * service接口实现类
 */
@Service
public class ImageUploadLogServiceImpl implements ImageUploadLogService {

    private static Logger logger = Logger.getLogger(ImageUploadLogServiceImpl.class);

    @Autowired
    private ImageUploadLogMapper imageUploadLogMapper;

    @Override
    public List<ImageUploadLog> getImageUploadLogList(ImageUploadLog record) {

        logger.info("getImageUploadLogList");
        try {

            return imageUploadLogMapper.queryAllImageUploadLog(record);
        } catch (Exception e) {
            logger.error("getImageUploadLogList", e);
        }

        return null;
    }

    @Override
    public List<ImageUploadLog> getImageUploadLogByPage(Page page, ImageUploadLog record) {

        logger.info("getImageUploadLogByPage");
        try {

            Map<String, Object> parameter = new HashMap<String, Object>();
            parameter.put("record", record);
            parameter.put(AppConstant.PAGE, page);

            return imageUploadLogMapper.queryImageUploadLogByPage(parameter);
        } catch (Exception e) {
            logger.error("getImageUploadLogByPage", e);
        }

        return null;
    }

    @Override
    public ImageUploadLog getImageUploadLogById(String id) {

        logger.info("getImageUploadLogyId");
        try {

            return imageUploadLogMapper.selectByPrimaryKey(Integer.valueOf(id));
        } catch (Exception e) {
            logger.error("getImageUploadLogById", e);
        }

        return null;
    }

    @Override
    public ImageUploadLog getImageUploadLog(ImageUploadLog record) {

        logger.info("getImageUploadLog");
        try {

            return imageUploadLogMapper.queryImageUploadLog(record);
        } catch (Exception e) {
            logger.error("getImageUploadLog", e);
        }

        return null;
    }

    @Override
    public boolean createImageUploadLog(ImageUploadLog record) {

        logger.info("createImageUploadLog");
        try {

            int updates = imageUploadLogMapper.insertSelective(record);

            if (updates > 0) {
                return true;
            }
        } catch (Exception e) {
            logger.error("createImageUploadLog", e);
        }

        return false;
    }

    @Override
    public boolean deleteImageUploadLog(String id) {

        logger.info("deleteImageUploadLog");
        try {

            int updates = imageUploadLogMapper.delete(id);

            if (updates > 0) {
                return true;
            }
        } catch (Exception e) {
            logger.error("deleteImageUploadLog", e);
        }

        return false;
    }

    @Override
    public boolean updateImageUploadLog(ImageUploadLog record) {

        logger.info("updateImageUploadLog");
        try {

            int updates = imageUploadLogMapper.updateByPrimaryKeySelective(record);

            if (updates > 0) {
                return true;
            }
        } catch (Exception e) {
            logger.error("updateImageUploadLog", e);
        }

        return false;
    }

    @Override
    public List<ImageUploadLog> queryDelOssImage(String orderId) {

        logger.info("queryDelOssImage");
        try {

            Map<String, Object> parameter = new HashMap<String, Object>();
            parameter.put("orderId", orderId);

            return imageUploadLogMapper.queryDelOssImage(parameter);
        } catch (Exception e) {
            logger.error("queryDelOssImage", e);
        }

        return null;
    }
}

