package com.ruoyi.ccdi.project.controller;

import com.ruoyi.ccdi.project.domain.dto.CcdiBankTagRebuildDTO;
import com.ruoyi.ccdi.project.service.CcdiProjectAccessService;
import com.ruoyi.ccdi.project.service.ICcdiBankTagService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目流水标签控制器
 */
@Tag(name = "项目流水标签")
@Slf4j
@RestController
@RequestMapping("/ccdi/project/tags")
public class CcdiBankTagController extends BaseController {

    @Resource
    private ICcdiBankTagService bankTagService;

    @Resource
    private CcdiProjectAccessService projectAccessService;

    /**
     * 手动提交流水标签重算任务
     */
    @Operation(summary = "手动重算项目流水标签")
    @PostMapping("/rebuild")
    @PreAuthorize("@ss.hasPermi('ccdi:project:edit')")
    public AjaxResult rebuild(@Validated @RequestBody CcdiBankTagRebuildDTO dto) {
        projectAccessService.assertCanOperate(dto.getProjectId());
        String operator = SecurityUtils.getUsername();
        log.info("【流水标签】收到手动重算请求: projectId={}, modelCode={}, operator={}",
            dto.getProjectId(), dto.getModelCode(), operator);
        return success(bankTagService.submitRebuild(dto, operator));
    }
}
