ソースを参照

消息发送携带路径地址

“luojun” 6 ヶ月 前
コミット
8aaa9cbb7e

+ 11 - 0
properties/gyt/sendMessage.properties

@@ -0,0 +1,11 @@
+appSecret=cl8/LJaX9IbzkTMbhaOUIg==
+appType=2
+appId=shr
+url=/spi/sendSms
+urlTask=/spi/sendSmsTask
+sendMessageUrl=https://msgdev.gooeto.com/api/spi/sendSms
+sendMessageTaskUrl=http://msgdev.gooeto.com/api/spi/sendSmsTask
+templateId=MSG_2024090901
+signName=湖南谷医堂
+name=测试
+shrPath=https://shr-test.gooeto.com:6888/

+ 122 - 0
websrc/com/kingdee/eas/custom/sendmessage/utils/SaveFileForDisk.java

@@ -0,0 +1,122 @@
+package com.kingdee.eas.custom.sendmessage.utils;
+
+import com.kingdee.bos.BOSException;
+import com.kingdee.bos.Context;
+import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
+import com.kingdee.eas.base.attachment.AttachmentFactory;
+import com.kingdee.eas.base.attachment.AttachmentInfo;
+import com.kingdee.eas.base.attachment.AttachmentManagerFacadeFactory;
+import com.kingdee.eas.base.attachment.IAttachmentManagerFacade;
+import com.kingdee.eas.common.EASBizException;
+import com.kingdee.eas.rpts.ctrlreport.osf.OSFExecutor;
+import com.kingdee.shr.certificationservice.HRCertificationBillInfo;
+import com.kingdee.util.StringUtils;
+
+import javax.servlet.ServletOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * 获取附件并保存到磁盘
+ */
+public class SaveFileForDisk {
+
+    private static String HOME_URL = "https://shr-test.gooeto.com:6888/";
+
+    /**
+     * 获取pdf对应的信息
+     * elecProofInfo 为证明单据
+     * @param ctx
+     * @param elecProofInfo
+     * @return
+     * @throws BOSException
+     * @throws EASBizException
+     * @throws IOException
+     */
+    public static Map<String,String>  getPDFInfo(Context ctx, HRCertificationBillInfo elecProofInfo ) throws BOSException, EASBizException, IOException {
+        Map<String,String> resultMap = new HashMap();
+        //获取证明号
+        String signNo = StringUtils.cnulls(elecProofInfo.getSignNO());
+        //签署完成后,调用osf服务,预览证明
+        String billId = StringUtils.cnulls(elecProofInfo.getId());
+        //调用osf服务
+        HashMap param = new HashMap<String,String>();
+        param.put("contractNo", signNo);
+        param.put("billId",  billId);
+        param.put("isDefault", "1");
+        Map<String, Object> result = (Map<String, Object>) OSFExecutor.executeOSF(ctx, param, "empPreViewECertificationV2Service");
+        boolean  isSucc = (Boolean)result.get("isSuccess");
+        String returnUrl = StringUtils.cnulls( result.get("returnUrl") );
+        //如果成功则把证件放入磁盘;
+        if(isSucc) {
+
+            String folderName =  createFolderName();
+            String fileName =  getPDFToDisk(ctx, returnUrl, folderName);
+            //发送消息
+            String urlPath  = HOME_URL+"?sole="+folderName+"&fname="+fileName;
+            //文件夹名
+            resultMap.put("dirName",folderName);
+            //文件名
+            resultMap.put("fileName",fileName);
+            //url路径
+            resultMap.put("urlPath",urlPath);
+        }
+        return resultMap;
+    }
+
+    public static  String  getPDFToDisk(Context ctx, String attachId, String dirName) throws IOException {
+
+        String home = System.getProperty("EAS_HOME"); // 获取 EAS 根目录
+        String fileDir = home+"/server/deploy/easweb.ear/shr_web.war/tmp/electronicAttachment/"+ dirName;
+        fileDir = fileDir.replace("\\", "/"); //
+        ServletOutputStream outputStream = null;
+        OutputStream fileOutputStream = null; // 创建文件输出流
+        try {
+            AttachmentInfo ai = AttachmentFactory.getLocalInstance(ctx).getAttachmentInfo(new ObjectUuidPK(attachId));
+            String fileName = ai.getName();
+            String simpleName = ai.getSimpleName();
+            IAttachmentManagerFacade iAttachmentManagerFacade = AttachmentManagerFacadeFactory.getLocalInstance(ctx);
+            byte[] content = iAttachmentManagerFacade.downLoad(attachId);
+
+            // 确保输出目录存在
+            File directory = new File(fileDir);
+            if (!directory.exists()) {
+                directory.mkdirs(); // 创建目录
+            }
+
+            // 指定文件的完整路径
+            File file = new File(directory, simpleName);
+            fileOutputStream = new FileOutputStream(file); // 创建文件输出流
+            fileOutputStream.write(content); // 将内容写入文件
+            fileOutputStream.flush();
+            return simpleName;
+
+        } catch (EASBizException | BOSException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (fileOutputStream != null) {
+                    fileOutputStream.close(); // 关闭文件输出流
+                }
+                if (outputStream != null) {
+                    outputStream.close(); // 关闭 Servlet 输出流
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return "";
+    }
+
+
+    public static String createFolderName () {
+        //使用uuid生成一个8位数的随机字符串作为文件夹名
+        return UUID.randomUUID().toString().replaceAll("-", "").substring(0, 8);
+    }
+
+}

+ 93 - 68
websrc/com/kingdee/eas/custom/sendmessage/utils/SendMessageUtil.java

@@ -87,77 +87,97 @@ public class SendMessageUtil {
             sic.add("certificationTemplet.name");
             sic.add("certificationTemplet.number");
             sic.add("certificationTemplet.id");
+            sic.add("certificationTemplet.certificationBillType.name");
+            sic.add("certificationTemplet.certificationBillType.number");
+            sic.add("certificationTemplet.certificationBillType.id");
             sic.add("certificationTemplet.templateId");
             FilterInfo filterInfo = new FilterInfo();
             filterInfo.getFilterItems().add(new FilterItemInfo("id", setBillId, CompareType.INCLUDE));
             EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
             HRCertificationBillCollection hrCertificationBillCollection = ihrCertificationBill.getHRCertificationBillCollection(entityViewInfo);
-            String md5Sign = null;
-            //过滤封装手机号
-            Map<String, Set> phoneMap = disposeCollFillterPhone(hrCertificationBillCollection);
-            //密钥
-            String appSecret = propt.getProperty("appSecret");
-            //uuid
-            String uuid = UUID.randomUUID().toString();
-            System.out.println("uuid---" + uuid);
-            //应用类型
-            String appType = propt.getProperty("appType");
-            //应用id
-            String appId = propt.getProperty("appId");
-            //url
-            String url = propt.getProperty("url");
-            String signName = propt.getProperty("signName");
-            logger.error("url---" + url);
-            for (String templateId : phoneMap.keySet()) {
-                Set<String> phoneSet = phoneMap.get(templateId);
-                for (String phone : phoneSet) {
-                    //时间戳
-                    Date date = new Date();
-                    String time = String.valueOf(date.getTime());
-                    messageLogsInfo.setTime(date);
-                    logger.error("time---" + time);
-                    //参数
-                    JSONObject params = new JSONObject();
-                    params.put("appId", appId);
-                    params.put("templateId", templateId);
-                    params.put("signName", signName);
-                    //批量发送才需要这个参数
-                    //params.put("phone", phone);
-                    params.put("phone", "15574198273");
-                    params.put("appId", appId);
-                    //消息模板
-                    JSONObject param = getTemplate(ctx, templateId, phone, messageLogsInfo);
-                    params.put("params", param);
-                    //请求参数
-                    JSONObject jsonObject = new JSONObject();
-                    //jsonObject.put("params", params.toString());
-                    jsonObject.put("time", time);
-                    jsonObject.put("uuid", uuid);
-                    jsonObject.put("phones", phone);
-                    md5Sign = md5Sign(appSecret, url, params, appType, time, uuid, jsonObject);
-                    jsonObject.put("md5Sign", md5Sign);
-                    messageLogsInfo.setRequestParams(jsonObject.toString());
-                    logger.error("md5Sign---" + md5Sign);
-                    logger.error("params---" + params);
-                    Response resultResponse = sendMeesage(params, appType, appId, uuid, md5Sign, time);
-                    String body = resultResponse.body().string();
-                    logger.error("body---" + body);
-                    JSONObject result = JSONObject.parseObject(body);
-                    String code = result.get("code").toString();
-                    if (!code.equals("200")) {
-                        error++;
-                        messageLogsInfo.setStatus(SendStatusEnum.fail);
-                    } else {
-                        seccuss++;
-                        messageLogsInfo.setStatus(SendStatusEnum.succeed);
-                    }
-                    //返回结果
-                    messageLogsInfo.setResult(body);
-                    messageLogsInfo.setSuccessNum(seccuss);
-                    messageLogsInfo.setFailNum(error);
-                    iMessageLogs.save(messageLogsInfo);
+            for (int i = 0; i < hrCertificationBillCollection.size(); i++) {
+                HRCertificationBillInfo hrCertificationBillInfo = hrCertificationBillCollection.get(i);
+                //手机号
+                String callPhone = hrCertificationBillInfo.getCallPhone();
+                //证明模板
+                CertificationTempletInfo certificationTemplet = hrCertificationBillInfo.getCertificationTemplet();
+                String templateName = certificationTemplet.getName();
+                String templateId = (String) certificationTemplet.get("templateId");
+                //证明模板
+                HRCertificationBillTypeInfo certificationBillType = certificationTemplet.getCertificationBillType();
+                //模版名称
+                messageLogsInfo.setReserved1(templateName);
+                messageLogsInfo.setReserved2(certificationBillType.getName());
+                if (StringUtils.isEmpty(templateId)) {
+                    throw new ShrWebBizException(templateName + "模板的消息id为空,请问维护!!");
                 }
+
+                String md5Sign = null;
+                //过滤封装手机号
+                //Map<String, Set> phoneMap = disposeCollFillterPhone(hrCertificationBillCollection, messageLogsInfo);
+                //密钥
+                String appSecret = propt.getProperty("appSecret");
+                //uuid
+                String uuid = UUID.randomUUID().toString();
+                System.out.println("uuid---" + uuid);
+                //应用类型
+                String appType = propt.getProperty("appType");
+                //应用id
+                String appId = propt.getProperty("appId");
+                //url
+                String url = propt.getProperty("url");
+                String signName = propt.getProperty("signName");
+                logger.error("url---" + url);
+                //时间戳
+                Date date = new Date();
+                String time = String.valueOf(date.getTime());
+                messageLogsInfo.setTime(date);
+                logger.error("time---" + time);
+                //参数
+                JSONObject params = new JSONObject();
+                params.put("appId", appId);
+                params.put("templateId", templateId);
+                params.put("signName", signName);
+                //批量发送才需要这个参数
+                //params.put("phone", phone);
+                params.put("phone", "15574198273");
+                params.put("appId", appId);
+                //消息模板
+                Map<String, String> resultMap = SaveFileForDisk.getPDFInfo(ctx, hrCertificationBillInfo);
+                JSONObject param = getTemplate(ctx, templateId, callPhone, resultMap.get("urlPath"), messageLogsInfo);
+                params.put("params", param);
+                //请求参数
+                JSONObject jsonObject = new JSONObject();
+                //jsonObject.put("params", params.toString());
+                jsonObject.put("time", time);
+                jsonObject.put("uuid", uuid);
+                jsonObject.put("phones", callPhone);
+                md5Sign = md5Sign(appSecret, url, params, appType, time, uuid, jsonObject);
+                jsonObject.put("md5Sign", md5Sign);
+                jsonObject.put("resultMap", resultMap);
+                messageLogsInfo.setRequestParams(resultMap.get("urlPath"));
+                messageLogsInfo.setRequestParams(jsonObject.toString());
+                logger.error("md5Sign---" + md5Sign);
+                logger.error("params---" + params);
+                Response resultResponse = sendMeesage(params, appType, appId, uuid, md5Sign, time);
+                String body = resultResponse.body().string();
+                logger.error("body---" + body);
+                JSONObject result = JSONObject.parseObject(body);
+                String code = result.get("code").toString();
+                if (!code.equals("200")) {
+                    error++;
+                    messageLogsInfo.setStatus(SendStatusEnum.fail);
+                } else {
+                    seccuss++;
+                    messageLogsInfo.setStatus(SendStatusEnum.succeed);
+                }
+                //返回结果
+                messageLogsInfo.setResult(body);
+                messageLogsInfo.setSuccessNum(seccuss);
+                messageLogsInfo.setFailNum(error);
+                iMessageLogs.save(messageLogsInfo);
             }
+
         } catch (Exception e) {
             error++;
             //返回结果
@@ -177,7 +197,7 @@ public class SendMessageUtil {
      * @param phone
      * @return
      */
-    public JSONObject getTemplate(Context ctx, String templateId, String phone, MessageLogsInfo messageLogsInfo) throws BOSException {
+    public JSONObject getTemplate(Context ctx, String templateId, String phone, String urlPath, MessageLogsInfo messageLogsInfo) throws BOSException {
         JSONObject param = new JSONObject();
         IPersonContactMethod iPersonContactMethod = PersonContactMethodFactory.getLocalInstance(ctx);
         PersonContactMethodInfo personContactMethodInfo = iPersonContactMethod
@@ -188,7 +208,7 @@ public class SendMessageUtil {
         //SHR发送电子证明
         if (templateId.equals("MSG_2411190001")) {
             param.put("name", person.getName());
-            param.put("urlPath", "下載地址");
+            param.put("urlPath", urlPath);
         }
         //SHR发送离职通知
         if (templateId.equals("MSG_2411200002")) {
@@ -199,7 +219,7 @@ public class SendMessageUtil {
             String lzDate = format.format(bizDate);
             param.put("name", person.getName());
             param.put("lzDate", lzDate);
-            param.put("urlPath", "下載地址");
+            param.put("urlPath", urlPath);
         }
         return param;
     }
@@ -211,7 +231,7 @@ public class SendMessageUtil {
      * @param hrCertificationBillCollection
      * @return
      */
-    public Map disposeCollFillterPhone(HRCertificationBillCollection hrCertificationBillCollection) throws ShrWebBizException {
+    public Map disposeCollFillterPhone(HRCertificationBillCollection hrCertificationBillCollection, MessageLogsInfo messageLogsInfo) throws ShrWebBizException {
         Map<String, Set> certificationBillTypeMap = new HashMap<>();
         for (int i = 0; i < hrCertificationBillCollection.size(); i++) {
             HRCertificationBillInfo hrCertificationBillInfo = hrCertificationBillCollection.get(i);
@@ -221,6 +241,11 @@ public class SendMessageUtil {
             CertificationTempletInfo certificationTemplet = hrCertificationBillInfo.getCertificationTemplet();
             String templateName = certificationTemplet.getName();
             String templateId = (String) certificationTemplet.get("templateId");
+            //证明模板
+            HRCertificationBillTypeInfo certificationBillType = certificationTemplet.getCertificationBillType();
+            //模版名称
+            messageLogsInfo.setReserved1(templateName);
+            messageLogsInfo.setReserved2(certificationBillType.getName());
             if (StringUtils.isEmpty(templateId)) {
                 throw new ShrWebBizException(templateName + "模板的消息id为空,请问维护!!");
             }