# WakeUpCallAreaServiceImpl.java

    package cloud.wconnect.frontoffice.service.endofshift.area.impl;

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.cons.CommonFieldI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.commonlib.util.I18nMessageUtils;
    import cloud.wconnect.frontoffice.cons.endofshift.EndOfShiftAreaEnum;
    import cloud.wconnect.frontoffice.entity.endofshift.ShiftReportInfo;
    import cloud.wconnect.frontoffice.entity.endofshift.ShiftWakeupCall;
    import cloud.wconnect.frontoffice.pojo.dto.endofshift.ShiftWakeupCallDTO;
    import cloud.wconnect.frontoffice.service.endofshift.IShiftReportInfoService;
    import cloud.wconnect.frontoffice.service.endofshift.IShiftWakeupCallService;
    import cloud.wconnect.frontoffice.service.endofshift.area.IEosDelete;
    import cloud.wconnect.frontoffice.service.endofshift.area.IEosSave;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.util.Objects;

    /**
     * Wake up call 区域service
     *
     * @author lichen
     * @date 2025/6/19
     */
    @Service
    @DS("ratelog_manage")
    public class WakeUpCallAreaServiceImpl implements IEosSave, IEosDelete {

        /**
         * 区域类型
         */
        public static final int WAKE_UP_CALL = EndOfShiftAreaEnum.WAKE_UP_CALL.getAreaId();
        @Autowired
        private IShiftReportInfoService shiftReportInfoService;
        @Autowired
        private BeanMapper beanMapper;
        @Autowired
        private IShiftWakeupCallService shiftWakeupCallService;
        @Autowired
        private I18nMessageUtils i18nMessageUtils;

        /**
         * 用于判断是否支持子类执行方法
         *
         * @param type 类型
         * @return java.lang.Boolean
         * @author lichen
         * @date 2025/6/19
         */
        @Override
        public boolean support(Integer type) {
            return type == WAKE_UP_CALL;
        }

        /**
         * 删除排班信息（指定资产指定日期指定排班配置）指定区域数据
         *
         * @param propertyId      资产id
         * @param shiftReportInfo 排班基础信息
         * @param id              区域的主键id
         * @return void
         * @author lichen
         * @date 2025/6/19
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void delete(Integer propertyId, ShiftReportInfo shiftReportInfo, Integer id) {
            //校验Guest Complaint是否存在且属于资产
            shiftWakeupCallService.checkIsExistAndAffiliation(id, propertyId);
            //根据主键删除Wake up call数据
            shiftWakeupCallService.removeById(id);
            //更新为可发送
            shiftReportInfoService.updateCanSend(shiftReportInfo.getId(), true);
        }

        /**
         * 保存排班信息（指定资产指定日期指定排班配置）指定区域的数据
         *
         * @param propertyId      属性ID
         * @param shiftReportInfo 排班基础信息
         * @param object          保存的区域对象
         * @param loginUserId     登录用户id
         * @return void
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void save(Integer propertyId, ShiftReportInfo shiftReportInfo, Object object, int loginUserId) {
            ShiftWakeupCallDTO shiftWakeupCallDTO = (ShiftWakeupCallDTO) object;
            if (Objects.nonNull(shiftWakeupCallDTO.getId())) {
                //校验Guest Complaint是否存在且属于资产
                shiftWakeupCallService.checkIsExistAndAffiliation(shiftWakeupCallDTO.getId(), propertyId);
                //校验状态是否非空
                if (Objects.isNull(shiftWakeupCallDTO.getStatus())) {
                    throw new BadRequestException(CommonErrorI18nConstant.CANNOT_EMPTY,
                            i18nMessageUtils.getErrorParamMapNeedTranslate(CommonFieldI18nConstant.STATUS),
                            BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the status cannot be null");
                }
            }

            //更新为可发送
            shiftReportInfoService.updateCanSend(shiftReportInfo.getId(), true);
            //操作时间
            long operatorTime = DateTimeUtils.nowTimestamp();

            ShiftWakeupCall shiftWakeupCall = beanMapper.map(shiftWakeupCallDTO, ShiftWakeupCall.class);
            shiftWakeupCall.setAlarmTime(shiftWakeupCallDTO.getAlarm());
            shiftWakeupCall.setOperateUid(loginUserId);
            shiftWakeupCall.setOperateTime(operatorTime);
            if (Objects.nonNull(shiftWakeupCallDTO.getId())) {
                //修改
                shiftWakeupCallService.updateById(shiftWakeupCall);
            } else {
                //新增
                shiftWakeupCall.setPropertyId(propertyId);
                shiftWakeupCall.setShiftId(shiftReportInfo.getId());
                shiftWakeupCall.setStatus(false);
                shiftWakeupCallService.save(shiftWakeupCall);
            }
        }
    }