package com.miaxis.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miaxis.common.core.domain.Response;
import com.miaxis.product.domain.ProductTypeInfo;
import com.miaxis.product.mapper.ProductTypeInfoMapper;
import com.miaxis.product.service.IProductTypeInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 品类Service业务层处理
 *
 * @author miaxis
 * @date 2021-03-11
 */
@Service
@RequiredArgsConstructor
public class ProductTypeInfoServiceImpl extends ServiceImpl<ProductTypeInfoMapper, ProductTypeInfo> implements IProductTypeInfoService {

    private final ProductTypeInfoMapper productTypeInfoMapper;

    /**
     * 查询品类列表
     *
     * @param productTypeInfo 品类
     * @return 品类
     */
    @Override
    public List<ProductTypeInfo> selectProductTypeInfoList(ProductTypeInfo productTypeInfo){
        return productTypeInfoMapper.selectProductTypeInfoList(productTypeInfo);
    }

    /**
     * 删除品类
     * @param ids
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Response<Integer> removeProductByIds(Long[] ids) {
        try {
            for (Long id : ids) {
                this.update(new UpdateWrapper<ProductTypeInfo>().set("status",1).eq("id",id));
            }
            return Response.success();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}
