package com.zcloud.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zcloud.common.utils.FileUploadUtil;
import com.zcloud.common.utils.PageUtils;
import com.zcloud.modules.sys.dao.BusImgfilesDao;
import com.zcloud.modules.sys.entity.BusImgfilesEntity;
import com.zcloud.modules.sys.service.BusImgfilesService;
import org.springframework.stereotype.Service;

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

/**
 * @Author fangjiakai
 * @Desc 图片附件(BusImgfiles)表服务实现类
 * @Date 2023-10-19 15:09:20
 */
@Service("busImgfilesService")
public class BusImgfilesServiceImpl extends ServiceImpl<BusImgfilesDao, BusImgfilesEntity> implements BusImgfilesService {

    @Override
    public PageUtils listPage(Map<String, Object> params) {
        Page<Map<String,Object>> page = new Page<>(Integer.parseInt(params.get("curPage").toString()),Integer.parseInt(params.get("limit").toString()));
        params.put("isDelete",0);
        IPage<Map<String,Object>> ipage = baseMapper.listPage(page,params);
        return new PageUtils(ipage);
    }


   @Override
	public void delete(String imgfilesId) {
		BusImgfilesEntity busImgfiles = getById(imgfilesId);
        FileUploadUtil.deleteFile(busImgfiles.getFilepath());

		this.removeById(imgfilesId);
	}

    @Override
    public List<BusImgfilesEntity> queryListByFlexibleParams(String paramName, Object paramValue) {
        QueryWrapper<BusImgfilesEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(paramName, paramValue); // 根据传入的参数名和参数值动态构建查询条件

        return baseMapper.selectList(queryWrapper);
    }

}
