- 继承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;
}
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;
}
}
<!--外部系统消息通知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服务接口-结束-->
- 导入并发布服务
定时任务
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);
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);
}
}
<!--外部系统消息通知定时任务服务接口-开始-->
<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"/>
<!--外部系统消息通知定时任务服务接口-结束-->
- 系统配置中导入系统任务