package com.zcloud.service.system.impl;

import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.mapper.datasource.system.ImgFilesMapper;
import com.zcloud.service.system.ImgFilesService;
import com.zcloud.util.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 说明：图片管理
 * 作者：luoxiaobao
 * 时间：2020-12-24
 * 官网：www.zcloudchina.com
 */
@Service
@Transactional //开启事物
public class ImgFilesServiceImpl implements ImgFilesService {

	@Autowired
	private ImgFilesMapper imgfilesMapper;

	/**新增
	 * @param pd
	 * @throws Exception
	 */
	public void save(PageData pd)throws Exception{
		imgfilesMapper.save(pd);
	}

	/**删除
	 * @param pd
	 * @throws Exception
	 */
	public void delete(PageData pd)throws Exception{
		imgfilesMapper.delete(pd);
	}

	/**删除
	 * @param pd
	 * @throws Exception
	 */
	public void deleteList(PageData pd)throws Exception{
		imgfilesMapper.deleteList(pd);
	}

	/**修改
	 * @param pd
	 * @throws Exception
	 */
	public void edit(PageData pd)throws Exception{
		imgfilesMapper.edit(pd);
	}

	/**列表
	 * @param page
	 * @throws Exception
	 */
	public List<PageData> list(Page page)throws Exception{
		return imgfilesMapper.datalistPage(page);
	}

	/**列表(全部)
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> listAll(PageData pd)throws Exception{
		return imgfilesMapper.listAll(pd);
	}

	/**通过id获取数据
	 * @param pd
	 * @throws Exception
	 */
	public PageData findById(PageData pd)throws Exception{
		return imgfilesMapper.findById(pd);
	}

	/**批量删除
	 * @param ArrayDATA_IDS
	 * @throws Exception
	 */
	public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
		imgfilesMapper.deleteAll(ArrayDATA_IDS);
	}

	/**列表(全部)
	 * @param pd
	 * @throws Exception
	 */
	public List<PageData> listAllByIds(PageData pd)throws Exception{
		return imgfilesMapper.listAllByIds(pd);
	}

	@Override
	public void deleteInspectionHiddenFile(PageData pd) throws Exception {
		imgfilesMapper.deleteInspectionHiddenFile(pd);
	}

	@Override
	public void deleteByPath(PageData pd) throws Exception {
		imgfilesMapper.deleteByPath(pd);
	}

	/**
	 * 根据标识 和 类型获取 附件信息
	 * @param key
	 * @param type
	 * @return
	 * @throws Exception
	 */
	public List<PageData> getListByKeyAndType (Object key ,String type) throws Exception{
		if(!Tools.isEmpty(key)){
			PageData pd = new PageData();
			pd.put("FOREIGN_KEY",key);
			pd.put("TYPE", type);
			return imgfilesMapper.listAll(pd);
		}
		return new ArrayList<>();
	}
}

