package com.zcloud.basic.info.persistence.repository.impl;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jjb.saas.framework.repository.common.PageHelper;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
import com.zcloud.basic.info.persistence.dataobject.ImgFilesDO;
import com.zcloud.basic.info.persistence.mapper.ImgFilesMapper;
import com.zcloud.basic.info.persistence.repository.ImgFilesRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
 * web-infrastructure
 *
 * @Author zhangyue
 * @Date 2025-10-30 16:10:07
 */
@Service
@RequiredArgsConstructor
public class ImgFilesRepositoryImpl extends BaseRepositoryImpl<ImgFilesMapper, ImgFilesDO> implements ImgFilesRepository {
    private final ImgFilesMapper imgFilesMapper;

    @Override
    public PageResponse<ImgFilesDO> listPage(Map<String, Object> params) {
        IPage<ImgFilesDO> iPage = new Query<ImgFilesDO>().getPage(params);
        QueryWrapper<ImgFilesDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        queryWrapper.orderByDesc("create_time");
        IPage<ImgFilesDO> result = imgFilesMapper.selectPage(iPage, queryWrapper);
        return PageHelper.pageToResponse(result, result.getRecords());
    }

    @Override
    public List<ImgFilesDO> listAll(Map<String, Object> params) {
        QueryWrapper<ImgFilesDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        queryWrapper.orderByDesc("create_time");
//        queryWrapper.select("id", "img_files_id", "file_path", "type", "foreign_key", "file_name", "corpinfo_id");
        return imgFilesMapper.selectList(queryWrapper);
    }

    @Override
    public void deleteList(Long[] ids) {
        UpdateWrapper<ImgFilesDO> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", ids);
        updateWrapper.eq("delete_enum" ,"FALSE");
        updateWrapper.set("delete_enum", "TRUE");
        imgFilesMapper.update(null, updateWrapper);
    }
}

