package com.xingxi.master.product.service.impl;

import com.xingxi.common.core.text.Convert;
import com.xingxi.common.enums.EDelFlag;
import com.xingxi.common.utils.DateUtils;
import com.xingxi.common.utils.ShiroUtils;
import com.xingxi.master.product.domain.ProdClass;
import com.xingxi.master.product.mapper.ProdClassMapper;
import com.xingxi.master.product.service.IProdClassService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品分类Service业务层处理
 *
 * @author xingxi
 * @date 2025-03-06
 */
@Service
public class ProdClassServiceImpl implements IProdClassService {
    @Resource
    private ProdClassMapper prodClassMapper;

    /**
     * 查询商品分类
     *
     * @param prodClassId 商品分类主键
     * @return 商品分类
     */
    @Override
    public ProdClass selectProdClassByProdClassId(Long prodClassId) {
        return prodClassMapper.selectProdClassByProdClassId(prodClassId);
    }

    /**
     * 查询商品分类列表
     *
     * @param prodClass 商品分类
     * @return 商品分类
     */
    @Override
    public List<ProdClass> selectProdClassList(ProdClass prodClass) {
        return prodClassMapper.selectProdClassList(prodClass);
    }

    /**
     * 新增商品分类
     *
     * @param prodClass 商品分类
     * @return 结果
     */
    @Override
    public int insertProdClass(ProdClass prodClass) {
        prodClass.setDelFlag(EDelFlag.NO.getVal());
        prodClass.setCreateUser(ShiroUtils.getLoginName());
        prodClass.setCreateTime(DateUtils.getNowDate());
        return prodClassMapper.insertProdClass(prodClass);
    }

    /**
     * 新增商品分类
     *
     * @param prodClassList 商品分类
     * @return 结果
     */
    @Override
    public int batchInsertProdClass(List<ProdClass> prodClassList) {
        return prodClassMapper.batchInsertProdClass(prodClassList);
    }

    /**
     * 修改商品分类
     *
     * @param prodClass 商品分类
     * @return 结果
     */
    @Override
    public int updateProdClass(ProdClass prodClass) {
        prodClass.setUpdateUser(ShiroUtils.getLoginName());
        prodClass.setUpdateTime(DateUtils.getNowDate());
        return prodClassMapper.updateProdClass(prodClass);
    }

    /**
     * 批量删除商品分类
     *
     * @param prodClassIds 需要删除的商品分类主键
     * @return 结果
     */
    @Override
    public int deleteProdClassByProdClassIds(String prodClassIds) {
        return prodClassMapper.deleteProdClassByProdClassIds(Convert.toStrArray(prodClassIds));
    }

    /**
     * 删除商品分类信息
     *
     * @param prodClassId 商品分类主键
     * @return 结果
     */
    @Override
    public int deleteProdClassByProdClassId(Long prodClassId) {
        return prodClassMapper.deleteProdClassByProdClassId(prodClassId);
    }

    /**
     * 逻辑删除商品分类
     *
     * @param prodClassId 商品分类主键
     * @return 结果
     */
    @Override
    public int logicDeleteProdClassByProdClassId(Long prodClassId) {
        return prodClassMapper.logicDeleteProdClassByProdClassId(prodClassId);
    }

    /**
     * 逻辑批量删除商品分类
     *
     * @param prodClassIds 需要删除的数据主键集合
     * @return 结果
     */
    @Override
    public int logicDeleteProdClassByProdClassIds(String[] prodClassIds) {
        return prodClassMapper.logicDeleteProdClassByProdClassIds(prodClassIds);
    }

    /**
     * 逻辑批量删除商品分类
     *
     * @param prodClass 商品分类
     * @return 结果
     */
    @Override
    public int logicDeleteProdClassByCondition(ProdClass prodClass) {
        return prodClassMapper.logicDeleteProdClassByCondition(prodClass);
    }
}
