a37736173357f4313a7498ee8aa4b735bb3eb0b4.svn-base 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. package com.kingdee.eas.custom.utils;
  2. import com.kingdee.bos.BOSException;
  3. import com.kingdee.bos.Context;
  4. import com.kingdee.bos.dao.IObjectPK;
  5. import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
  6. import com.kingdee.bos.message.common.KDMessageAttachment;
  7. import com.kingdee.bos.util.BOSUuid;
  8. import com.kingdee.eas.base.permission.IUser;
  9. import com.kingdee.eas.base.permission.UserFactory;
  10. import com.kingdee.eas.base.permission.UserInfo;
  11. import com.kingdee.eas.basedata.person.IPerson;
  12. import com.kingdee.eas.basedata.person.PersonFactory;
  13. import com.kingdee.eas.basedata.person.PersonInfo;
  14. import com.kingdee.eas.common.EASBizException;
  15. import com.kingdee.eas.mobile.CellphoneNumberTypeEnum;
  16. import com.kingdee.eas.mobile.EmailAddressInfo;
  17. import com.kingdee.eas.mobile.EmailSendMessageInfo;
  18. import com.kingdee.eas.mobile.MimeTypeEnum;
  19. import com.kingdee.eas.mobile.MobileException;
  20. import com.kingdee.eas.mobile.MobileMessageAddressInfo;
  21. import com.kingdee.eas.mobile.SendMobileMessageInfo;
  22. import com.kingdee.eas.mobile.dao.DefaultEmailMessageDAO;
  23. import com.kingdee.eas.mobile.dao.DefaultSendMoMsgDao;
  24. import com.kingdee.eas.mobile.framework.ServerCenterFactory;
  25. import com.kingdee.eas.mobile.msg.MobileConnectException;
  26. import com.kingdee.eas.mobile.msg.util.MsgUtil;
  27. import com.kingdee.eas.mobile.util.AppMsgUtil;
  28. import com.kingdee.eas.mobile.util.MobileUtil;
  29. import com.kingdee.eas.util.app.ContextUtil;
  30. import com.kingdee.util.StringUtils;
  31. import java.util.List;
  32. // 发送邮件的重写类
  33. public class SendUtils extends MsgUtil {
  34. public static boolean msgSend(Context ctx, String title, int priority, boolean revertible, String content,
  35. String personId, int msgType, KDMessageAttachment[] attachment, String assignID)
  36. throws EASBizException, BOSException {
  37. return msgSend(ctx, title, priority, revertible, content, personId, msgType, attachment, assignID,
  38. (MimeTypeEnum) null);
  39. }
  40. public static boolean msgSend(Context ctx, String title, int priority, boolean revertible, String content,
  41. String personId, int msgType, KDMessageAttachment[] attachment, String assignID, MimeTypeEnum mimeType)
  42. throws EASBizException, BOSException {
  43. PersonInfo person = null;
  44. String address = null;
  45. if (!StringUtils.isEmpty(personId)) {
  46. IPerson iPerson = PersonFactory.getLocalInstance(ctx);
  47. IObjectPK pk = null;
  48. pk = new ObjectUuidPK(personId);
  49. person = iPerson.getPersonInfo(pk);
  50. boolean succeed = false;
  51. switch (msgType) {
  52. case 1 :
  53. address = person.getCell();
  54. if (StringUtils.isEmpty(address)) {
  55. throw new MobileConnectException(MobileConnectException.USER_NOT_LOIGN);
  56. }
  57. succeed = sendMobileMsg(ctx, title, priority, revertible, content, address, assignID);
  58. return succeed;
  59. case 2 :
  60. address = person.getEmail();
  61. if (StringUtils.isEmpty(address)) {
  62. //throw new MobileConnectException(MobileConnectException.USER_NOT_LOIGN_EMAIL);
  63. return succeed;
  64. }
  65. succeed = sendMail(ctx, title, priority, revertible, content, address, attachment, assignID,
  66. mimeType);
  67. ServerCenterFactory.getServerCenter(ctx);
  68. return succeed;
  69. case 3 :
  70. address = person.getRtx();
  71. if (StringUtils.isEmpty(address)) {
  72. throw new MobileConnectException(MobileConnectException.USER_NOT_LOIGN_RTX);
  73. }
  74. succeed = sendRTXMsg(ctx, title, priority, revertible, content, address);
  75. ServerCenterFactory.getServerCenter(ctx);
  76. return succeed;
  77. default :
  78. throw new MobileException(MobileException.MSGTYPE_ERROR);
  79. }
  80. } else {
  81. throw new MobileConnectException(MobileConnectException.USER_NOT_LOIGN);
  82. }
  83. }
  84. private static boolean sendMail(Context ctx, String title, int priority, boolean revertible, String content,
  85. String address, KDMessageAttachment[] attachment, String assignID) throws EASBizException, BOSException {
  86. return sendMail(ctx, title, priority, revertible, content, address, attachment, assignID, (MimeTypeEnum) null);
  87. }
  88. private static boolean sendMail(Context ctx, String title, int priority, boolean revertible, String content,
  89. String address, KDMessageAttachment[] attachment, String assignID, MimeTypeEnum mimeType)
  90. throws EASBizException, BOSException {
  91. EmailSendMessageInfo emailSendMsgInfo = new EmailSendMessageInfo();
  92. if (mimeType != null) {
  93. emailSendMsgInfo.setMimeType(mimeType);
  94. }
  95. emailSendMsgInfo.setPriority(AppMsgUtil.getPriorityEnum(priority));
  96. emailSendMsgInfo.setRevertible(revertible);
  97. emailSendMsgInfo.setAssignID(assignID);
  98. emailSendMsgInfo.setContent(content);
  99. emailSendMsgInfo.setTitle(title);
  100. EmailAddressInfo addressInfo = new EmailAddressInfo();
  101. UserInfo userInfo = ContextUtil.getCurrentUserInfo(ctx);
  102. if (userInfo != null) {
  103. addressInfo.setSendBizUser(userInfo);
  104. PersonInfo sendPersonInfo = AppMsgUtil.getPersonByUser(ctx, userInfo);
  105. if (sendPersonInfo != null && !StringUtils.isEmpty(sendPersonInfo.getEmail())) {
  106. addressInfo.setFrom(sendPersonInfo.getEmail());
  107. }
  108. emailSendMsgInfo.setTitle(title);
  109. } else {
  110. emailSendMsgInfo.setTitle(title);
  111. }
  112. addressInfo.setTo(address);
  113. emailSendMsgInfo.setAddress(addressInfo);
  114. boolean sendSuccess = false;
  115. IObjectPK pk = DefaultEmailMessageDAO.addNew(ctx, emailSendMsgInfo);
  116. if (pk != null) {
  117. sendSuccess = true;
  118. } else {
  119. //logger.info("add email: pk is null.");
  120. }
  121. return sendSuccess;
  122. }
  123. private static boolean sendMobileMsg(Context ctx, String title, int priority, boolean revertible, String content,
  124. String receiveMobileNumber, String assignID) throws EASBizException, BOSException {
  125. SendMobileMessageInfo sendMoMsgInfo = new SendMobileMessageInfo();
  126. sendMoMsgInfo.setSendHandcraft(true);
  127. sendMoMsgInfo.setRevertible(revertible);
  128. sendMoMsgInfo.setPriority(AppMsgUtil.getPriorityEnum(priority));
  129. sendMoMsgInfo.setContent(title);
  130. sendMoMsgInfo.setTitle(content);
  131. sendMoMsgInfo.setAssignID(assignID);
  132. MobileMessageAddressInfo addressInfo = new MobileMessageAddressInfo();
  133. UserInfo userInfo = ContextUtil.getCurrentUserInfo(ctx);
  134. if (userInfo != null) {
  135. addressInfo.setSendBizUser(userInfo);
  136. PersonInfo sendPersonInfo = AppMsgUtil.getPersonByUser(ctx, userInfo);
  137. if (sendPersonInfo != null && !StringUtils.isEmpty(sendPersonInfo.getCell())) {
  138. addressInfo.setSendMobileNumber(sendPersonInfo.getCell());
  139. addressInfo.setSendCellNumberType(
  140. CellphoneNumberTypeEnum.getEnum(MobileUtil.getCellphoneNumberType(sendPersonInfo.getCell())));
  141. }
  142. sendMoMsgInfo.setTitle(title);
  143. } else {
  144. sendMoMsgInfo.setTitle(content);
  145. }
  146. addressInfo.setReceiveMobileNumber(receiveMobileNumber);
  147. addressInfo.setReceiveCellNumberType(
  148. CellphoneNumberTypeEnum.getEnum(MobileUtil.getCellphoneNumberType(receiveMobileNumber)));
  149. UserInfo receiveUserInfo = null;
  150. String receiveUserId = AppMsgUtil.getUserIdByMobileNumber(ctx, receiveMobileNumber);
  151. IUser iUser = UserFactory.getLocalInstance(ctx);
  152. if (!StringUtils.isEmpty(receiveUserId)) {
  153. try {
  154. receiveUserInfo = iUser.getUserInfo(new ObjectUuidPK(receiveUserId));
  155. } catch (Exception var15) {
  156. receiveUserInfo = null;
  157. }
  158. }
  159. addressInfo.setReceiveBizUser(receiveUserInfo);
  160. sendMoMsgInfo.setAddress(addressInfo);
  161. IObjectPK pk = null;
  162. boolean sendSuccess = false;
  163. pk = DefaultSendMoMsgDao.addNew(ctx, sendMoMsgInfo);
  164. if (pk != null) {
  165. sendSuccess = true;
  166. }
  167. return sendSuccess;
  168. }
  169. private static boolean sendRTXMsg(Context ctx, String title, int priority, boolean revertible, String content,
  170. String address) throws EASBizException, BOSException {
  171. return false;
  172. }
  173. public static int msgGroupSend(Context ctx, String title, int priority, boolean revertible, String content,
  174. List userList, int msgType, KDMessageAttachment[] attachment) throws EASBizException, BOSException {
  175. if (msgType != 2 && msgType != 1) {
  176. throw new MobileException(MobileException.MSGTYPE_ERROR);
  177. } else {
  178. IUser iUser = UserFactory.getLocalInstance(ctx);
  179. IObjectPK pk = null;
  180. BOSUuid uuid = null;
  181. UserInfo receiveUser = null;
  182. PersonInfo receivePerson = null;
  183. String address = null;
  184. int userNum = userList.size();
  185. int sentNum = 0;
  186. boolean sendSucceed = false;
  187. for (int i = 0; i < userNum; ++i) {
  188. try {
  189. if (userList.get(i) != null && !StringUtils.isEmpty(userList.get(i).toString())) {
  190. uuid = BOSUuid.read(userList.get(i).toString().trim());
  191. pk = new ObjectUuidPK(uuid);
  192. receiveUser = iUser.getUserInfo(pk);
  193. if (receiveUser.getPerson() != null) {
  194. receivePerson = AppMsgUtil.getPersonByUser(ctx, receiveUser);
  195. if (receivePerson != null) {
  196. switch (msgType) {
  197. case 2 :
  198. address = receivePerson.getEmail();
  199. if (StringUtils.isEmpty(address)) {
  200. break;
  201. }
  202. sendSucceed = sendMail(ctx, title, priority, revertible, content, address,
  203. attachment, (String) null);
  204. case 1 :
  205. address = receivePerson.getCell();
  206. if (StringUtils.isEmpty(address)) {
  207. break;
  208. }
  209. // sendSucceed = newMsgMobile(ctx, revertible, title, content, priority,
  210. // receiveUser, address);
  211. default :
  212. if (sendSucceed) {
  213. ++sentNum;
  214. sendSucceed = false;
  215. }
  216. }
  217. }
  218. }
  219. }
  220. } catch (Exception var19) {
  221. //logger.info("Exception in MsgUtil.msgGroupSend方法" + var19.getMessage());
  222. }
  223. }
  224. return sentNum;
  225. }
  226. }
  227. }