ScannerServiceEx.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //
  2. // Source code recreated from a .class file by IntelliJ IDEA
  3. // (powered by FernFlower decompiler)
  4. //
  5. package kd.imc.rim;
  6. import com.alibaba.fastjson.JSONObject;
  7. import java.util.Map;
  8. import kd.bos.context.RequestContext;
  9. import kd.bos.dataentity.resource.ResManager;
  10. import kd.bos.ext.form.control.CustomControl;
  11. import kd.bos.form.ConfirmCallBackListener;
  12. import kd.bos.form.ConfirmTypes;
  13. import kd.bos.form.MessageBoxOptions;
  14. import kd.bos.form.plugin.AbstractFormPlugin;
  15. import kd.bos.logging.Log;
  16. import kd.bos.logging.LogFactory;
  17. import kd.bos.threads.ThreadPool;
  18. import kd.bos.threads.ThreadPools;
  19. import kd.imc.rim.common.invoice.collector.ScannerService;
  20. import kd.imc.rim.common.utils.BigDecimalUtil;
  21. import kd.imc.rim.common.utils.FileUploadUtils;
  22. import kd.imc.rim.common.utils.ImcConfigUtil;
  23. import kd.imc.rim.common.utils.RimConfigUtils;
  24. import org.apache.commons.lang3.StringUtils;
  25. public class ScannerServiceEx {
  26. private static final int threadNum = 5;
  27. private static ThreadPool checkThreadPool = ThreadPools.newFixedThreadPool("scanner_check_pool_Ex", 5);
  28. private static final Log LOGGER = LogFactory.getLog(ScannerService.class);
  29. public static final String operate_invoice = "invoice";
  30. public static final String operate_attach = "attach";
  31. public ScannerServiceEx() {
  32. }
  33. public static void startWebScoket(CustomControl control, String linkKey) {
  34. RequestContext request = RequestContext.get();
  35. String socketUrl = request.getClientFullContextPath() + "msgwatch/?identifytype=" + linkKey + "&tenantsessionkey=KERPSESSIONID" + request.getTenantId();
  36. if (socketUrl.startsWith("https")) {
  37. socketUrl = "wss" + socketUrl.substring(5);
  38. } else if (socketUrl.startsWith("http")) {
  39. socketUrl = "ws" + socketUrl.substring(4);
  40. }
  41. JSONObject map = new JSONObject();
  42. map.put("operate", "open");
  43. map.put("qrcodeType", "cloudhub");
  44. map.put("socketUrl", socketUrl);
  45. map.put("linkKey", linkKey);
  46. map.put("enableWebSocket", "1");
  47. if ("0".equals(RimConfigUtils.getConfig("rim_fpzs", "enablesocket"))) {
  48. map.put("enableWebSocket", "0");
  49. }
  50. map.put("time", System.currentTimeMillis());
  51. LOGGER.info("startWebScoket:" + JSONObject.toJSONString(map));
  52. control.setData(map);
  53. }
  54. public static void startInterval(CustomControl control) {
  55. JSONObject json = new JSONObject();
  56. json.put("time", 1000);
  57. json.put("millisec", 1000);
  58. json.put("request", System.currentTimeMillis());
  59. control.setData(json);
  60. }
  61. public static void removeUpload(CustomControl control) {
  62. JSONObject map1 = new JSONObject();
  63. map1.put("operate", "remove");
  64. map1.put("fid", control.getView().getEntityId());
  65. control.setData(map1);
  66. }
  67. public static void initUpload(CustomControl control, boolean canImportExcels, String title) {
  68. JSONObject map1 = new JSONObject();
  69. RequestContext request = RequestContext.get();
  70. map1.put("operate", "init");
  71. map1.put("pageId", control.getView().getPageId());
  72. map1.put("uploadUrl", request.getClientFullContextPath() + "attachment/upload.do");
  73. map1.put("title", title);
  74. Map<String, String> rimFpzsConfig = ImcConfigUtil.getValue("rim_fpzs");
  75. int maxfilesize = BigDecimalUtil.transDecimal(rimFpzsConfig.get("maxfilesize")).intValue();
  76. if (maxfilesize < 1) {
  77. maxfilesize = 10;
  78. }
  79. map1.put("maxFileSize", maxfilesize);
  80. setImageCompress(map1, rimFpzsConfig);
  81. map1.put("fid", control.getView().getEntityId());
  82. map1.put("loadMsg", ResManager.loadKDString("上传中..", "ScannerService_0", "imc-rim-common", new Object[0]));
  83. map1.put("canImportExcels", canImportExcels);
  84. control.setData(map1);
  85. }
  86. public static void setImageCompress(Map<String, Object> map1, Map<String, String> rimFpzsConfig) {
  87. double fileLimitSize = 3.0;
  88. double fileQuality = 0.98;
  89. int fileLimitPixel = 1500;
  90. if (rimFpzsConfig != null && StringUtils.isNotEmpty((CharSequence)rimFpzsConfig.get("imageCompress"))) {
  91. String imageCompress = (String)rimFpzsConfig.get("imageCompress");
  92. String[] str = imageCompress.split(",");
  93. double limitSize;
  94. if (str.length > 0) {
  95. limitSize = BigDecimalUtil.transDecimal(str[0]).doubleValue();
  96. if (limitSize > 0.0 && limitSize <= 8.0) {
  97. fileLimitSize = limitSize;
  98. }
  99. }
  100. if (str.length > 1) {
  101. limitSize = BigDecimalUtil.transDecimal(str[1]).doubleValue();
  102. if (limitSize > 0.0) {
  103. fileQuality = limitSize;
  104. }
  105. }
  106. if (str.length > 2) {
  107. limitSize = BigDecimalUtil.transDecimal(str[2]).intValue();
  108. if (limitSize > 0) {
  109. fileLimitPixel = (int) limitSize;
  110. }
  111. }
  112. }
  113. map1.put("fileLimitSize", fileLimitSize);
  114. map1.put("fileQuality", fileQuality);
  115. map1.put("fileLimitPixel", fileLimitPixel);
  116. }
  117. public static void upload(CustomControl control) {
  118. JSONObject map1 = new JSONObject();
  119. map1.put("operate", "upload");
  120. map1.put("time", System.currentTimeMillis());
  121. control.setData(map1);
  122. }
  123. public static void init(CustomControl control, String pageId) {
  124. RequestContext request = RequestContext.get();
  125. JSONObject map1 = new JSONObject();
  126. map1.put("pageId", pageId);
  127. map1.put("init", "init");
  128. map1.put("savePath", FileUploadUtils.getInvoiceDir("invoice") + pageId + "");
  129. map1.put("uploadUrl", request.getClientFullContextPath() + "attachment/upload.do");
  130. map1.put("time", System.currentTimeMillis());
  131. map1.put("fid", control.getView().getEntityId());
  132. setScannerParam(map1);
  133. map1.put("downloadUrl", getJsScanner());
  134. control.setData(map1);
  135. }
  136. public static void scanner(CustomControl control, String pageId, String operate) {
  137. RequestContext request = RequestContext.get();
  138. JSONObject map1 = new JSONObject();
  139. map1.put("pageId", pageId);
  140. map1.put("operate", operate);
  141. map1.put("savePath", FileUploadUtils.getInvoiceDir("invoice") + pageId + "");
  142. String contextPath = request.getClientFullContextPath();
  143. if (contextPath.endsWith("/")) {
  144. contextPath = contextPath.substring(0, contextPath.length() - 1);
  145. }
  146. map1.put("contextPath", contextPath);
  147. map1.put("uploadUrl", contextPath + "/attachment/upload.do");
  148. map1.put("time", System.currentTimeMillis());
  149. map1.put("fid", control.getView().getEntityId());
  150. setScannerParam(map1);
  151. map1.put("downloadUrl", getJsScanner());
  152. control.setData(map1);
  153. }
  154. private static void setScannerParam(JSONObject param) {
  155. Map<String, String> map = ImcConfigUtil.getValue("rim_fpzs");
  156. String resolution = null;
  157. String scannerType = null;
  158. String limitpixel = null;
  159. if (map != null) {
  160. resolution = StringUtils.trimToEmpty((String)map.get("resolution"));
  161. scannerType = StringUtils.trimToEmpty((String)map.get("scanner_type"));
  162. limitpixel = StringUtils.trimToEmpty((String)map.get("limitpixel"));
  163. }
  164. if (StringUtils.isEmpty(scannerType)) {
  165. scannerType = "rq";
  166. }
  167. if (map != null && "dm".equals(scannerType)) {
  168. param.put("productKey", map.get("productkey"));
  169. }
  170. if (StringUtils.isEmpty(resolution)) {
  171. resolution = "100";
  172. }
  173. if (StringUtils.isEmpty(limitpixel)) {
  174. limitpixel = "2000";
  175. }
  176. param.put("scannerType", scannerType);
  177. param.put("resolution", resolution);
  178. param.put("fileLimitPixel", limitpixel);
  179. param.put("loadMsg", ResManager.loadKDString("扫描上传中..", "ScannerService_1", "imc-rim-common", new Object[0]));
  180. }
  181. public static boolean scannerFail(AbstractFormPlugin plugin, String eventArgs) {
  182. if (eventArgs != null) {
  183. if (eventArgs.indexOf("JsScanner.msi") > 0) {
  184. plugin.getView().showConfirm(ResManager.loadKDString("扫描仪需要安装JsScanner,是否安装?", "ScannerService_2", "imc-rim-common", new Object[0]), MessageBoxOptions.YesNo, ConfirmTypes.Default, new ConfirmCallBackListener("downJsScanner", plugin));
  185. return false;
  186. }
  187. if (eventArgs.indexOf("websocket connect error") > 0) {
  188. plugin.getView().showTipNotification(ResManager.loadKDString("请确认已经连接并打开扫描仪!", "ScannerService_3", "imc-rim-common", new Object[0]), 3000);
  189. return false;
  190. }
  191. if (eventArgs.indexOf("No data source found in this environment") > 0) {
  192. plugin.getView().showTipNotification(ResManager.loadKDString("请检查是否正确安装扫描仪驱动!", "ScannerService_4", "imc-rim-common", new Object[0]), 3000);
  193. return false;
  194. }
  195. JSONObject js = JSONObject.parseObject(eventArgs);
  196. if (js != null) {
  197. String description = js.getString("description");
  198. if (!StringUtils.isEmpty(description)) {
  199. plugin.getView().showTipNotification(description, 3000);
  200. return true;
  201. }
  202. }
  203. }
  204. plugin.getView().showErrorNotification(eventArgs);
  205. return false;
  206. }
  207. public static boolean uploadFinish(String eventArgs) {
  208. return eventArgs != null && (eventArgs.indexOf("cancelSelectSource") > 0 || eventArgs.indexOf("confirmDownload") > 0 || eventArgs.indexOf("cancelDownload") > 0);
  209. }
  210. public static String getJsScanner() {
  211. RequestContext request = RequestContext.get();
  212. return request.getClientFullContextPath() + "kingdee/imc/scanner/rq-scanner/lib/JsScanner.msi";
  213. }
  214. public static void downJsScanner(AbstractFormPlugin plugin) {
  215. RequestContext request = RequestContext.get();
  216. plugin.getView().openUrl(request.getClientFullContextPath() + "kingdee/imc/scanner/rq-scanner/lib/JsScanner.msi");
  217. }
  218. public static void recognitionInvoice(String source, String pageId, String url, String fileName, JSONObject businessParam, Map<String, Object> customParam) {
  219. LOGGER.info("Scanner recognitionInvoice...");
  220. RecognitionCheckTaskEx task = new RecognitionCheckTaskEx(RequestContext.get(), source, pageId, businessParam, customParam, url, fileName);
  221. checkThreadPool.submit(task);
  222. }
  223. public static Long getUploadIndex(JSONObject uploadResult) {
  224. Long index = BigDecimalUtil.transDecimal(uploadResult.get("index")).longValue();
  225. Long timeStamp = uploadResult.getLong("uploadTimeStamp");
  226. if (timeStamp == null) {
  227. timeStamp = System.currentTimeMillis();
  228. }
  229. return timeStamp + index;
  230. }
  231. }