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

import java.util.List;

import cn.hutool.core.collection.CollUtil;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.houqin.utils.SM4EncryptUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.canteen.core.kitchen.mapper.KitchenStaffMorningCheckMapper;
import com.bonus.canteen.core.kitchen.domain.KitchenStaffMorningCheck;
import com.bonus.canteen.core.kitchen.service.IKitchenStaffMorningCheckService;

/**
 * 厨房员工晨检记录Service业务层处理
 * 
 * @author xsheng
 * @date 2025-06-16
 */
@Service
public class KitchenStaffMorningCheckServiceImpl implements IKitchenStaffMorningCheckService {
    @Autowired
    private KitchenStaffMorningCheckMapper kitchenStaffMorningCheckMapper;

    /**
     * 查询厨房员工晨检记录
     * 
     * @param checkId 厨房员工晨检记录主键
     * @return 厨房员工晨检记录
     */
    @Override
    public KitchenStaffMorningCheck selectKitchenStaffMorningCheckByCheckId(Long checkId) {
        return kitchenStaffMorningCheckMapper.selectKitchenStaffMorningCheckByCheckId(checkId);
    }

    /**
     * 查询厨房员工晨检记录列表
     * 
     * @param kitchenStaffMorningCheck 厨房员工晨检记录
     * @return 厨房员工晨检记录
     */
    @Override
    public List<KitchenStaffMorningCheck> selectKitchenStaffMorningCheckList(KitchenStaffMorningCheck kitchenStaffMorningCheck) {
        String encryptedSearchValue = SM4EncryptUtils.sm4Encrypt(kitchenStaffMorningCheck.getSearchValue());
        kitchenStaffMorningCheck.setEncryptedSearchValue(encryptedSearchValue);
        List<KitchenStaffMorningCheck> kitchenStaffMorningCheckList = kitchenStaffMorningCheckMapper
                .selectKitchenStaffMorningCheckList(kitchenStaffMorningCheck);
        if(CollUtil.isNotEmpty(kitchenStaffMorningCheckList)) {
            kitchenStaffMorningCheckList.forEach(value -> {
                value.setPhonenumber(SM4EncryptUtils.sm4Decrypt(value.getPhonenumber()));
            });
        }

        return kitchenStaffMorningCheckList;
    }

    /**
     * 新增厨房员工晨检记录
     * 
     * @param kitchenStaffMorningCheck 厨房员工晨检记录
     * @return 结果
     */
    @Override
    public int insertKitchenStaffMorningCheck(KitchenStaffMorningCheck kitchenStaffMorningCheck) {
        kitchenStaffMorningCheck.setCreateTime(DateUtils.getNowDate());
        try {
            return kitchenStaffMorningCheckMapper.insertKitchenStaffMorningCheck(kitchenStaffMorningCheck);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 修改厨房员工晨检记录
     * 
     * @param kitchenStaffMorningCheck 厨房员工晨检记录
     * @return 结果
     */
    @Override
    public int updateKitchenStaffMorningCheck(KitchenStaffMorningCheck kitchenStaffMorningCheck) {
        kitchenStaffMorningCheck.setUpdateTime(DateUtils.getNowDate());
        try {
            return kitchenStaffMorningCheckMapper.updateKitchenStaffMorningCheck(kitchenStaffMorningCheck);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 批量删除厨房员工晨检记录
     * 
     * @param checkIds 需要删除的厨房员工晨检记录主键
     * @return 结果
     */
    @Override
    public int deleteKitchenStaffMorningCheckByCheckIds(Long[] checkIds) {
        return kitchenStaffMorningCheckMapper.deleteKitchenStaffMorningCheckByCheckIds(checkIds);
    }

    /**
     * 删除厨房员工晨检记录信息
     * 
     * @param checkId 厨房员工晨检记录主键
     * @return 结果
     */
    @Override
    public int deleteKitchenStaffMorningCheckByCheckId(Long checkId) {
        return kitchenStaffMorningCheckMapper.deleteKitchenStaffMorningCheckByCheckId(checkId);
    }
}
