package com.goldenwater.web.controller.efinder;

import com.goldenwater.slgc.entity.efinder.DocFile;
import com.goldenwater.slgc.service.efinder.IDocFileService;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/efinder/pageoffice")
public class PageOfficeController extends BaseController {
    @Autowired
    private IDocFileService docFileService;

    /**
     * 在线打开Word文档（PageOffice集成）
     * 因缺少PageOffice商业库JAR，返回文件信息供前端处理
     */
    @GetMapping("/open/{fileId}")
    public AjaxResult open(@PathVariable Long fileId) {
        DocFile file = docFileService.selectById(fileId);
        if (file == null) {
            return error("文件不存在");
        }
        Map<String, Object> result = new HashMap<>();
        result.put("id", file.getId());
        result.put("name", file.getName());
        result.put("path", file.getPath());
        result.put("type", file.getType());
        result.put("size", file.getSize());
        return success(result);
    }
}
