//package com.yaoyicloud.render;
//
//import java.io.IOException;
//
//import java.io.InputStream;
//import java.util.List;
//import java.util.Map;
//
//import com.deepoove.poi.config.Configure;
//import com.deepoove.poi.config.ConfigureBuilder;
//import com.fasterxml.jackson.core.type.TypeReference;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.yaoyicloud.config.CommonDataCache;
//import com.yaoyicloud.config.FilerepoProperties;
//import com.yaoyicloud.factory.FXYAbstractRender;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.collections4.CollectionUtils;
//import org.apache.commons.collections4.MapUtils;
//
//@Slf4j
//public final class InterestConflictsRender extends FXYAbstractRender {
//    private final FilerepoProperties filerepoProperties;
//    private final CommonDataCache commonDataCache;
//
//    public InterestConflictsRender(String cwd, FilerepoProperties filerepoProperties, CommonDataCache commonDataCache) {
//        super(cwd);
//        this.filerepoProperties = filerepoProperties;
//        this.commonDataCache = commonDataCache;
//    }
//
//    @Override
//    protected String getBasicPath() throws IOException {
//        return filerepoProperties.getBasePath();
//    }
//
//    @Override
//    protected String getReportImagePath() {
//        return filerepoProperties.getReportImagePath();
//    }
//
//    /**
//     * Docx 渲染
//     *
//     * @param info 数据
//     * @param inputStream 模板内容
//     * @return 本地文件目录
//     * @throws IOException
//     */
//    public String renderDocx(String info, InputStream inputStream,
//                             String relationId) throws IOException {
//        log.info("开始渲染利益冲突报告模块，relationId: {}", relationId);
//
//        // 配置POI-TL渲染器
//        ConfigureBuilder builder = Configure.builder();
//        builder.addPlugin('^', this.pictureRenderPolicy());
//
//        ObjectMapper objectMapper = new ObjectMapper();
//        Map<String, Object> data = objectMapper.readValue(info, new TypeReference<Map<String, Object>>() {});
//
//        Map<String, Object> commonDataCacheData = commonDataCache.getData(relationId);
//        if (MapUtils.isNotEmpty(commonDataCacheData)) {
//            data.putAll(commonDataCacheData);
//        }
//        fillDefaultValues(data);
//        try {
//            // 渲染文档
//            String resultPath = this.renderDocx(data, inputStream, builder, relationId, "interestConflicts");
//            log.info("渲染利益冲突报告模块成功，文件路径: {}", resultPath);
//            return resultPath;
//        } catch (Exception e) {
//            log.error("渲染利益冲突报告模块失败，relationId: {}", relationId, e);
//            throw new IOException("文档渲染失败", e);
//        }
//    }
//
//    /**
//     * 填充默认值，确保所有必要字段都存在
//     */
//    private void fillDefaultValues(Map<String, Object> data) {
//        List<Map<String, Object>> items = (List<Map<String, Object>>) data.get("interestConflicts");
//        if (CollectionUtils.isEmpty(items)) {
//            data.put("interestConflictsAltText", "未上传");
//        }
//
//    }
//}
