You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.5 KiB
65 lines
2.5 KiB
package com.tptj.demo.hg.attachment.downloader; |
|
|
|
import com.fr.cache.Attachment; |
|
import com.fr.cache.AttachmentFileBase; |
|
import com.fr.cache.AttachmentSource; |
|
import com.fr.decision.webservice.v10.login.LoginService; |
|
import com.fr.general.web.ParameterConstants; |
|
import com.fr.intelli.record.Focus; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.record.analyzer.EnableMetrics; |
|
import com.fr.stable.bridge.ObjectHolder; |
|
import com.fr.stable.fun.assist.Selector; |
|
import com.fr.stable.fun.impl.AbstractAttachmentDownloader; |
|
import com.fr.web.fun.DefaultAttachmentDownloader; |
|
import com.fr.web.utils.WebUtils; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
/** |
|
* @author 秃破天际 |
|
* @version 10.0 |
|
* Created by 秃破天际 on 2021/6/22 |
|
**/ |
|
@EnableMetrics |
|
public class Demo extends AbstractAttachmentDownloader { |
|
|
|
public Selector selector() { |
|
return new Selector() { |
|
@Override |
|
public boolean accept( ObjectHolder holder ) { |
|
HttpServletRequest req = holder.get(HttpServletRequest.class); |
|
String id = WebUtils.getHTTPRequestParameter(req, "id"); |
|
String[] id_array = id.split("\\."); |
|
return true; |
|
} |
|
}; |
|
} |
|
@Override |
|
@Focus(id="com.tptj.demo.hg.attachment.downloader.v10",text = "AttachmentDownloader") |
|
public void download(HttpServletRequest req, HttpServletResponse res, String id, String[] idArray) throws Exception { |
|
if(idArray.length != 1){ |
|
DefaultAttachmentDownloader.getInstance().download(req,res,id,idArray); |
|
return; |
|
} |
|
//删除原来的附件 |
|
AttachmentSource.removeAttachment(id); |
|
//创建一个新的附件 |
|
AttachmentFileBase file = new AttachmentFileBase("D:/test", "Hello.txt"); |
|
Attachment attachment = new Attachment( id, ParameterConstants.FILE, "Hello.txt",file); |
|
//把附件设置到缓存中 |
|
AttachmentSource.putAttachment(id,attachment); |
|
//重新输出附件 |
|
DefaultAttachmentDownloader.getInstance().download(req,res,id,idArray); |
|
//打印日志 |
|
String username = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req); |
|
//Attachment attachment = AttachmentSource.getAttachment(id); |
|
FineLoggerFactory.getLogger().info("User[{}] Loaded Attachment[{}]", username , attachment.getFilename() ); |
|
} |
|
|
|
@Override |
|
public String createDownloadScript(String downloadURL) { |
|
return "window.open('" + downloadURL + "')"; |
|
} |
|
}
|
|
|