package com.fs.qw.service.impl;

import com.fs.qw.domain.QwMaterial;
import com.fs.qw.dto.QwMaterialDTO;
import com.fs.qw.mapper.QwMaterialMapper;
import com.fs.qw.service.IQwMaterialService;
import com.fs.qw.utils.QwUploadUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@Service
public class QwMaterialServiceImpl implements IQwMaterialService
{
    @Autowired
    private QwMaterialMapper qwMaterialMapper;

    /**
     * 查询企微素材库
     *
     * @param id 企微素材库ID
     * @return 企微素材库
     */
    @Override
    public QwMaterial selectQwMaterialById(Long id)
    {
        return qwMaterialMapper.selectById(id);
    }

    /**
     * 查询企微素材库列表
     *
     * @param qwMaterial 企微素材库
     * @return 企微素材库
     */
    @Override
    public List<QwMaterial> selectQwMaterialList(QwMaterial qwMaterial)
    {
        return qwMaterialMapper.selectQwMaterialList(qwMaterial);
    }

    @Override
    public int insertQwsMaterials(QwMaterialDTO qwMaterialDTO) throws Exception{
//        QwMaterial qwMaterial = QwUploadUtil.uploads(file,qwMaterialDTO.getDeviceId());
        QwMaterial qwMaterial = new QwMaterial();
        BeanUtils.copyProperties(qwMaterialDTO.getData(),qwMaterial);
        qwMaterial.setUrl(qwMaterialDTO.getUrl());
        qwMaterial.setFileName(qwMaterialDTO.getFileName());
        qwMaterial.setGroupId(qwMaterialDTO.getGroupId());
        qwMaterial.setCompanyUserId(qwMaterialDTO.getCompanyUserId());
        return qwMaterialMapper.insertQwMaterial(qwMaterial);
    }

    /**
     * 修改企微素材库
     *
     * @param qwMaterial 企微素材库
     * @return 结果
     */
    @Override
    public int updateQwMaterial(QwMaterial qwMaterial)
    {
        return qwMaterialMapper.updateQwMaterial(qwMaterial);
    }

    /**
     * 批量删除企微素材库
     *
     * @param ids 需要删除的企微素材库ID
     * @return 结果
     */
    @Override
    public int deleteQwMaterialByIds(Long[] ids)
    {
        return qwMaterialMapper.deleteQwMaterialByIds(ids);
    }

    /**
     * 删除企微素材库信息
     *
     * @param id 企微素材库ID
     * @return 结果
     */
    @Override
    public int deleteQwMaterialById(Long id)
    {
        return qwMaterialMapper.deleteQwMaterialById(id);
    }
}
