package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.WyPlatformBillTemplateExportLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.WyPlatformBillTemplateMapper;
import com.ruoyi.system.domain.WyPlatformBillTemplate;
import com.ruoyi.system.service.IWyPlatformBillTemplateService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 酒单套打模板Service业务层处理
 *
 * @author ruoyi
 * @date 2025-02-15
 */
@Service
public class WyPlatformBillTemplateServiceImpl implements IWyPlatformBillTemplateService {
    @Autowired
    private WyPlatformBillTemplateMapper wyPlatformBillTemplateMapper;

    /**
     * 查询酒单套打模板
     *
     * @param id 酒单套打模板主键
     * @return 酒单套打模板
     */
    @Override
    public WyPlatformBillTemplate selectWyPlatformBillTemplateById(Long id) {
        return wyPlatformBillTemplateMapper.selectWyPlatformBillTemplateById(id);
    }

    /**
     * 查询酒单套打模板列表
     *
     * @param wyPlatformBillTemplate 酒单套打模板
     * @return 酒单套打模板
     */
    @Override
    public List<WyPlatformBillTemplate> selectWyPlatformBillTemplateList(WyPlatformBillTemplate wyPlatformBillTemplate) {
        return wyPlatformBillTemplateMapper.selectWyPlatformBillTemplateList(wyPlatformBillTemplate);
    }

    /**
     * 新增酒单套打模板
     *
     * @param wyPlatformBillTemplate 酒单套打模板
     * @return 结果
     */
    @Override
    public int insertWyPlatformBillTemplate(WyPlatformBillTemplate wyPlatformBillTemplate) {
        wyPlatformBillTemplate.setCreateTime(DateUtils.getNowDate());
        return wyPlatformBillTemplateMapper.insertWyPlatformBillTemplate(wyPlatformBillTemplate);
    }

    /**
     * 修改酒单套打模板
     *
     * @param wyPlatformBillTemplate 酒单套打模板
     * @return 结果
     */
    @Override
    public int updateWyPlatformBillTemplate(WyPlatformBillTemplate wyPlatformBillTemplate) {
        wyPlatformBillTemplate.setUpdateTime(DateUtils.getNowDate());
        return wyPlatformBillTemplateMapper.updateWyPlatformBillTemplate(wyPlatformBillTemplate);
    }

    /**
     * 保存导出记录
     */
    @Transactional
    @Override
    public int saveExportRecord(WyPlatformBillTemplate template) {
        if (template.getTotalExportCount() == null) {
            template.setTotalExportCount(1L);
        } else {
            template.setTotalExportCount(template.getTotalExportCount() + 1);
        }
        updateWyPlatformBillTemplate(template);
        final WyPlatformBillTemplateExportLog wyPlatformBillTemplateExportLog = new WyPlatformBillTemplateExportLog();
        wyPlatformBillTemplateExportLog.setTemplateId(template.getId());
        wyPlatformBillTemplateExportLog.setBarId(template.getBarId());
        wyPlatformBillTemplateExportLog.setTemplateType(template.getTemplateType());
        wyPlatformBillTemplateExportLog.setRemark(template.getRemark());
        return insertTemplateExportLog(wyPlatformBillTemplateExportLog);
    }

    /**
     * 批量删除酒单套打模板
     *
     * @param ids 需要删除的酒单套打模板主键
     * @return 结果
     */
    @Override
    public int deleteWyPlatformBillTemplateByIds(Long[] ids) {
        return wyPlatformBillTemplateMapper.deleteWyPlatformBillTemplateByIds(ids);
    }

    /**
     * 删除酒单套打模板信息
     *
     * @param id 酒单套打模板主键
     * @return 结果
     */
    @Override
    public int deleteWyPlatformBillTemplateById(Long id) {
        return wyPlatformBillTemplateMapper.deleteWyPlatformBillTemplateById(id);
    }

    @Override
    public List<WyPlatformBillTemplateExportLog> selectTemplateExportLogList(WyPlatformBillTemplateExportLog wyPlatformBillTemplateExportLog) {
        return wyPlatformBillTemplateMapper.selectTemplateExportLogList(wyPlatformBillTemplateExportLog);
    }

    @Override
    public int insertTemplateExportLog(WyPlatformBillTemplateExportLog wyPlatformBillTemplateExportLog) {
        wyPlatformBillTemplateExportLog.setCreateTime(DateUtils.getNowDate());
        return wyPlatformBillTemplateMapper.insertTemplateExportLog(wyPlatformBillTemplateExportLog);
    }

    @Override
    public int updateTemplateExportLog(WyPlatformBillTemplateExportLog wyPlatformBillTemplateExportLog) {
        wyPlatformBillTemplateExportLog.setUpdateTime(DateUtils.getNowDate());
        return wyPlatformBillTemplateMapper.updateTemplateExportLog(wyPlatformBillTemplateExportLog);
    }

    @Override
    public int deleteTemplateExportLog(Long id) {
        return wyPlatformBillTemplateMapper.deleteTemplateExportLog(id);
    }

    @Override
    public WyPlatformBillTemplateExportLog selectTemplateExportLogById(Long id) {
        return wyPlatformBillTemplateMapper.selectTemplateExportLogById(id);
    }

}
