- 继承com.landray.kmss.sys.webservice2.interfaces.ISysWebservice,同时在接口上使用@WebService注解将其标识为WebService接口
package com.landray.kmss.third.notify.webservice;
import com.alibaba.fastjson.JSONObject;
import com.landray.kmss.sys.webservice2.interfaces.ISysWebservice;
import javax.jws.WebService;
@WebService
public interface IThirdNotifyWebService extends ISysWebservice {
JSONObject sendToNotifyInfo(JSONObject jsonObject) throws Exception;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
package com.landray.kmss.third.notify.webservice.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.landray.kmss.common.service.IBaseService;
import com.landray.kmss.constant.SysNotifyConstant;
import com.landray.kmss.hr.staff.model.HrStaffPersonInfo;
import com.landray.kmss.hr.staff.service.IHrStaffPersonInfoService;
import com.landray.kmss.sys.metadata.interfaces.ExtendDataServiceImp;
import com.landray.kmss.sys.notify.constant.SysNotifyConstants;
import com.landray.kmss.sys.notify.interfaces.ISysNotifyMainCoreService;
import com.landray.kmss.sys.notify.interfaces.NotifyContext;
import com.landray.kmss.third.notify.model.ThirdNotifyInfoDetails;
import com.landray.kmss.third.notify.service.IThirdNotifyInfoDetailsService;
import com.landray.kmss.third.notify.webservice.IThirdNotifyWebService;
import com.landray.kmss.web.annotation.RestApi;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static com.landray.kmss.third.notify.webservice.ThirdNotifyConstant.*;
import static com.landray.kmss.util.SpringBeanUtil.getBean;
@Controller
@RequestMapping(value = "/api/third-notify/thirdNotifyWebService", method = RequestMethod.POST)
@RestApi(docUrl = "/third/notify/webservice/third_notify_service_help.jsp", name = "thirdNotifyWebServiceImp", resourceKey = "third-notify:module.third.notify")
public class ThirdNotifyWebServiceImpl extends ExtendDataServiceImp implements IThirdNotifyWebService {
private IThirdNotifyInfoDetailsService thirdNotifyInfoDetailsService;
public IBaseService getServiceImp() {
if (thirdNotifyInfoDetailsService == null) {
thirdNotifyInfoDetailsService = (IThirdNotifyInfoDetailsService) getBean("thirdNotifyInfoDetailsService");
}
return thirdNotifyInfoDetailsService;
}
private ISysNotifyMainCoreService sysNotifyMainCoreService;
public ISysNotifyMainCoreService getSysNotifyMainCoreServiceImp() {
if (sysNotifyMainCoreService == null) {
sysNotifyMainCoreService = (ISysNotifyMainCoreService) getBean("sysNotifyMainCoreService");
}
return sysNotifyMainCoreService;
}
private IHrStaffPersonInfoService hrStaffPersonInfoService;
public IHrStaffPersonInfoService getHrStaffPersonInfoServiceImp() {
if (hrStaffPersonInfoService == null) {
hrStaffPersonInfoService = (IHrStaffPersonInfoService) getBean("hrStaffPersonInfoService");
}
return hrStaffPersonInfoService;
}
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@ResponseBody
@RequestMapping(value = "/sendToNotifyInfo", method = RequestMethod.POST)
public JSONObject sendToNotifyInfo(@RequestBody JSONObject jsonObject) throws Exception {
JSONObject resultJson = new JSONObject();
JSONArray resultJsonArr = new JSONArray();
boolean isError = false;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
if (jsonObject != null && !jsonObject.isEmpty() && jsonObject.size() != 0) {
if (jsonObject.containsKey("sendToNotifyInfo")) {
JSONArray jsonArray = jsonObject.getJSONArray("sendToNotifyInfo");
if (jsonArray.size() != 0 && !jsonArray.isEmpty()) {
ThirdNotifyInfoDetails thirdNotifyInfoDetails = new ThirdNotifyInfoDetails();
JSONObject jsonItem;
String notifySubject;
String notifyContent;
String notifySenderNo;
String notifyPush;
String notifyType;
String notifySendTime;
for (int i = 0; i < jsonArray.size(); i++) {
isError = false;
jsonItem = jsonArray.getJSONObject(i);
if (jsonItem != null && !jsonItem.isEmpty()) {
notifySubject = jsonItem.get("notifySubject").toString();
thirdNotifyInfoDetails.setNotifySubject(notifySubject);
notifyContent = jsonItem.get("notifyContent").toString();
thirdNotifyInfoDetails.setNotifyContent(notifyContent);
notifySenderNo = jsonItem.get("notifySenderNo").toString();
if ("".equals(notifySenderNo) || notifySenderNo == "") {
JSONObject resultNoJson = new JSONObject();
resultNoJson.put(RETURNSTATE, ERROR);
resultNoJson.put(RETURNMESSAGE, "[notifySenderNo]" + MESSAGENOTIFYSENDERNO);
resultJsonArr.add(resultNoJson);
isError = true;
} else {
thirdNotifyInfoDetails.setNotifySenderNo(notifySenderNo);
}
thirdNotifyInfoDetails.setNotifySenderName(jsonItem.get("notifySenderName").toString());
notifySendTime = jsonItem.get("notifySendTime").toString();
if (!"".equals(notifySendTime) && notifySendTime != "") {
try {
thirdNotifyInfoDetails.setNotifySendTime(dateFormat.parse(notifySendTime));
} catch (Exception e) {
JSONObject resultTimeJson = new JSONObject();
resultTimeJson.put(RETURNSTATE, ERROR);
resultTimeJson.put(RETURNMESSAGE, "编号:[" + notifySenderNo + "]" + MESSAGENOTIFYTIME);
resultJsonArr.add(resultTimeJson);
isError = true;
}
} else {
thirdNotifyInfoDetails.setNotifySendTime(null);
}
thirdNotifyInfoDetails.setNotifySource(jsonItem.get("notifySource").toString());
notifyPush = jsonItem.get("notifyPush").toString();
if (NOW.equals(notifyPush) || TIMED.equals(notifyPush)) {
thirdNotifyInfoDetails.setNotifyPush(notifyPush);
} else {
JSONObject resultPushJson = new JSONObject();
resultPushJson.put(RETURNSTATE, ERROR);
resultPushJson.put(RETURNMESSAGE, "编号:[" + notifySenderNo + "]" + MESSAGENOTIFYPUSH);
resultJsonArr.add(resultPushJson);
isError = true;
}
notifyType = jsonItem.get("notifyType").toString();
if (DINGTALK.equals(notifyType) || EMAIL.equals(notifyType)) {
thirdNotifyInfoDetails.setNotifyType(notifyType);
} else {
JSONObject resultTypeJson = new JSONObject();
resultTypeJson.put(RETURNSTATE, ERROR);
resultTypeJson.put(RETURNMESSAGE, "编号:[" + notifySenderNo + "]" + MESSAGENOTIFYTYPE);
resultJsonArr.add(resultTypeJson);
isError = true;
}
thirdNotifyInfoDetails.setNotifyRecipientNo(jsonItem.get("notifyRecipientNo").toString());
thirdNotifyInfoDetails.setNotifyRecipientName(jsonItem.get("notifyRecipientName").toString());
thirdNotifyInfoDetails.setNotifyCreateTime(new Date());
thirdNotifyInfoDetails.setNotifyUpdateTime(new Date());
if (NOW.equals(notifyPush) && DINGTALK.equals(notifyType) && !isError) {
try {
JSONObject sendResult = this.sendTodoFromResource(notifySenderNo, notifySubject, notifyContent);
if (SUCCES.equals(sendResult.getString(RETURNSTATE))) {
thirdNotifyInfoDetails.setNotifyIsFlag("1");
getServiceImp().add(thirdNotifyInfoDetails);
} else {
JSONObject getSendState = new JSONObject();
getSendState.put(RETURNSTATE, sendResult.getString(RETURNSTATE));
getSendState.put(RETURNMESSAGE, "编号:[" + notifySenderNo + "]" + sendResult.getString(RETURNMESSAGE));
resultJsonArr.add(getSendState);
isError = true;
}
} catch (Exception e) {
JSONObject errorJson = new JSONObject();
errorJson.put(RETURNSTATE, ERROR);
errorJson.put(RETURNMESSAGE, "编号:[" + notifySenderNo + "]" + MESSAGESEND2);
resultJsonArr.add(errorJson);
isError = true;
e.printStackTrace();
}
} else if (TIMED.equals(notifyPush) && !isError) {
thirdNotifyInfoDetails.setNotifyIsFlag("0");
getServiceImp().add(thirdNotifyInfoDetails);
}
}
}
} else {
resultJson.put(RETURNSTATE, ERROR);
resultJson.put(RETURNMESSAGE, MESSAGE4);
return resultJson;
}
} else {
resultJson.put(RETURNSTATE, ERROR);
resultJson.put(RETURNMESSAGE, MESSAGE3);
return resultJson;
}
} else {
resultJson.put(RETURNSTATE, ERROR);
resultJson.put(RETURNMESSAGE, MESSAGE2);
return resultJson;
}
} catch (Exception e) {
resultJson.put(RETURNSTATE, ERROR);
resultJson.put(RETURNMESSAGE, MESSAGE1);
e.printStackTrace();
return resultJson;
}
if (isError) {
resultJson.put(RETURNSTATE, ERROR);
resultJson.put(RETURNMESSAGE, resultJsonArr);
} else {
resultJson.put(RETURNSTATE, SUCCES);
resultJson.put(RETURNMESSAGE, MESSAGESUCCES);
}
return resultJson;
}
public JSONObject sendTodoFromResource(String notifySenderNo, String notifySubject, String notifyContent) {
JSONObject sendResultJson = new JSONObject();
sendResultJson.put(RETURNSTATE, SUCCES);
sendResultJson.put(RETURNMESSAGE, MESSAGESEND1);
try {
HrStaffPersonInfo senderInfo = getHrStaffPersonInfoServiceImp().findPersonInfoByStaffNo(notifySenderNo);
if (senderInfo == null) {
sendResultJson.put(RETURNSTATE, ERROR);
sendResultJson.put(RETURNMESSAGE, MESSAGESEND3);
return sendResultJson;
}
NotifyContext notifyContext = getSysNotifyMainCoreServiceImp()
.getContext(null);
notifyContext.setNotifyType("todo");
notifyContext.setFlag(SysNotifyConstant.NOTIFY_TODOTYPE_ONCE);
notifyContext.setKey("thirdNotifyInfo");
List targets = new ArrayList();
targets.add(senderInfo.getFdOrgPerson());
notifyContext.setNotifyTarget(targets);
notifyContext.setLink("");
notifyContext.setSubject(notifySubject);
notifyContext.setContent(notifyContent);
notifyContext.setParameter1(SysNotifyConstants.SUPPORT_MORETIMES_SEND_TODO);
getSysNotifyMainCoreServiceImp().sendNotify(senderInfo, notifyContext, null);
} catch (Exception e) {
e.printStackTrace();
sendResultJson.put(RETURNSTATE, ERROR);
sendResultJson.put(RETURNMESSAGE, MESSAGESEND2);
return sendResultJson;
}
return sendResultJson;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
<!--外部系统消息通知WebService服务接口-->
<bean id="thirdNotifyWebService" class="com.landray.kmss.third.notify.webservice.impl.ThirdNotifyWebServiceImpl"/>
- 在功能模块中添加WebService的扩展配置,实现Web服务的扩展点
<!--外部系统消息通知WebService服务接口-开始-->
<extension
point="com.landray.kmss.sys.webservice2">
<item
name="registry">
<param
name="serviceName"
value="外部系统消息通知"/>
<param
name="serviceClass"
value="com.landray.kmss.third.notify.webservice.IThirdNotifyWebService"/>
<param
name="serviceBean"
value="thirdNotifyWebService"/>
<param
name="serviceDoc"
value="/third/notify/webservice/third_notify_service_help.jsp"/>
</item>
</extension>
<!--外部系统消息通知WebService服务接口-结束-->
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 导入并发布服务
定时任务
package com.landray.kmss.third.notify.webservice;
import com.landray.kmss.common.service.IBaseService;
public interface IThirdNotifyJobWebService extends IBaseService {
void sendToNotifyInfoJob() throws Exception;
}
package com.landray.kmss.third.notify.webservice.impl;
import com.alibaba.fastjson.JSONObject;
import com.landray.kmss.common.service.BaseServiceImp;
import com.landray.kmss.common.service.IBaseService;
import com.landray.kmss.third.notify.model.ThirdNotifyInfoDetails;
import com.landray.kmss.third.notify.service.IThirdNotifyInfoDetailsService;
import com.landray.kmss.third.notify.webservice.IThirdNotifyJobWebService;
import com.landray.kmss.util.SpringBeanUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Date;
import java.util.List;
import static com.landray.kmss.third.notify.webservice.ThirdNotifyConstant.*;
import static com.landray.kmss.util.SpringBeanUtil.getBean;
public class ThirdNotifyJobWebServiceImpl extends BaseServiceImp implements IThirdNotifyJobWebService {
private static final Log logger = LogFactory.getLog(ThirdNotifyJobWebServiceImpl.class);
private IThirdNotifyInfoDetailsService thirdNotifyInfoDetailsService;
public IBaseService getServiceImp() {
if (thirdNotifyInfoDetailsService == null) {
thirdNotifyInfoDetailsService = (IThirdNotifyInfoDetailsService) getBean("thirdNotifyInfoDetailsService");
}
return thirdNotifyInfoDetailsService;
}
private IThirdNotifyInfoDetailsService getThirdNotifyInfoDetailsService() {
if (thirdNotifyInfoDetailsService == null)
thirdNotifyInfoDetailsService = (IThirdNotifyInfoDetailsService) SpringBeanUtil
.getBean("thirdNotifyInfoDetailsService");
return thirdNotifyInfoDetailsService;
}
private ThirdNotifyWebServiceImpl thirdNotifyWebService;
private ThirdNotifyWebServiceImpl getThirdNotifyWebService() {
if (thirdNotifyWebService == null)
thirdNotifyWebService = (ThirdNotifyWebServiceImpl) SpringBeanUtil
.getBean("thirdNotifyWebService");
return thirdNotifyWebService;
}
@Override
public void sendToNotifyInfoJob() throws Exception {
try {
List<ThirdNotifyInfoDetails> sendDataList = getThirdNotifyInfoDetailsService().getSendJobData();
if (sendDataList.size() != 0) {
Date nowDate = new Date();
for (int i = 0; i < sendDataList.size(); i++) {
ThirdNotifyInfoDetails infoDetails = sendDataList.get(i);
if (infoDetails != null) {
Date notifySendTime = infoDetails.getNotifySendTime();
if (notifySendTime != null && DINGTALK.equals(infoDetails.getNotifyType())) {
int dateResult = nowDate.compareTo(notifySendTime);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
package com.landray.kmss.third.notify.service;
import com.landray.kmss.sys.metadata.interfaces.IExtendDataService;
import com.landray.kmss.third.notify.model.ThirdNotifyInfoDetails;
import java.util.List;
public interface IThirdNotifyInfoDetailsService extends IExtendDataService {
List<ThirdNotifyInfoDetails> getSendJobData() throws Exception;
}
package com.landray.kmss.third.notify.service.spring;
import com.landray.kmss.common.actions.RequestContext;
import com.landray.kmss.common.convertor.ConvertorContext;
import com.landray.kmss.common.dao.HQLInfo;
import com.landray.kmss.common.forms.IExtendForm;
import com.landray.kmss.common.model.IBaseModel;
import com.landray.kmss.sys.metadata.interfaces.ExtendDataServiceImp;
import com.landray.kmss.sys.notify.interfaces.ISysNotifyMainCoreService;
import com.landray.kmss.third.notify.model.ThirdNotifyInfoDetails;
import com.landray.kmss.third.notify.service.IThirdNotifyInfoDetailsService;
import com.landray.kmss.third.notify.util.ThirdNotifyUtil;
import com.landray.kmss.util.SpringBeanUtil;
import java.util.Date;
import java.util.List;
public class ThirdNotifyInfoDetailsServiceImp extends ExtendDataServiceImp implements IThirdNotifyInfoDetailsService {
private ISysNotifyMainCoreService sysNotifyMainCoreService;
public IBaseModel convertBizFormToModel(IExtendForm form, IBaseModel model, ConvertorContext context) throws Exception {
model = super.convertBizFormToModel(form, model, context);
if (model instanceof ThirdNotifyInfoDetails) {
ThirdNotifyInfoDetails thirdNotifyInfoDetails = (ThirdNotifyInfoDetails) model;
}
return model;
}
public IBaseModel initBizModelSetting(RequestContext requestContext) throws Exception {
ThirdNotifyInfoDetails thirdNotifyInfoDetails = new ThirdNotifyInfoDetails();
thirdNotifyInfoDetails.setNotifyCreateTime(new Date());
thirdNotifyInfoDetails.setNotifyUpdateTime(new Date());
ThirdNotifyUtil.initModelFromRequest(thirdNotifyInfoDetails, requestContext);
return thirdNotifyInfoDetails;
}
public void initCoreServiceFormSetting(IExtendForm form, IBaseModel model, RequestContext requestContext) throws Exception {
ThirdNotifyInfoDetails thirdNotifyInfoDetails = (ThirdNotifyInfoDetails) model;
}
public ISysNotifyMainCoreService getSysNotifyMainCoreService() {
if (sysNotifyMainCoreService == null) {
sysNotifyMainCoreService = (ISysNotifyMainCoreService) SpringBeanUtil.getBean("sysNotifyMainCoreService");
}
return sysNotifyMainCoreService;
}
@Override
public List<ThirdNotifyInfoDetails> getSendJobData() throws Exception {
HQLInfo hqlInfo = new HQLInfo();
try {
hqlInfo.setWhereBlock("thirdNotifyInfoDetails.notifyPush = :notifyPush and thirdNotifyInfoDetails.notifyIsFlag = :notifyIsFlag");
hqlInfo.setParameter("notifyPush", "2");
hqlInfo.setParameter("notifyIsFlag", "0");
} catch (Exception e) {
e.printStackTrace();
}
return this.findList(hqlInfo);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
<!--外部系统消息通知定时任务服务接口-开始-->
<bean id="thirdNotifyJobWebService"
class="com.landray.kmss.third.notify.webservice.impl.ThirdNotifyJobWebServiceImpl"/>
<!--外部系统消息通知定时任务服务接口-结束-->
<!--外部系统消息通知定时任务服务接口-开始-->
<quartz
messageKey="third-notify:module.third.notify"
jobService="thirdNotifyJobWebService"
cronExpression="0 10 0 ? * *"
jobMethod="sendToNotifyInfoJob"
description="third-notify:module.third.notify.description"/>
<!--外部系统消息通知定时任务服务接口-结束-->
- 系统配置中导入系统任务