zhoushihao
2024-12-30 2e20e85173b764e43a6e4022072bc8fb0cc61330
hangzhoumesParent/moduleService/howllowGlassModule/src/main/java/com/mes/hollow/controller/HollowBigStorageCageController.java
@@ -2,17 +2,30 @@
import com.mes.hollow.entity.dto.HollowBigStorageAndDetailsDTO;
import com.mes.hollow.entity.dto.LisecHollowDetails;
import com.mes.hollow.entity.vo.HollowBigStorageDetailsQueryVO;
import com.mes.hollow.service.HollowBigStorageCageService;
import com.mes.utils.Blank;
import com.mes.utils.Result;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.Version;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.ResponseEntity;
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;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * (HollowBigStorageCage)表控制层
@@ -20,6 +33,7 @@
 * @author makejava
 * @since 2024-11-21 09:22:39
 */
@Api(tags = "中空理片笼详情")
@RestController
@RequestMapping("hollowBigStorageCage")
public class HollowBigStorageCageController {
@@ -31,5 +45,35 @@
    public Result<List<HollowBigStorageAndDetailsDTO>> queryHollowBigStorageCageDetail(@RequestBody HollowBigStorageDetailsQueryVO query) {
        return Result.build(200, "查询成功", hollowBigStorageCageService.queryHollowBigStorageCageDetail(query));
    }
    @PostMapping("/generate")
    public ResponseEntity<FileSystemResource> generate(@RequestBody LisecHollowDetails details) throws IOException, TemplateException {
// 创建和配置Freemarker配置实例
        Configuration cfg = new Configuration(new Version("2.3.29"));
        cfg.setClassForTemplateLoading(HollowBigStorageCageController.class, "/templates/");
        // 创建Calculator实例
        Blank blank = new Blank();
        // 创建数据模型
        Map<String, Object> root = new HashMap<>();
        root.put("blank", blank);
        root.put("details", details);
        // 获取模板
        Template temp = cfg.getTemplate("hollowGlass.ftl");
        // 合并数据模型和模板
        StringWriter out = new StringWriter();
        try {
            temp.process(root, out);
        } catch (TemplateException | IOException e) {
            e.printStackTrace();
        }
        // 输出结果
        System.out.println(out.toString());
        return null;
    }
}