package com.cf.imes.module.executor.api.customplateno;

import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.module.executor.api.customplateno.dto.CustomPlateNoRuleDTO;
import com.cf.imes.module.executor.service.customplatenorule.CustomPlateNoGenerateRuleService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.util.List;

/**
 * @author Gqr
 * @since 2024/11/28 18:24
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class OrderCustomPlateNoApiImpl implements OrderCustomPlateNoApi {

    @Resource
    List<CustomPlateNoGenerateRuleService> customPlateNoGenerateRuleServices;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public CommonResult<Boolean> resetOrderSeq(CustomPlateNoRuleDTO ruleDTO) {
        for (CustomPlateNoGenerateRuleService ruleService : customPlateNoGenerateRuleServices) {
            if (ruleService.match(ruleDTO.getRuleCode())) {
                ruleService.reset(ruleDTO);
                break;
            }
        }
        return CommonResult.success(true);
    }
}
