123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- //
- // Source code recreated from a .class file by IntelliJ IDEA
- // (powered by FernFlower decompiler)
- //
- package kd.imc.rim;
- import com.alibaba.fastjson.JSONObject;
- import java.util.Map;
- import kd.bos.context.RequestContext;
- import kd.bos.dataentity.resource.ResManager;
- import kd.bos.ext.form.control.CustomControl;
- import kd.bos.form.ConfirmCallBackListener;
- import kd.bos.form.ConfirmTypes;
- import kd.bos.form.MessageBoxOptions;
- import kd.bos.form.plugin.AbstractFormPlugin;
- import kd.bos.logging.Log;
- import kd.bos.logging.LogFactory;
- import kd.bos.threads.ThreadPool;
- import kd.bos.threads.ThreadPools;
- import kd.imc.rim.common.invoice.collector.ScannerService;
- import kd.imc.rim.common.utils.BigDecimalUtil;
- import kd.imc.rim.common.utils.FileUploadUtils;
- import kd.imc.rim.common.utils.ImcConfigUtil;
- import kd.imc.rim.common.utils.RimConfigUtils;
- import org.apache.commons.lang3.StringUtils;
- public class ScannerServiceEx {
- private static final int threadNum = 5;
- private static ThreadPool checkThreadPool = ThreadPools.newFixedThreadPool("scanner_check_pool_Ex", 5);
- private static final Log LOGGER = LogFactory.getLog(ScannerService.class);
- public static final String operate_invoice = "invoice";
- public static final String operate_attach = "attach";
- public ScannerServiceEx() {
- }
- public static void startWebScoket(CustomControl control, String linkKey) {
- RequestContext request = RequestContext.get();
- String socketUrl = request.getClientFullContextPath() + "msgwatch/?identifytype=" + linkKey + "&tenantsessionkey=KERPSESSIONID" + request.getTenantId();
- if (socketUrl.startsWith("https")) {
- socketUrl = "wss" + socketUrl.substring(5);
- } else if (socketUrl.startsWith("http")) {
- socketUrl = "ws" + socketUrl.substring(4);
- }
- JSONObject map = new JSONObject();
- map.put("operate", "open");
- map.put("qrcodeType", "cloudhub");
- map.put("socketUrl", socketUrl);
- map.put("linkKey", linkKey);
- map.put("enableWebSocket", "1");
- if ("0".equals(RimConfigUtils.getConfig("rim_fpzs", "enablesocket"))) {
- map.put("enableWebSocket", "0");
- }
- map.put("time", System.currentTimeMillis());
- LOGGER.info("startWebScoket:" + JSONObject.toJSONString(map));
- control.setData(map);
- }
- public static void startInterval(CustomControl control) {
- JSONObject json = new JSONObject();
- json.put("time", 1000);
- json.put("millisec", 1000);
- json.put("request", System.currentTimeMillis());
- control.setData(json);
- }
- public static void removeUpload(CustomControl control) {
- JSONObject map1 = new JSONObject();
- map1.put("operate", "remove");
- map1.put("fid", control.getView().getEntityId());
- control.setData(map1);
- }
- public static void initUpload(CustomControl control, boolean canImportExcels, String title) {
- JSONObject map1 = new JSONObject();
- RequestContext request = RequestContext.get();
- map1.put("operate", "init");
- map1.put("pageId", control.getView().getPageId());
- map1.put("uploadUrl", request.getClientFullContextPath() + "attachment/upload.do");
- map1.put("title", title);
- Map<String, String> rimFpzsConfig = ImcConfigUtil.getValue("rim_fpzs");
- int maxfilesize = BigDecimalUtil.transDecimal(rimFpzsConfig.get("maxfilesize")).intValue();
- if (maxfilesize < 1) {
- maxfilesize = 10;
- }
- map1.put("maxFileSize", maxfilesize);
- setImageCompress(map1, rimFpzsConfig);
- map1.put("fid", control.getView().getEntityId());
- map1.put("loadMsg", ResManager.loadKDString("上传中..", "ScannerService_0", "imc-rim-common", new Object[0]));
- map1.put("canImportExcels", canImportExcels);
- control.setData(map1);
- }
- public static void setImageCompress(Map<String, Object> map1, Map<String, String> rimFpzsConfig) {
- double fileLimitSize = 3.0;
- double fileQuality = 0.98;
- int fileLimitPixel = 1500;
- if (rimFpzsConfig != null && StringUtils.isNotEmpty((CharSequence)rimFpzsConfig.get("imageCompress"))) {
- String imageCompress = (String)rimFpzsConfig.get("imageCompress");
- String[] str = imageCompress.split(",");
- double limitSize;
- if (str.length > 0) {
- limitSize = BigDecimalUtil.transDecimal(str[0]).doubleValue();
- if (limitSize > 0.0 && limitSize <= 8.0) {
- fileLimitSize = limitSize;
- }
- }
- if (str.length > 1) {
- limitSize = BigDecimalUtil.transDecimal(str[1]).doubleValue();
- if (limitSize > 0.0) {
- fileQuality = limitSize;
- }
- }
- if (str.length > 2) {
- limitSize = BigDecimalUtil.transDecimal(str[2]).intValue();
- if (limitSize > 0) {
- fileLimitPixel = (int) limitSize;
- }
- }
- }
- map1.put("fileLimitSize", fileLimitSize);
- map1.put("fileQuality", fileQuality);
- map1.put("fileLimitPixel", fileLimitPixel);
- }
- public static void upload(CustomControl control) {
- JSONObject map1 = new JSONObject();
- map1.put("operate", "upload");
- map1.put("time", System.currentTimeMillis());
- control.setData(map1);
- }
- public static void init(CustomControl control, String pageId) {
- RequestContext request = RequestContext.get();
- JSONObject map1 = new JSONObject();
- map1.put("pageId", pageId);
- map1.put("init", "init");
- map1.put("savePath", FileUploadUtils.getInvoiceDir("invoice") + pageId + "");
- map1.put("uploadUrl", request.getClientFullContextPath() + "attachment/upload.do");
- map1.put("time", System.currentTimeMillis());
- map1.put("fid", control.getView().getEntityId());
- setScannerParam(map1);
- map1.put("downloadUrl", getJsScanner());
- control.setData(map1);
- }
- public static void scanner(CustomControl control, String pageId, String operate) {
- RequestContext request = RequestContext.get();
- JSONObject map1 = new JSONObject();
- map1.put("pageId", pageId);
- map1.put("operate", operate);
- map1.put("savePath", FileUploadUtils.getInvoiceDir("invoice") + pageId + "");
- String contextPath = request.getClientFullContextPath();
- if (contextPath.endsWith("/")) {
- contextPath = contextPath.substring(0, contextPath.length() - 1);
- }
- map1.put("contextPath", contextPath);
- map1.put("uploadUrl", contextPath + "/attachment/upload.do");
- map1.put("time", System.currentTimeMillis());
- map1.put("fid", control.getView().getEntityId());
- setScannerParam(map1);
- map1.put("downloadUrl", getJsScanner());
- control.setData(map1);
- }
- private static void setScannerParam(JSONObject param) {
- Map<String, String> map = ImcConfigUtil.getValue("rim_fpzs");
- String resolution = null;
- String scannerType = null;
- String limitpixel = null;
- if (map != null) {
- resolution = StringUtils.trimToEmpty((String)map.get("resolution"));
- scannerType = StringUtils.trimToEmpty((String)map.get("scanner_type"));
- limitpixel = StringUtils.trimToEmpty((String)map.get("limitpixel"));
- }
- if (StringUtils.isEmpty(scannerType)) {
- scannerType = "rq";
- }
- if (map != null && "dm".equals(scannerType)) {
- param.put("productKey", map.get("productkey"));
- }
- if (StringUtils.isEmpty(resolution)) {
- resolution = "100";
- }
- if (StringUtils.isEmpty(limitpixel)) {
- limitpixel = "2000";
- }
- param.put("scannerType", scannerType);
- param.put("resolution", resolution);
- param.put("fileLimitPixel", limitpixel);
- param.put("loadMsg", ResManager.loadKDString("扫描上传中..", "ScannerService_1", "imc-rim-common", new Object[0]));
- }
- public static boolean scannerFail(AbstractFormPlugin plugin, String eventArgs) {
- if (eventArgs != null) {
- if (eventArgs.indexOf("JsScanner.msi") > 0) {
- plugin.getView().showConfirm(ResManager.loadKDString("扫描仪需要安装JsScanner,是否安装?", "ScannerService_2", "imc-rim-common", new Object[0]), MessageBoxOptions.YesNo, ConfirmTypes.Default, new ConfirmCallBackListener("downJsScanner", plugin));
- return false;
- }
- if (eventArgs.indexOf("websocket connect error") > 0) {
- plugin.getView().showTipNotification(ResManager.loadKDString("请确认已经连接并打开扫描仪!", "ScannerService_3", "imc-rim-common", new Object[0]), 3000);
- return false;
- }
- if (eventArgs.indexOf("No data source found in this environment") > 0) {
- plugin.getView().showTipNotification(ResManager.loadKDString("请检查是否正确安装扫描仪驱动!", "ScannerService_4", "imc-rim-common", new Object[0]), 3000);
- return false;
- }
- JSONObject js = JSONObject.parseObject(eventArgs);
- if (js != null) {
- String description = js.getString("description");
- if (!StringUtils.isEmpty(description)) {
- plugin.getView().showTipNotification(description, 3000);
- return true;
- }
- }
- }
- plugin.getView().showErrorNotification(eventArgs);
- return false;
- }
- public static boolean uploadFinish(String eventArgs) {
- return eventArgs != null && (eventArgs.indexOf("cancelSelectSource") > 0 || eventArgs.indexOf("confirmDownload") > 0 || eventArgs.indexOf("cancelDownload") > 0);
- }
- public static String getJsScanner() {
- RequestContext request = RequestContext.get();
- return request.getClientFullContextPath() + "kingdee/imc/scanner/rq-scanner/lib/JsScanner.msi";
- }
- public static void downJsScanner(AbstractFormPlugin plugin) {
- RequestContext request = RequestContext.get();
- plugin.getView().openUrl(request.getClientFullContextPath() + "kingdee/imc/scanner/rq-scanner/lib/JsScanner.msi");
- }
- public static void recognitionInvoice(String source, String pageId, String url, String fileName, JSONObject businessParam, Map<String, Object> customParam) {
- LOGGER.info("Scanner recognitionInvoice...");
- RecognitionCheckTaskEx task = new RecognitionCheckTaskEx(RequestContext.get(), source, pageId, businessParam, customParam, url, fileName);
- checkThreadPool.submit(task);
- }
- public static Long getUploadIndex(JSONObject uploadResult) {
- Long index = BigDecimalUtil.transDecimal(uploadResult.get("index")).longValue();
- Long timeStamp = uploadResult.getLong("uploadTimeStamp");
- if (timeStamp == null) {
- timeStamp = System.currentTimeMillis();
- }
- return timeStamp + index;
- }
- }
|