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.ProdAttrPrice;
import com.xingxi.master.product.mapper.ProdAttrPriceMapper;
import com.xingxi.master.product.service.IProdAttrPriceService;
import org.springframework.stereotype.Service;

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

/**
 * 商品属性价格Service业务层处理
 *
 * @author xingxi
 * @date 2025-03-06
 */
@Service
public class ProdAttrPriceServiceImpl implements IProdAttrPriceService {
    @Resource
    private ProdAttrPriceMapper prodAttrPriceMapper;

    /**
     * 查询商品属性价格
     *
     * @param prodAttrPriceId 商品属性价格主键
     * @return 商品属性价格
     */
    @Override
    public ProdAttrPrice selectProdAttrPriceByProdAttrPriceId(Long prodAttrPriceId) {
        return prodAttrPriceMapper.selectProdAttrPriceByProdAttrPriceId(prodAttrPriceId);
    }

    /**
     * 查询商品属性价格列表
     *
     * @param prodAttrPrice 商品属性价格
     * @return 商品属性价格
     */
    @Override
    public List<ProdAttrPrice> selectProdAttrPriceList(ProdAttrPrice prodAttrPrice) {
        return prodAttrPriceMapper.selectProdAttrPriceList(prodAttrPrice);
    }

    /**
     * 新增商品属性价格
     *
     * @param prodAttrPrice 商品属性价格
     * @return 结果
     */
    @Override
    public int insertProdAttrPrice(ProdAttrPrice prodAttrPrice) {
        prodAttrPrice.setCreateTime(DateUtils.getNowDate());
        return prodAttrPriceMapper.insertProdAttrPrice(prodAttrPrice);
    }

    /**
     * 新增商品属性价格
     *
     * @param prodAttrPriceList 商品属性价格
     * @return 结果
     */
    @Override
    public int batchInsertProdAttrPrice(List<ProdAttrPrice> prodAttrPriceList) {
        return prodAttrPriceMapper.batchInsertProdAttrPrice(prodAttrPriceList);
    }

    /**
     * 修改商品属性价格
     *
     * @param prodAttrPrice 商品属性价格
     * @return 结果
     */
    @Override
    public int updateProdAttrPrice(ProdAttrPrice prodAttrPrice) {
        ProdAttrPrice result = prodAttrPriceMapper.selectProdAttrPriceByProdAttrPriceId(prodAttrPrice.getProdAttrPriceId());
        if (result == null) {
            prodAttrPrice.setDelFlag(EDelFlag.NO.getVal());
            prodAttrPrice.setCreateUser(ShiroUtils.getLoginName());
            prodAttrPrice.setCreateTime(DateUtils.getNowDate());
            return prodAttrPriceMapper.insertProdAttrPrice(prodAttrPrice);
        } else {
            prodAttrPrice.setUpdateUser(ShiroUtils.getLoginName());
            prodAttrPrice.setUpdateTime(DateUtils.getNowDate());
            return prodAttrPriceMapper.updateProdAttrPrice(prodAttrPrice);
        }
    }

    /**
     * 批量删除商品属性价格
     *
     * @param prodAttrPriceIds 需要删除的商品属性价格主键
     * @return 结果
     */
    @Override
    public int deleteProdAttrPriceByProdAttrPriceIds(String prodAttrPriceIds) {
        return prodAttrPriceMapper.deleteProdAttrPriceByProdAttrPriceIds(Convert.toStrArray(prodAttrPriceIds));
    }

    /**
     * 删除商品属性价格信息
     *
     * @param prodAttrPriceId 商品属性价格主键
     * @return 结果
     */
    @Override
    public int deleteProdAttrPriceByProdAttrPriceId(Long prodAttrPriceId) {
        return prodAttrPriceMapper.deleteProdAttrPriceByProdAttrPriceId(prodAttrPriceId);
    }

    /**
     * 逻辑删除商品属性价格
     *
     * @param prodAttrPriceId 商品属性价格主键
     * @return 结果
     */
    @Override
    public int logicDeleteProdAttrPriceByProdAttrPriceId(Long prodAttrPriceId) {
        return prodAttrPriceMapper.logicDeleteProdAttrPriceByProdAttrPriceId(prodAttrPriceId);
    }

    /**
     * 逻辑批量删除商品属性价格
     *
     * @param prodAttrPriceIds 需要删除的数据主键集合
     * @return 结果
     */
    @Override
    public int logicDeleteProdAttrPriceByProdAttrPriceIds(String[] prodAttrPriceIds) {
        return prodAttrPriceMapper.logicDeleteProdAttrPriceByProdAttrPriceIds(prodAttrPriceIds);
    }

    /**
     * 逻辑批量删除商品属性价格
     *
     * @param prodAttrPrice 商品属性价格
     * @return 结果
     */
    @Override
    public int logicDeleteProdAttrPriceByCondition(ProdAttrPrice prodAttrPrice) {
        return prodAttrPriceMapper.logicDeleteProdAttrPriceByCondition(prodAttrPrice);
    }
}
