BaseService.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package com.yihu.wlyy.service;
  2. import java.security.KeyPair;
  3. import java.util.Iterator;
  4. import java.util.UUID;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import com.yihu.wlyy.entity.security.RSA;
  7. import com.yihu.wlyy.repository.security.RSADao;
  8. import com.yihu.wlyy.util.CommonUtil;
  9. import org.springframework.stereotype.Service;
  10. @Service
  11. public class BaseService {
  12. // RSA加密信息持久化DAO
  13. @Autowired
  14. private RSADao rsaDao;
  15. public String getCode() {
  16. return UUID.randomUUID().toString().replaceAll("-", "");
  17. }
  18. @Autowired
  19. private CommonUtil CommonUtil;
  20. /**
  21. * 发送平台消息
  22. * @param content 消息内容
  23. * @param data 群组标识\网络咨询标识\问卷随访标识
  24. * @param platform 消息平台,1微信端/患者端,2医生APP端
  25. * @param readonly 只读消息:1否,0是
  26. * @param receiver 消息接收人(微信平台为患者标识,医生APP平台为医生标识)
  27. * @param sender 消息发送人标识
  28. * @param state 消息状态,1已发送,0待发送,-1发送失败
  29. * @param title 消息标题
  30. * @param type 消息类型(101患者申请取消签约、102患者同意取消签约、103患者拒绝取消签约、104患者填写了血糖记录、105患者填写了血压记录、106患者填写了体重记录、107患者填写了腰围记录、108患者填写了运动记录、109患者填写了用药记录、110患者填写了饮食记录、111患者提交了问卷随访、112请求添加好友消息、113入群消息、114群解散消息、115踢出群消息、116新的网络咨询、117网络咨询追问、201医生拒绝签约、202医生同意签约、203医生申请取消签约、204医生同意取消签约、205医生拒绝取消签约、206新的问卷随访、207新的健康干预、208请求添加好友消息、209入群消息、210群解散消息、211踢出群消息、212聊天消息提醒、213群聊天消息、214医生回复了网络咨询、215请求添加为家人、216电话随访,217、上门随访)
  31. * @return
  32. */
  33. // public Message sendMessage(String receiver, String sender, String title, String content, String data, int type, int platform, int readonly, int state) {
  34. // // 生成消息标识
  35. // Message message = new Message();
  36. // message.setCode(getCode());
  37. // message.setContent(content);
  38. // message.setData(data);
  39. // message.setDel("1");
  40. // message.setPlatform(platform);
  41. // message.setRead(0);
  42. // message.setReadonly(readonly);
  43. // message.setReceiver(receiver);
  44. // message.setSender(sender);
  45. // message.setState(state);
  46. // message.setTitle(title);
  47. // message.setType(type);
  48. // return messageDao.save(message);
  49. // }
  50. /**
  51. * 保存RSA加密信息
  52. * @return
  53. */
  54. public RSA saveRSA(KeyPair keyPair) {
  55. RSA rsa = new RSA();
  56. rsa.setData(CommonUtil.toByteArray(keyPair));
  57. // 先清空
  58. rsaDao.deleteAll();
  59. // 再添加
  60. return rsaDao.save(rsa);
  61. }
  62. /**
  63. * 读取RSA加密信息
  64. * @return
  65. */
  66. public RSA loadRSA() {
  67. Iterable<RSA> iterable = rsaDao.findAll();
  68. if (iterable != null) {
  69. Iterator<RSA> it = iterable.iterator();
  70. if (it != null && it.hasNext()) {
  71. return it.next();
  72. }
  73. }
  74. return null;
  75. }
  76. }