package com.pjilisense.flxai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pjilisense.flxai.base.service.impl.CrudServiceImpl;
import com.pjilisense.flxai.dao.FilesDao;
import com.pjilisense.flxai.dto.FilesDTO;
import com.pjilisense.flxai.entity.FilesEntity;
import com.pjilisense.flxai.service.FilesService;
import cn.hutool.core.util.StrUtil;
import com.pjilisense.flxai.utils.MapUtils;
import org.springframework.stereotype.Service;

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

/**
 * ${comments}
 *
 * @author liushujing liushujing@philisense.com
 * @since 1.0.0 2025-01-14
 */
@Service
public class FilesServiceImpl extends CrudServiceImpl<FilesDao, FilesEntity, FilesDTO> implements FilesService {

    @Override
    public QueryWrapper<FilesEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<FilesEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }
//    public QueryWrapper<FilesEntity> getWrapperModifyName(FilesDTO dto){
//        String id = (String)dto.getId();
//
//        QueryWrapper<FilesEntity> wrapper = new QueryWrapper<>();
//        wrapper.eq(StrUtil.isNotBlank(id), "id", id);
//
//        return wrapper;
//    }

    @Override
    public boolean modifyFileName(FilesDTO dto) {
        int cnt = baseDao.modifyFileName(MapUtils.objectToMap(dto));
//        FilesEntity entity = baseDao.selectOne(getWrapperModifyName(dto));
//        entity.setName(dto.getName());
//        int cnt = baseDao.updateById(entity);
        return cnt>0;
    }

    @Override
    public boolean modifyFileStatus(FilesDTO dto) {
        Map map = MapUtils.objectToMap(dto);
        int cnt = baseDao.modifyFileStatus(map);
        return cnt>0;
    }

    @Override
    public boolean modifyFileCategory(FilesDTO dto) {
        Map map = MapUtils.objectToMap(dto);
        int cnt = baseDao.modifyFileCategory(map);
        return cnt>0;
    }
}