package com.miaxis.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.customer.domain.CustomerInfo;
import com.miaxis.customer.service.ICustomerInfoService;
import com.miaxis.customer.vo.CustomerInfoVo;
import com.miaxis.product.domain.ProductTypeInfo;
import com.miaxis.product.mapper.ProductTypeInfoMapper;
import com.miaxis.product.service.IProductTypeInfoService;
import com.miaxis.product.vo.ProductTypeInfoVo;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
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;

    private final ICustomerInfoService customerInfoService;

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

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

    /**
     * 获取品类详情信息
     * @param id
     * @return
     */
    @Override
    public Response<ProductTypeInfoVo> getProductDetailsById(Long id) {

        return Response.success(productTypeInfoMapper.getProductDetailsById(id));
    }
}
