package com.cf.imes.module.plan.controller.admin.orderimport;

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
import com.cf.imes.module.plan.service.orderImport.WebCadOrderImportService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import jakarta.annotation.Resource;

import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.IMPORT;
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.WEBCAD_ORDER_IMPORT_ORGANID_EMPTY_ERROR;

/**
 * @author Gqr
 * @since 2025/3/4 10:22
 */
@Tag(name = "管理后台 - 订单导入管理")
@RestController
@RequestMapping("/plan/order")
public class OrderImportController {
    @Resource
    private WebCadOrderImportService webCadOrderImportService;

    @PostMapping("/webcad/import")
    @Operation(summary = "webcad拆单导入订单")
    @OperateLog(type = IMPORT)
    public CommonResult<Boolean> webCadOrderImport(@RequestParam("file") MultipartFile file) {
        Long organId = OrganContextHolder.getOrganId();

        if (ObjectUtil.isNull(organId)) {
            throw new ServiceException(WEBCAD_ORDER_IMPORT_ORGANID_EMPTY_ERROR);
        }
        webCadOrderImportService.webCadOrderImport(file);
        return CommonResult.success(true);
    }
}
