package com.czg.service.account.service.impl;

import cn.hutool.core.util.StrUtil;
import com.czg.market.dto.MkCouponGiftDTO;
import com.czg.market.entity.MkCouponGift;
import com.czg.service.account.util.AliOssUtil;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.SysImageLibrary;
import com.czg.account.service.SysImageLibraryService;
import com.czg.service.account.mapper.SysImageLibraryMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统图库 服务层实现。
 *
 * @author zs
 * @since 2025-09-25
 */
@Service
public class SysImageLibraryServiceImpl extends ServiceImpl<SysImageLibraryMapper, SysImageLibrary> implements SysImageLibraryService {

    @Resource
    private AliOssUtil aliOssUtil;

    @Override
    public Page<SysImageLibrary> getImagePage(String name) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like(SysImageLibrary::getName, StrUtil.isBlank(name) ? null : name)
                .orderBy(SysImageLibrary::getId).desc();
        return pageAs(PageUtil.buildPage(), queryWrapper, SysImageLibrary.class);
    }

    @Override
    public String upload(byte[] bytes, String fileName, String suffix) throws Exception {
        return aliOssUtil.uploadSelfSuffix(bytes, fileName, suffix);
    }

}
