package com.ruoyi.app.service.impl;

import java.util.List;

import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.app.domain.AppGoods;
import com.ruoyi.app.mapper.AppGoodsMapper;
import com.ruoyi.app.service.IAppGoodsService;
import com.ruoyi.common.constant.AppConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-15
 */
@Service
public class AppGoodsServiceImpl implements IAppGoodsService
{
    @Autowired
    private AppGoodsMapper appGoodsMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param goodsId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public AppGoods selectAppGoodsByGoodsId(String goodsId)
    {
        return appGoodsMapper.selectAppGoodsByGoodsId(goodsId);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param appGoods 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<AppGoods> selectAppGoodsList(AppGoods appGoods)
    {
        return appGoodsMapper.selectAppGoodsList(appGoods);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param appGoods 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertAppGoods(AppGoods appGoods)
    {
        return appGoodsMapper.insertAppGoods(appGoods);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param appGoods 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateAppGoods(AppGoods appGoods)
    {
        return appGoodsMapper.updateAppGoods(appGoods);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param goodsIds 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteAppGoodsByGoodsIds(String[] goodsIds)
    {
        return appGoodsMapper.deleteAppGoodsByGoodsIds(goodsIds);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param goodsId 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteAppGoodsByGoodsId(String goodsId)
    {
        return appGoodsMapper.deleteAppGoodsByGoodsId(goodsId);
    }

    @Override
    public void changeGoodsIsEnableStatus(String[] goodsIds) {
        List<AppGoods> appGoodsList = appGoodsMapper.selectAppGoodsListByGoodsIds(goodsIds);
        if (CollectionUtil.isNotEmpty(appGoodsList)) {
            appGoodsList.forEach(appGoods -> {
                Long oldIsEnabled = appGoods.getGoodsStatus();
                if (AppConstants.GOODS_STATUS_ENABLE.equals(oldIsEnabled)) {
                    appGoods.setGoodsStatus(AppConstants.GOODS_STATUS_DISABLE);
                } else if (AppConstants.GOODS_STATUS_DISABLE.equals(oldIsEnabled)) {
                    appGoods.setGoodsStatus(AppConstants.GOODS_STATUS_ENABLE);
                }
                appGoodsMapper.updateAppGoods(appGoods);
            });
        }
    }
}
