package com.cf.imes.module.system.service.customplateno.factory.service.impl;

import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.module.executor.api.customplateno.OrderCustomPlateNoApi;
import com.cf.imes.module.executor.api.customplateno.dto.CustomPlateNoRuleDTO;
import com.cf.imes.module.system.service.customplateno.factory.service.AbstractCustomPlateNoResetServiceHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

import static com.cf.imes.module.system.enums.ErrorCodeConstants.SYSTEM_CONFIG_CUSTOM_PLATE_NO_ORDER_RESET_UPDATE_ERROR;

/**
 * 自定义板编号房间序号规则复位处理器
 *
 * @author Gqr
 * @since 2024/11/28 19:01
 */
@Service("roomNoRuleResetServiceHandler")
@Slf4j
public class RoomNoRuleResetServiceHandler extends AbstractCustomPlateNoResetServiceHandler {

    @Resource
    private OrderCustomPlateNoApi orderCustomPlateNoApi;

    @Override
    public void reset(CustomPlateNoRuleDTO ruleDTO) {
        // 更新使用该配置的订单中的orderNoSeq
        CommonResult<Boolean> orderResetResult = orderCustomPlateNoApi.resetOrderSeq(ruleDTO);
        if(orderResetResult.isError()) {
            ServiceException serviceException = new ServiceException(SYSTEM_CONFIG_CUSTOM_PLATE_NO_ORDER_RESET_UPDATE_ERROR);
            log.error(orderResetResult.getMsg(), serviceException);
            throw serviceException;
        }
    }
}
