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

import java.util.List;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.canteen.core.kitchen.mapper.KitchenDeviceSensorMetricMapper;
import com.bonus.canteen.core.kitchen.domain.KitchenDeviceSensorMetric;
import com.bonus.canteen.core.kitchen.service.IKitchenDeviceSensorMetricService;

/**
 * 厨房设备衡量指标设置Service业务层处理
 * 
 * @author xsheng
 * @date 2025-06-16
 */
@Service
public class KitchenDeviceSensorMetricServiceImpl implements IKitchenDeviceSensorMetricService {
    @Autowired
    private KitchenDeviceSensorMetricMapper kitchenDeviceSensorMetricMapper;

    /**
     * 查询厨房设备衡量指标设置
     * 
     * @param measureId 厨房设备衡量指标设置主键
     * @return 厨房设备衡量指标设置
     */
    @Override
    public KitchenDeviceSensorMetric selectKitchenDeviceSensorMetricByMeasureId(Long measureId) {
        return kitchenDeviceSensorMetricMapper.selectKitchenDeviceSensorMetricByMeasureId(measureId);
    }

    /**
     * 查询厨房设备衡量指标设置列表
     * 
     * @param kitchenDeviceSensorMetric 厨房设备衡量指标设置
     * @return 厨房设备衡量指标设置
     */
    @Override
    public List<KitchenDeviceSensorMetric> selectKitchenDeviceSensorMetricList(KitchenDeviceSensorMetric kitchenDeviceSensorMetric) {
        return kitchenDeviceSensorMetricMapper.selectKitchenDeviceSensorMetricList(kitchenDeviceSensorMetric);
    }

    /**
     * 新增厨房设备衡量指标设置
     * 
     * @param kitchenDeviceSensorMetric 厨房设备衡量指标设置
     * @return 结果
     */
    @Override
    public int insertKitchenDeviceSensorMetric(KitchenDeviceSensorMetric kitchenDeviceSensorMetric) {
        kitchenDeviceSensorMetric.setCreateTime(DateUtils.getNowDate());
        kitchenDeviceSensorMetric.setCreateBy(SecurityUtils.getUsername());
        try {
            return kitchenDeviceSensorMetricMapper.insertKitchenDeviceSensorMetric(kitchenDeviceSensorMetric);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    @Override
    public int batchInsertKitchenDeviceSensorMetric(List<KitchenDeviceSensorMetric> list) {
        try {
            int count = 0;
            for (KitchenDeviceSensorMetric metric : list) {
                metric.setCreateTime(DateUtils.getNowDate());
                metric.setCreateBy(SecurityUtils.getUsername());
                count += kitchenDeviceSensorMetricMapper.insertKitchenDeviceSensorMetric(metric);
            }
            return count;
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 修改厨房设备衡量指标设置
     * 
     * @param kitchenDeviceSensorMetric 厨房设备衡量指标设置
     * @return 结果
     */
    @Override
    public int updateKitchenDeviceSensorMetric(KitchenDeviceSensorMetric kitchenDeviceSensorMetric) {
        kitchenDeviceSensorMetric.setUpdateTime(DateUtils.getNowDate());
        kitchenDeviceSensorMetric.setUpdateBy(SecurityUtils.getUsername());
        try {
            return kitchenDeviceSensorMetricMapper.updateKitchenDeviceSensorMetric(kitchenDeviceSensorMetric);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    @Override
    public int batchUpdateKitchenDeviceSensorMetric(List<KitchenDeviceSensorMetric> list) {
        try {
            int count = 0;
            for (KitchenDeviceSensorMetric metric : list) {
                metric.setUpdateTime(DateUtils.getNowDate());
                metric.setUpdateBy(SecurityUtils.getUsername());
                count += kitchenDeviceSensorMetricMapper.updateKitchenDeviceSensorMetric(metric);
            }
            return count;
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    @Override
    public int rollbackKitchenDeviceSensorMetricByMeasureIds(Long[] measureIds) {
        return kitchenDeviceSensorMetricMapper.rollbackKitchenDeviceSensorMetricByMeasureIds(measureIds);
    }

    /**
     * 批量删除厨房设备衡量指标设置
     * 
     * @param measureIds 需要删除的厨房设备衡量指标设置主键
     * @return 结果
     */
    @Override
    public int deleteKitchenDeviceSensorMetricByMeasureIds(Long[] measureIds) {
        return kitchenDeviceSensorMetricMapper.deleteKitchenDeviceSensorMetricByMeasureIds(measureIds);
    }

    /**
     * 删除厨房设备衡量指标设置信息
     * 
     * @param measureId 厨房设备衡量指标设置主键
     * @return 结果
     */
    @Override
    public int deleteKitchenDeviceSensorMetricByMeasureId(Long measureId) {
        return kitchenDeviceSensorMetricMapper.deleteKitchenDeviceSensorMetricByMeasureId(measureId);
    }
}
