package com.huijy.management.service.impl;

import java.util.List;
import com.huijy.common.utils.DateUtils;
import com.huijy.management.domain.ShopGuestRecord;
import com.huijy.management.service.IShopGuestRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.huijy.management.mapper.ShopSalesRecordMapper;
import com.huijy.management.domain.ShopSalesRecord;
import com.huijy.management.service.IShopSalesRecordService;

/**
 * 店铺销售记录Service业务层处理
 *
 * @author luobo
 * @date 2021-09-12
 */
@Service
public class ShopSalesRecordServiceImpl implements IShopSalesRecordService
{
    @Autowired
    private ShopSalesRecordMapper shopSalesRecordMapper;

    @Autowired
    private IShopGuestRecordService shopGuestRecordService;

    /**
     * 查询店铺销售记录
     *
     * @param shopSalesRecordId 店铺销售记录主键
     * @return 店铺销售记录
     */
    @Override
    public ShopSalesRecord selectShopSalesRecordByShopSalesRecordId(Long shopSalesRecordId)
    {
        return shopSalesRecordMapper.selectShopSalesRecordByShopSalesRecordId(shopSalesRecordId);
    }

    /**
     * 查询店铺销售记录列表
     *
     * @param shopSalesRecord 店铺销售记录
     * @return 店铺销售记录
     */
    @Override
    public List<ShopSalesRecord> selectShopSalesRecordList(ShopSalesRecord shopSalesRecord)
    {
        return shopSalesRecordMapper.selectShopSalesRecordList(shopSalesRecord);
    }

    /**
     * 新增店铺销售记录
     *
     * @param shopSalesRecord 店铺销售记录
     * @return 结果
     */
    @Override
    public int insertShopSalesRecord(ShopSalesRecord shopSalesRecord)
    {
        shopSalesRecord.setCreateTime(DateUtils.getNowDate());
       Integer row = shopSalesRecordMapper.insertShopSalesRecord(shopSalesRecord);
       if (shopSalesRecord.getShopGuestRecordList()!=null && shopSalesRecord.getShopGuestRecordList().size()>0){
           for (ShopGuestRecord item:shopSalesRecord.getShopGuestRecordList()){
               item.setShopId(shopSalesRecord.getShopId());
               item.setCreateTime(shopSalesRecord.getCreateTime());
               shopGuestRecordService.insertShopGuestRecord(item);
           }
       }
        return row;
    }

    /**
     * 修改店铺销售记录
     *
     * @param shopSalesRecord 店铺销售记录
     * @return 结果
     */
    @Override
    public int updateShopSalesRecord(ShopSalesRecord shopSalesRecord)
    {
        return shopSalesRecordMapper.updateShopSalesRecord(shopSalesRecord);
    }

    /**
     * 批量删除店铺销售记录
     *
     * @param shopSalesRecordIds 需要删除的店铺销售记录主键
     * @return 结果
     */
    @Override
    public int deleteShopSalesRecordByShopSalesRecordIds(Long[] shopSalesRecordIds)
    {
        return shopSalesRecordMapper.deleteShopSalesRecordByShopSalesRecordIds(shopSalesRecordIds);
    }

    /**
     * 删除店铺销售记录信息
     *
     * @param shopSalesRecordId 店铺销售记录主键
     * @return 结果
     */
    @Override
    public int deleteShopSalesRecordByShopSalesRecordId(Long shopSalesRecordId)
    {
        return shopSalesRecordMapper.deleteShopSalesRecordByShopSalesRecordId(shopSalesRecordId);
    }
}
