|
@@ -0,0 +1,84 @@
|
|
|
+package nckd.jimin.jyyy.fi.plugin.form;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import kd.bos.dataentity.utils.StringUtils;
|
|
|
+import kd.bos.form.control.events.ItemClickEvent;
|
|
|
+import kd.bos.form.plugin.AbstractFormPlugin;
|
|
|
+import kd.bos.logging.Log;
|
|
|
+import kd.bos.logging.LogFactory;
|
|
|
+import kd.imc.bds.common.utils.UrlServiceUtils;
|
|
|
+import kd.imc.bds.common.utils.ViewUtil;
|
|
|
+import kd.sdk.plugin.Plugin;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 动态表单插件
|
|
|
+ */
|
|
|
+public class ViewImageByDownloadFilePlugin extends AbstractFormPlugin implements Plugin {
|
|
|
+
|
|
|
+ private static Log logger = LogFactory.getLog(ViewImageByDownloadFilePlugin.class);
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void itemClick(ItemClickEvent evt) {
|
|
|
+ String itemKey = evt.getItemKey();
|
|
|
+ if (StringUtils.equals(itemKey, "down_test")) {
|
|
|
+ this.downOneFile();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void downOneFile() {
|
|
|
+ JSONObject selectImage = this.getSelectImage();
|
|
|
+ if (selectImage != null) {
|
|
|
+ String viewFileIndexList = selectImage.getString("viewFileIndexList");
|
|
|
+ JSONArray imageArr = selectImage.getJSONArray("imageArr");
|
|
|
+
|
|
|
+ for(int i = 0; i < imageArr.size(); ++i) {
|
|
|
+ JSONObject imageJson = imageArr.getJSONObject(i);
|
|
|
+ if (StringUtils.contains(viewFileIndexList, imageJson.getString("view_file_index"))) {
|
|
|
+ String fileUrl = imageJson.getString("downloadUrl");
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(fileUrl)) {
|
|
|
+ fileUrl = imageJson.getString("localUrl");
|
|
|
+ }
|
|
|
+ logger.info("ViewImages fileUrl: " + fileUrl);
|
|
|
+ String uuu = UrlServiceUtils.getDownloadUrl(fileUrl);
|
|
|
+ logger.info("ViewImages downFileURL: " + uuu);
|
|
|
+ this.getView().openUrl(uuu);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.getView().showTipNotification("下载失败,未查询到当前影像文件");
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject getSelectImage() {
|
|
|
+ String selectImage = this.getPageCache().get("VIEW_IMAGE_LIST_SELECT");
|
|
|
+ logger.info("ViewImages selectImage: " + selectImage);
|
|
|
+ if (StringUtils.isEmpty(selectImage)) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ String[] selectIndex = selectImage.split(",");
|
|
|
+ String perfix = selectIndex[0];
|
|
|
+ String index = selectIndex[1];
|
|
|
+ String viewFileIndex = selectIndex[2];
|
|
|
+ String viewFileIndexList = selectImage.substring(perfix.length() + index.length() + 1);
|
|
|
+ String imageStr = this.getView().getPageCache().get("VIEW_IMAGE_LIST_KEY_" + index);
|
|
|
+ logger.info("ViewImages imageStr: " + imageStr);
|
|
|
+ JSONObject billJson = JSONObject.parseObject(imageStr);
|
|
|
+ if (billJson == null) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ billJson.put("viewFileIndex", viewFileIndex);
|
|
|
+ billJson.put("viewFileIndexList", viewFileIndexList);
|
|
|
+ logger.info("ViewImages getSelectImage: " + billJson);
|
|
|
+ return billJson;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|