package com.mall.product.service.impl;

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.mall.common.domain.vo.result.PageResult;
import com.mall.product.domain.dto.AttrAttrgroupRelationDto;
import com.mall.product.domain.entity.AttrAttrgroupRelation;
import com.mall.product.domain.vo.AttrAttrgroupRelationVo;
import com.mall.product.mapper.AttrAttrgroupRelationMapper;
import com.mall.product.service.AttrAttrgroupRelationService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 属性&属性分组关联 服务实现类
 * </p>
 *
 * @author Bunny
 * @since 2025-07-04 14:05:53
 */
@Service
@Transactional
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationMapper, AttrAttrgroupRelation> implements AttrAttrgroupRelationService {

    /**
     * * 属性&属性分组关联 服务实现类
     *
     * @param pageParams 属性&属性分组关联分页查询page对象
     * @param dto        属性&属性分组关联分页查询对象
     * @return 查询分页属性&属性分组关联返回对象
     */
    @Override
    public PageResult<AttrAttrgroupRelationVo> getAttrAttrgroupRelationPage(Page<AttrAttrgroupRelation> pageParams, AttrAttrgroupRelationDto dto) {
        IPage<AttrAttrgroupRelationVo> page = baseMapper.selectListByPage(pageParams, dto);

        return PageResult.<AttrAttrgroupRelationVo>builder()
                .list(page.getRecords())
                .pageNo(page.getCurrent())
                .pageSize(page.getSize())
                .total(page.getTotal())
                .build();
    }

    /**
     * 添加属性&属性分组关联
     *
     * @param dto 属性&属性分组关联添加
     */
    @Override
    public void addAttrAttrgroupRelation(AttrAttrgroupRelationDto dto) {
        AttrAttrgroupRelation attrAttrgroupRelation = new AttrAttrgroupRelation();
        BeanUtils.copyProperties(dto, attrAttrgroupRelation);
        save(attrAttrgroupRelation);
    }

    /**
     * 更新属性&属性分组关联
     *
     * @param dto 属性&属性分组关联更新
     */
    @Override
    public void updateAttrAttrgroupRelation(AttrAttrgroupRelationDto dto) {
        AttrAttrgroupRelation attrAttrgroupRelation = new AttrAttrgroupRelation();
        BeanUtils.copyProperties(dto, attrAttrgroupRelation);
        updateById(attrAttrgroupRelation);
    }

    /**
     * 删除|批量删除属性&属性分组关联
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteAttrAttrgroupRelation(List<Long> ids) {
        removeByIds(ids);
    }
}