package com.bonus.canteen.core.kitchen.service.impl;

import java.util.List;

import cn.hutool.core.collection.CollUtil;
import com.bonus.canteen.core.kitchen.domain.constants.SampleCabinetActionTypeEnum;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.canteen.core.kitchen.mapper.KitchenSampleCabinetRecordMapper;
import com.bonus.canteen.core.kitchen.domain.KitchenSampleCabinetRecord;
import com.bonus.canteen.core.kitchen.service.IKitchenSampleCabinetRecordService;

/**
 * 留样柜操作记录Service业务层处理
 * 
 * @author xsheng
 * @date 2025-06-16
 */
@Service
public class KitchenSampleCabinetRecordServiceImpl implements IKitchenSampleCabinetRecordService {
    @Autowired
    private KitchenSampleCabinetRecordMapper kitchenSampleCabinetRecordMapper;

    /**
     * 查询留样柜操作记录
     * 
     * @param recordId 留样柜操作记录主键
     * @return 留样柜操作记录
     */
    @Override
    public KitchenSampleCabinetRecord selectKitchenSampleCabinetRecordByRecordId(Long recordId) {
        return kitchenSampleCabinetRecordMapper.selectKitchenSampleCabinetRecordByRecordId(recordId);
    }

    /**
     * 查询留样柜操作记录列表
     * 
     * @param kitchenSampleCabinetRecord 留样柜操作记录
     * @return 留样柜操作记录
     */
    @Override
    public List<KitchenSampleCabinetRecord> selectKitchenSampleCabinetRecordList(KitchenSampleCabinetRecord kitchenSampleCabinetRecord) {
        List<KitchenSampleCabinetRecord> kitchenSampleCabinetRecordList = kitchenSampleCabinetRecordMapper
                .selectKitchenSampleCabinetRecordList(kitchenSampleCabinetRecord);
        if(CollUtil.isNotEmpty(kitchenSampleCabinetRecordList)) {
            for (KitchenSampleCabinetRecord record : kitchenSampleCabinetRecordList) {
                record.setActionTypeName(SampleCabinetActionTypeEnum.getDescByKey(record.getActionType()));
            }
        }
        return kitchenSampleCabinetRecordList;
    }

    /**
     * 新增留样柜操作记录
     * 
     * @param kitchenSampleCabinetRecord 留样柜操作记录
     * @return 结果
     */
    @Override
    public int insertKitchenSampleCabinetRecord(KitchenSampleCabinetRecord kitchenSampleCabinetRecord) {
        kitchenSampleCabinetRecord.setCreateTime(DateUtils.getNowDate());
        try {
            return kitchenSampleCabinetRecordMapper.insertKitchenSampleCabinetRecord(kitchenSampleCabinetRecord);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 修改留样柜操作记录
     * 
     * @param kitchenSampleCabinetRecord 留样柜操作记录
     * @return 结果
     */
    @Override
    public int updateKitchenSampleCabinetRecord(KitchenSampleCabinetRecord kitchenSampleCabinetRecord) {
        kitchenSampleCabinetRecord.setUpdateTime(DateUtils.getNowDate());
        try {
            return kitchenSampleCabinetRecordMapper.updateKitchenSampleCabinetRecord(kitchenSampleCabinetRecord);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 批量删除留样柜操作记录
     * 
     * @param recordIds 需要删除的留样柜操作记录主键
     * @return 结果
     */
    @Override
    public int deleteKitchenSampleCabinetRecordByRecordIds(Long[] recordIds) {
        return kitchenSampleCabinetRecordMapper.deleteKitchenSampleCabinetRecordByRecordIds(recordIds);
    }

    /**
     * 删除留样柜操作记录信息
     * 
     * @param recordId 留样柜操作记录主键
     * @return 结果
     */
    @Override
    public int deleteKitchenSampleCabinetRecordByRecordId(Long recordId) {
        return kitchenSampleCabinetRecordMapper.deleteKitchenSampleCabinetRecordByRecordId(recordId);
    }
}
