package com.ycwl.basic.service.pc.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ycwl.basic.mapper.FaceSampleMapper;
import com.ycwl.basic.model.pc.faceSample.entity.FaceSampleEntity;
import com.ycwl.basic.model.pc.faceSample.req.FaceSampleReqQuery;
import com.ycwl.basic.model.pc.faceSample.resp.FaceSampleRespVO;
import com.ycwl.basic.service.pc.FaceSampleService;
import com.ycwl.basic.utils.ApiResponse;
import com.ycwl.basic.utils.SnowFlakeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author：longbinbin
 * @Date：2024/12/2 16:39
 */
@Service
public class FaceSampleServiceImpl implements FaceSampleService {
    @Autowired
    private FaceSampleMapper faceSampleMapper;

    @Override
    public ApiResponse<PageInfo<FaceSampleRespVO>> pageQuery(FaceSampleReqQuery faceSampleReqQuery) {
        PageHelper.startPage(faceSampleReqQuery.getPageNum(),faceSampleReqQuery.getPageSize());
        List<FaceSampleRespVO> list = faceSampleMapper.list(faceSampleReqQuery);
        PageInfo<FaceSampleRespVO> pageInfo = new PageInfo<>(list);
        return ApiResponse.success(pageInfo);
    }

    @Override
    public ApiResponse<List<FaceSampleRespVO>> list(FaceSampleReqQuery faceSampleReqQuery) {
        return ApiResponse.success(faceSampleMapper.list(faceSampleReqQuery));
    }

    @Override
    public ApiResponse<FaceSampleRespVO> getById(Long id) {
        return ApiResponse.success(faceSampleMapper.getById(id));
    }

    @Override
    public ApiResponse<Integer> add(FaceSampleEntity faceSample) {
        faceSample.setId(SnowFlakeUtil.getLongId());
        int i = faceSampleMapper.add(faceSample);
        if (i == 0) {
            return ApiResponse.fail("添加失败");
        }
        return ApiResponse.success(i);
    }

    @Override
    public ApiResponse<Integer> deleteById(Long id) {
        int i = faceSampleMapper.deleteById(id);
        if (i == 0) {
            return ApiResponse.fail("删除失败");
        }
        return ApiResponse.success(i);
    }

    @Override
    public ApiResponse<Integer> deleteByIds(List<Long> ids) {
        int i = faceSampleMapper.deleteByIds(ids);
        if (i == 0) {
            return ApiResponse.fail("删除失败");
        }
        return ApiResponse.success(i);
    }

    @Override
    public ApiResponse<Integer> update(FaceSampleEntity faceSample) {
        int i = faceSampleMapper.update(faceSample);
        if (i == 0) {
            return ApiResponse.fail("修改失败");
        }
        return ApiResponse.success(i);
    }
}
