12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package com.yihu.wlyy.service;
- import java.security.KeyPair;
- import java.util.Iterator;
- import java.util.UUID;
- import org.springframework.beans.factory.annotation.Autowired;
- import com.yihu.wlyy.entity.security.RSA;
- import com.yihu.wlyy.repository.security.RSADao;
- import com.yihu.wlyy.util.CommonUtil;
- import org.springframework.stereotype.Service;
- @Service
- public class BaseService {
- // RSA加密信息持久化DAO
- @Autowired
- private RSADao rsaDao;
- public String getCode() {
- return UUID.randomUUID().toString().replaceAll("-", "");
- }
- @Autowired
- private CommonUtil CommonUtil;
- /**
- * 发送平台消息
- * @param content 消息内容
- * @param data 群组标识\网络咨询标识\问卷随访标识
- * @param platform 消息平台,1微信端/患者端,2医生APP端
- * @param readonly 只读消息:1否,0是
- * @param receiver 消息接收人(微信平台为患者标识,医生APP平台为医生标识)
- * @param sender 消息发送人标识
- * @param state 消息状态,1已发送,0待发送,-1发送失败
- * @param title 消息标题
- * @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、上门随访)
- * @return
- */
- // public Message sendMessage(String receiver, String sender, String title, String content, String data, int type, int platform, int readonly, int state) {
- // // 生成消息标识
- // Message message = new Message();
- // message.setCode(getCode());
- // message.setContent(content);
- // message.setData(data);
- // message.setDel("1");
- // message.setPlatform(platform);
- // message.setRead(0);
- // message.setReadonly(readonly);
- // message.setReceiver(receiver);
- // message.setSender(sender);
- // message.setState(state);
- // message.setTitle(title);
- // message.setType(type);
- // return messageDao.save(message);
- // }
- /**
- * 保存RSA加密信息
- * @return
- */
- public RSA saveRSA(KeyPair keyPair) {
- RSA rsa = new RSA();
- rsa.setData(CommonUtil.toByteArray(keyPair));
- // 先清空
- rsaDao.deleteAll();
- // 再添加
- return rsaDao.save(rsa);
- }
- /**
- * 读取RSA加密信息
- * @return
- */
- public RSA loadRSA() {
- Iterable<RSA> iterable = rsaDao.findAll();
- if (iterable != null) {
- Iterator<RSA> it = iterable.iterator();
- if (it != null && it.hasNext()) {
- return it.next();
- }
- }
- return null;
- }
- }
|