|
|
@@ -1,19 +1,26 @@
|
|
|
package nckd.fi.er.message;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.grapecity.documents.excel.S;
|
|
|
+import kd.bos.context.RequestContext;
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
import kd.bos.exception.KDBizException;
|
|
|
import kd.bos.logging.Log;
|
|
|
import kd.bos.logging.LogFactory;
|
|
|
import kd.bos.orm.query.QCP;
|
|
|
import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
import kd.bos.servicehelper.QueryServiceHelper;
|
|
|
import kd.bos.servicehelper.parameter.SystemParamServiceHelper;
|
|
|
import kd.bos.workflow.engine.msg.AbstractMessageServiceHandler;
|
|
|
import kd.bos.workflow.engine.msg.ctx.MessageContext;
|
|
|
import kd.bos.workflow.engine.msg.info.MessageInfo;
|
|
|
import kd.bos.workflow.engine.msg.info.ToDoInfo;
|
|
|
+import nckd.base.common.utils.DateUtil;
|
|
|
import nckd.base.common.utils.HttpUtils;
|
|
|
+import nckd.base.common.utils.ParamUtils;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
@@ -41,22 +48,38 @@ public class SendMsgToWeChatOA extends AbstractMessageServiceHandler {
|
|
|
@Override
|
|
|
public void sendMessage(MessageContext ctx, MessageInfo message) {
|
|
|
super.sendMessage(ctx, message);
|
|
|
+ log.info("-----------------------------------------"+"微信公众号发送提醒信息:" +message.getMessageContent().getLocaleValue_zh_CN()+" begin--------------------------------------------------");
|
|
|
+ //微信公众号消息推送地址
|
|
|
String mobUrl = message.getMobContentUrl();
|
|
|
+ //微信公众号消息推送地址
|
|
|
String contentUrl = message.getContentUrl();
|
|
|
+ //表单数据id
|
|
|
+ Long bizDataId = message.getBizDataId();
|
|
|
+ if(bizDataId == null){
|
|
|
+ log.info("表单数据id为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //表单标识
|
|
|
+ String entityNumber = message.getEntityNumber();
|
|
|
+ if(StringUtils.isEmpty(entityNumber)){
|
|
|
+ log.info("表单标识为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
Long id = message.getId();
|
|
|
- //消息标题
|
|
|
- String title = message.getMessageTitle().getLocaleValue_zh_CN();
|
|
|
- //消息内容
|
|
|
- String content = message.getMessageContent().getLocaleValue_zh_CN();
|
|
|
-// Map<String, Object> publicParamWhole = SystemParamServiceHelper.loadPublicParametersFromCache();
|
|
|
- //微信获取token地址 设置为系统参数
|
|
|
- String url = "https://api.weixin.qq.com/cgi-bin/stable_token?";
|
|
|
- //公众号appid 设置为系统参数
|
|
|
- String appid = "wx75dd6e337f49f16c";
|
|
|
- //公众号密码 设置为系统参数
|
|
|
- String appsecret = "582ec148de67eebb9d41da86a6a03844";
|
|
|
- //公众号模板消息 模板id 设置为系统参数
|
|
|
- String templateid = "-MwmQae_NQ31EAmuYHC3n-aKMk9Qo6I1B1Kd1dSCqho";
|
|
|
+
|
|
|
+ //从系统参数中获取以下参数值
|
|
|
+ Map<String, Object> sysCtrlParamMap = sysCtrlParam();
|
|
|
+ //微信获取token地址
|
|
|
+ String url = (String) sysCtrlParamMap.get("nckd_tokenurl");
|
|
|
+ //公众号appid
|
|
|
+ String appid = (String) sysCtrlParamMap.get("nckd_appid");
|
|
|
+ //公众号密码
|
|
|
+ String appsecret = (String) sysCtrlParamMap.get("nckd_appsecret");
|
|
|
+ //公众号模板消息 模板id
|
|
|
+ String templateid = (String) sysCtrlParamMap.get("nckd_textfield");
|
|
|
+
|
|
|
String accessToken = "";
|
|
|
//请求token接口参数
|
|
|
Map<String,Object> data = new HashMap<>();
|
|
|
@@ -81,6 +104,7 @@ public class SendMsgToWeChatOA extends AbstractMessageServiceHandler {
|
|
|
//当前消息发送人用户id
|
|
|
List<Long> userIds = message.getUserIds();
|
|
|
List<Long> errUserIds = new ArrayList<Long>();
|
|
|
+
|
|
|
if(!StringUtils.isEmpty(accessToken)){
|
|
|
//微信公众号模板消息接口url 配置成参数
|
|
|
url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
|
|
|
@@ -88,26 +112,17 @@ public class SendMsgToWeChatOA extends AbstractMessageServiceHandler {
|
|
|
//模板消息接口请求参数
|
|
|
Map<String,Object> requestJson = new HashMap<>();
|
|
|
requestJson.put("template_id",templateid);
|
|
|
- requestJson.put("url",mobUrl);
|
|
|
+ //采购订单 跳转路径
|
|
|
+// String testUrl = "http://erp-test.jxctly.com/ierp/mobile.html?form=mobsp_purorderview&accountId="+ RequestContext.get().getAccountId()+"&pkId="+message.getBizDataId();
|
|
|
+ //对账单 跳转路径
|
|
|
+ String testUrl = "http://erp-test.jxctly.com/ierp/mobile.html?form=mobsp_checkaccountview&accountId="+ RequestContext.get().getAccountId()+"&pkId="+message.getBizDataId();
|
|
|
+// String testUrl = "http://erp-test.jxctly.com/ierp/mobile.html?form=mobsp_checkaccountlist&accountId="+ RequestContext.get().getAccountId()+"&pkId="+message.getBizDataId();
|
|
|
+ requestJson.put("url",testUrl);
|
|
|
requestJson.put("client_msg_id",id);
|
|
|
- // 修改成实际得审批消息数据
|
|
|
- String dataStr = "{\n" +
|
|
|
- " \"first\": {\n" +
|
|
|
- " \"value\":\"恭喜你审批通过\"\n" +
|
|
|
- " },\n" +
|
|
|
- " \"keyword1\":{\n" +
|
|
|
- " \"value\":\"丁思喜\"\n" +
|
|
|
- " },\n" +
|
|
|
- " \"keyword2\": {\n" +
|
|
|
- " \"value\":\"审批通过\"\n" +
|
|
|
- " },\n" +
|
|
|
- " \"keyword3\": {\n" +
|
|
|
- " \"value\":\"20251227\"\n" +
|
|
|
- " },\n" +
|
|
|
- " \"remark\":{\n" +
|
|
|
- " \"value\":\"消息测试\"\n" +
|
|
|
- " }\n" +
|
|
|
- " }\n";
|
|
|
+ //组装data参数
|
|
|
+ JSONObject dataJson = madeJsonObject(entityNumber,bizDataId);
|
|
|
+ // 转换为字符串
|
|
|
+ String dataStr = dataJson.toJSONString();
|
|
|
Map map = JSONObject.parseObject(dataStr, Map.class);
|
|
|
requestJson.put("data",map);
|
|
|
//获取当前用户id对应得微信公众号openid,每个用户都需要发送
|
|
|
@@ -125,7 +140,7 @@ public class SendMsgToWeChatOA extends AbstractMessageServiceHandler {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
log.info("公众号:"+response);
|
|
|
- if(!StringUtils.isEmpty(response)){
|
|
|
+ if(StringUtils.isEmpty(response)){
|
|
|
errUserIds.add(userId);
|
|
|
}else{
|
|
|
JSONObject json = JSONObject.parseObject(response);
|
|
|
@@ -146,6 +161,54 @@ public class SendMsgToWeChatOA extends AbstractMessageServiceHandler {
|
|
|
|
|
|
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 组装Json
|
|
|
+ * @param entityNumber
|
|
|
+ * @param bizDataId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ private JSONObject madeJsonObject(String entityNumber,Long bizDataId) {
|
|
|
+ //获取表单名称 、 单据编号
|
|
|
+ Map<String, String> queryEntityMap = queryEntityObject(entityNumber,bizDataId);
|
|
|
+ // 动态构建 JSON 对象
|
|
|
+ JSONObject dataJson = new JSONObject();
|
|
|
+
|
|
|
+ // first 部分
|
|
|
+ JSONObject firstObj = new JSONObject();
|
|
|
+ firstObj.put("value", "【您有新的任务通知】 您有新的待办消息任务,请及时反馈执行进度");
|
|
|
+
|
|
|
+ // msgType 部分
|
|
|
+ JSONObject msgTypeObj = new JSONObject();
|
|
|
+ msgTypeObj.put("value", queryEntityMap.get("entityName"));
|
|
|
+
|
|
|
+ // orderNumber 部分
|
|
|
+ JSONObject orderNumberObj = new JSONObject();
|
|
|
+ orderNumberObj.put("value", queryEntityMap.get("billno"));
|
|
|
+ // 组装完整 JSON
|
|
|
+ dataJson.put("first", firstObj);
|
|
|
+ dataJson.put("msgType", msgTypeObj);
|
|
|
+ dataJson.put("orderNumber", orderNumberObj);
|
|
|
+ return dataJson;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> queryEntityObject(String entityNumber, Long bizDataId) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ //查询主实体对象 获取表单名称
|
|
|
+ DynamicObject entityobject = BusinessDataServiceHelper.loadSingle("bos_entityobject","name",new QFilter[]{
|
|
|
+ new QFilter("number", QCP.equals, entityNumber)});
|
|
|
+ String entityName = entityobject.getString("name");
|
|
|
+ map.put("entityName",entityName);
|
|
|
+ //查询表单
|
|
|
+ DynamicObject hotelcheckingbill = BusinessDataServiceHelper.loadSingle(entityNumber,"billno",new QFilter[]{
|
|
|
+ new QFilter("id", QCP.equals, String.valueOf(bizDataId))
|
|
|
+ });
|
|
|
+ //单据编码
|
|
|
+ String billno = hotelcheckingbill.getString("billno");
|
|
|
+ map.put("billno",billno);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
//根据用户id获取微信openid
|
|
|
private String getUserOpenId(Long userId) {
|
|
|
String openid = "";
|
|
|
@@ -158,4 +221,19 @@ public class SendMsgToWeChatOA extends AbstractMessageServiceHandler {
|
|
|
}
|
|
|
return openid;
|
|
|
}
|
|
|
+
|
|
|
+ //获取公共参数
|
|
|
+ private Map<String, Object> sysCtrlParam() {
|
|
|
+ //获取采购应用参数
|
|
|
+ Map<String, Object> sysCtrlParamMap = ParamUtils.getSysCtrlParameter(ParamUtils.PM);
|
|
|
+ //微信获取token地址
|
|
|
+ sysCtrlParamMap.get("nckd_tokenurl");
|
|
|
+ //公众号appid
|
|
|
+ sysCtrlParamMap.get("nckd_appid");
|
|
|
+ //公众号密码
|
|
|
+ sysCtrlParamMap.get("nckd_appsecret");
|
|
|
+ //公众号模板消息 模板id
|
|
|
+ sysCtrlParamMap.get("nckd_textfield");
|
|
|
+ return sysCtrlParamMap;
|
|
|
+ }
|
|
|
}
|