123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- package com.kingdee.eas.custom.utils;
- import com.kingdee.bos.BOSException;
- import com.kingdee.bos.Context;
- import com.kingdee.bos.dao.IObjectPK;
- import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
- import com.kingdee.bos.message.common.KDMessageAttachment;
- import com.kingdee.bos.util.BOSUuid;
- import com.kingdee.eas.base.permission.IUser;
- import com.kingdee.eas.base.permission.UserFactory;
- import com.kingdee.eas.base.permission.UserInfo;
- import com.kingdee.eas.basedata.person.IPerson;
- import com.kingdee.eas.basedata.person.PersonFactory;
- import com.kingdee.eas.basedata.person.PersonInfo;
- import com.kingdee.eas.common.EASBizException;
- import com.kingdee.eas.mobile.CellphoneNumberTypeEnum;
- import com.kingdee.eas.mobile.EmailAddressInfo;
- import com.kingdee.eas.mobile.EmailSendMessageInfo;
- import com.kingdee.eas.mobile.MimeTypeEnum;
- import com.kingdee.eas.mobile.MobileException;
- import com.kingdee.eas.mobile.MobileMessageAddressInfo;
- import com.kingdee.eas.mobile.SendMobileMessageInfo;
- import com.kingdee.eas.mobile.dao.DefaultEmailMessageDAO;
- import com.kingdee.eas.mobile.dao.DefaultSendMoMsgDao;
- import com.kingdee.eas.mobile.framework.ServerCenterFactory;
- import com.kingdee.eas.mobile.msg.MobileConnectException;
- import com.kingdee.eas.mobile.msg.util.MsgUtil;
- import com.kingdee.eas.mobile.util.AppMsgUtil;
- import com.kingdee.eas.mobile.util.MobileUtil;
- import com.kingdee.eas.util.app.ContextUtil;
- import com.kingdee.util.StringUtils;
- import java.util.List;
- // 发送邮件的重写类
- public class SendUtils extends MsgUtil {
-
- public static boolean msgSend(Context ctx, String title, int priority, boolean revertible, String content,
- String personId, int msgType, KDMessageAttachment[] attachment, String assignID)
- throws EASBizException, BOSException {
- return msgSend(ctx, title, priority, revertible, content, personId, msgType, attachment, assignID,
- (MimeTypeEnum) null);
- }
-
- public static boolean msgSend(Context ctx, String title, int priority, boolean revertible, String content,
- String personId, int msgType, KDMessageAttachment[] attachment, String assignID, MimeTypeEnum mimeType)
- throws EASBizException, BOSException {
- PersonInfo person = null;
- String address = null;
- if (!StringUtils.isEmpty(personId)) {
- IPerson iPerson = PersonFactory.getLocalInstance(ctx);
- IObjectPK pk = null;
- pk = new ObjectUuidPK(personId);
- person = iPerson.getPersonInfo(pk);
- boolean succeed = false;
- switch (msgType) {
- case 1 :
- address = person.getCell();
- if (StringUtils.isEmpty(address)) {
- throw new MobileConnectException(MobileConnectException.USER_NOT_LOIGN);
- }
- succeed = sendMobileMsg(ctx, title, priority, revertible, content, address, assignID);
- return succeed;
- case 2 :
- address = person.getEmail();
- if (StringUtils.isEmpty(address)) {
- //throw new MobileConnectException(MobileConnectException.USER_NOT_LOIGN_EMAIL);
- return succeed;
- }
- succeed = sendMail(ctx, title, priority, revertible, content, address, attachment, assignID,
- mimeType);
- ServerCenterFactory.getServerCenter(ctx);
- return succeed;
- case 3 :
- address = person.getRtx();
- if (StringUtils.isEmpty(address)) {
- throw new MobileConnectException(MobileConnectException.USER_NOT_LOIGN_RTX);
- }
- succeed = sendRTXMsg(ctx, title, priority, revertible, content, address);
- ServerCenterFactory.getServerCenter(ctx);
- return succeed;
- default :
- throw new MobileException(MobileException.MSGTYPE_ERROR);
- }
- } else {
- throw new MobileConnectException(MobileConnectException.USER_NOT_LOIGN);
- }
- }
- private static boolean sendMail(Context ctx, String title, int priority, boolean revertible, String content,
- String address, KDMessageAttachment[] attachment, String assignID) throws EASBizException, BOSException {
- return sendMail(ctx, title, priority, revertible, content, address, attachment, assignID, (MimeTypeEnum) null);
- }
-
- private static boolean sendMail(Context ctx, String title, int priority, boolean revertible, String content,
- String address, KDMessageAttachment[] attachment, String assignID, MimeTypeEnum mimeType)
- throws EASBizException, BOSException {
- EmailSendMessageInfo emailSendMsgInfo = new EmailSendMessageInfo();
- if (mimeType != null) {
- emailSendMsgInfo.setMimeType(mimeType);
- }
- emailSendMsgInfo.setPriority(AppMsgUtil.getPriorityEnum(priority));
- emailSendMsgInfo.setRevertible(revertible);
- emailSendMsgInfo.setAssignID(assignID);
- emailSendMsgInfo.setContent(content);
- emailSendMsgInfo.setTitle(title);
- EmailAddressInfo addressInfo = new EmailAddressInfo();
- UserInfo userInfo = ContextUtil.getCurrentUserInfo(ctx);
- if (userInfo != null) {
- addressInfo.setSendBizUser(userInfo);
- PersonInfo sendPersonInfo = AppMsgUtil.getPersonByUser(ctx, userInfo);
- if (sendPersonInfo != null && !StringUtils.isEmpty(sendPersonInfo.getEmail())) {
- addressInfo.setFrom(sendPersonInfo.getEmail());
- }
- emailSendMsgInfo.setTitle(title);
- } else {
- emailSendMsgInfo.setTitle(title);
- }
- addressInfo.setTo(address);
- emailSendMsgInfo.setAddress(addressInfo);
- boolean sendSuccess = false;
- IObjectPK pk = DefaultEmailMessageDAO.addNew(ctx, emailSendMsgInfo);
- if (pk != null) {
- sendSuccess = true;
- } else {
- //logger.info("add email: pk is null.");
- }
- return sendSuccess;
- }
-
- private static boolean sendMobileMsg(Context ctx, String title, int priority, boolean revertible, String content,
- String receiveMobileNumber, String assignID) throws EASBizException, BOSException {
- SendMobileMessageInfo sendMoMsgInfo = new SendMobileMessageInfo();
- sendMoMsgInfo.setSendHandcraft(true);
- sendMoMsgInfo.setRevertible(revertible);
- sendMoMsgInfo.setPriority(AppMsgUtil.getPriorityEnum(priority));
- sendMoMsgInfo.setContent(title);
- sendMoMsgInfo.setTitle(content);
- sendMoMsgInfo.setAssignID(assignID);
- MobileMessageAddressInfo addressInfo = new MobileMessageAddressInfo();
- UserInfo userInfo = ContextUtil.getCurrentUserInfo(ctx);
- if (userInfo != null) {
- addressInfo.setSendBizUser(userInfo);
- PersonInfo sendPersonInfo = AppMsgUtil.getPersonByUser(ctx, userInfo);
- if (sendPersonInfo != null && !StringUtils.isEmpty(sendPersonInfo.getCell())) {
- addressInfo.setSendMobileNumber(sendPersonInfo.getCell());
- addressInfo.setSendCellNumberType(
- CellphoneNumberTypeEnum.getEnum(MobileUtil.getCellphoneNumberType(sendPersonInfo.getCell())));
- }
- sendMoMsgInfo.setTitle(title);
- } else {
- sendMoMsgInfo.setTitle(content);
- }
- addressInfo.setReceiveMobileNumber(receiveMobileNumber);
- addressInfo.setReceiveCellNumberType(
- CellphoneNumberTypeEnum.getEnum(MobileUtil.getCellphoneNumberType(receiveMobileNumber)));
- UserInfo receiveUserInfo = null;
- String receiveUserId = AppMsgUtil.getUserIdByMobileNumber(ctx, receiveMobileNumber);
- IUser iUser = UserFactory.getLocalInstance(ctx);
- if (!StringUtils.isEmpty(receiveUserId)) {
- try {
- receiveUserInfo = iUser.getUserInfo(new ObjectUuidPK(receiveUserId));
- } catch (Exception var15) {
- receiveUserInfo = null;
- }
- }
- addressInfo.setReceiveBizUser(receiveUserInfo);
- sendMoMsgInfo.setAddress(addressInfo);
- IObjectPK pk = null;
- boolean sendSuccess = false;
- pk = DefaultSendMoMsgDao.addNew(ctx, sendMoMsgInfo);
- if (pk != null) {
- sendSuccess = true;
- }
- return sendSuccess;
- }
-
- private static boolean sendRTXMsg(Context ctx, String title, int priority, boolean revertible, String content,
- String address) throws EASBizException, BOSException {
- return false;
- }
- public static int msgGroupSend(Context ctx, String title, int priority, boolean revertible, String content,
- List userList, int msgType, KDMessageAttachment[] attachment) throws EASBizException, BOSException {
- if (msgType != 2 && msgType != 1) {
- throw new MobileException(MobileException.MSGTYPE_ERROR);
- } else {
- IUser iUser = UserFactory.getLocalInstance(ctx);
- IObjectPK pk = null;
- BOSUuid uuid = null;
- UserInfo receiveUser = null;
- PersonInfo receivePerson = null;
- String address = null;
- int userNum = userList.size();
- int sentNum = 0;
- boolean sendSucceed = false;
- for (int i = 0; i < userNum; ++i) {
- try {
- if (userList.get(i) != null && !StringUtils.isEmpty(userList.get(i).toString())) {
- uuid = BOSUuid.read(userList.get(i).toString().trim());
- pk = new ObjectUuidPK(uuid);
- receiveUser = iUser.getUserInfo(pk);
- if (receiveUser.getPerson() != null) {
- receivePerson = AppMsgUtil.getPersonByUser(ctx, receiveUser);
- if (receivePerson != null) {
- switch (msgType) {
- case 2 :
- address = receivePerson.getEmail();
- if (StringUtils.isEmpty(address)) {
- break;
- }
- sendSucceed = sendMail(ctx, title, priority, revertible, content, address,
- attachment, (String) null);
- case 1 :
- address = receivePerson.getCell();
- if (StringUtils.isEmpty(address)) {
- break;
- }
- // sendSucceed = newMsgMobile(ctx, revertible, title, content, priority,
- // receiveUser, address);
- default :
- if (sendSucceed) {
- ++sentNum;
- sendSucceed = false;
- }
- }
- }
- }
- }
- } catch (Exception var19) {
- //logger.info("Exception in MsgUtil.msgGroupSend方法" + var19.getMessage());
- }
- }
- return sentNum;
- }
-
- }
- }
|