package com.ltkj.web.controller.api; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.ltkj.common.core.domain.AjaxResult; import com.ltkj.web.controller.system.TjCheckController; import com.ltkj.web.controller.system.TjReportController; import org.springframework.beans.factory.annotation.Autowired; 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.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; /** * @Company: 西安路泰科技有限公司 * @Author: zhaowenxuan * @Date: 2025/2/18 10:59 */ @RequestMapping("/api") @RestController public class DefaultController { @Autowired private TjReportController tjReportController; @Autowired private TjCheckController tjCheckController; /** * 提供给三方调用的报告查看接口 * @param response * @param json */ @PostMapping("/viewReport") public void viewReport(HttpServletResponse response, @RequestBody String json){ JSONObject entries = JSONUtil.parseObj(json); String tjNum = entries.getStr("tjNum"); tjReportController.preview(response,true,tjNum); } /** * 提供给三方调用的报告数据接口 * @param json * @return */ @PostMapping("/reportData") public AjaxResult reportData(@RequestBody String json){ String tjNum = JSONUtil.parseObj(json).getStr("tjNum"); JSONObject entries = JSONUtil.parseObj(tjCheckController.updateCheckType(tjNum)); removeNullFields(entries); return JSONUtil.toBean(entries, AjaxResult.class); } public static void removeNullFields(JSONObject jsonObject) { ArrayList strings = new ArrayList<>(); strings.add("orderId"); strings.add("updateTime"); strings.add("orderDetailId"); strings.add("flowingWaterId"); strings.add("createBy"); strings.add("deleted"); strings.add("createTime"); strings.add("updateBy"); strings.add("createId"); strings.add("prosId"); strings.add("params"); List keysToRemove = new ArrayList<>(); jsonObject.forEach((key, value) -> { if (strings.contains(key)) { keysToRemove.add(key); } else if (value == null) { keysToRemove.add(key); } else if (value instanceof JSONObject) { removeNullFields((JSONObject) value); } else if (value instanceof JSONArray) { JSONArray jsonArray = (JSONArray) value; for (Object arrayItem : jsonArray) { if (arrayItem instanceof JSONObject) { removeNullFields((JSONObject) arrayItem); } } } }); for (String key : keysToRemove) { jsonObject.remove(key); } } }