|
@@ -1,8 +1,8 @@
|
|
|
package thyyxxk.webserver.service.ca;
|
|
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
|
-import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.io.file.FileNameUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.IdcardUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
@@ -16,12 +16,14 @@ import com.dtflys.forest.Forest;
|
|
|
import com.dtflys.forest.http.ForestRequest;
|
|
|
import com.dtflys.forest.logging.LogConfiguration;
|
|
|
import com.dtflys.forest.utils.ForestDataType;
|
|
|
-import com.sun.org.apache.bcel.internal.generic.NEW;
|
|
|
import lombok.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.ibatis.annotations.Update;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import thyyxxk.webserver.config.Assertion;
|
|
|
+import thyyxxk.webserver.config.envionment.Archive;
|
|
|
+import thyyxxk.webserver.config.envionment.CaData;
|
|
|
import thyyxxk.webserver.config.exception.BizException;
|
|
|
import thyyxxk.webserver.config.exception.ExceptionEnum;
|
|
|
import thyyxxk.webserver.constants.YesOrNo;
|
|
@@ -36,9 +38,9 @@ import thyyxxk.webserver.service.redislike.RedisLikeService;
|
|
|
import thyyxxk.webserver.service.zhuyuanyisheng.emr.EmrServer;
|
|
|
import thyyxxk.webserver.utils.ResultVoUtil;
|
|
|
|
|
|
-import javax.swing.text.EditorKit;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URLDecoder;
|
|
|
+import java.nio.charset.Charset;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -48,7 +50,6 @@ import java.util.concurrent.TimeUnit;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class CaServer implements Assertion {
|
|
|
-
|
|
|
private final CaData caData;
|
|
|
private final String SUCCRSS = "success";
|
|
|
private final RedisLikeService redisLikeService;
|
|
@@ -57,26 +58,17 @@ public class CaServer implements Assertion {
|
|
|
private final RedisServer redisServer;
|
|
|
private final EmrCaSignDao emrCaSignDao;
|
|
|
private final EmrPatientDao emrPatientDao;
|
|
|
+ private final Archive archive;
|
|
|
|
|
|
private final static String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKAc+jzqVKHsjNdyuDGL7u6zZR55j87l+0GGT4/yEV+K8ZtL1GoIgOD6vv6eEg2iOwl6Wh6hq8XR4cIyzVyvMZ35dIw3oGN89ObtuCha7gLOmWYUIGVnkUBkLFeIdwe4F8bq1q15o7azsTVekSyNJf/wnxWMp8ibtvO41T8DIzZPAgMBAAECgYAeeLVVD4Gw2VyKij4sy8Var1CQxrDMPu+c7ktJCVguFzrZA8r2rQyeBIqB2aJ07smOibcJ+lm/Ca0N8O4tc/gcm4g/JsjBALFUmqyCkLQpRyIbz8V9uAmrLcchT74GS727Uv4KVTmQNDZTPIDdSZWSJ8S+WKmj8q3wUF1HLF1eXQJBAOC7D6xIB2XNS6Voa7C7m8aeg53lfcDUVJ6m0YFdvMbsU2cnlxnCSX1OsghFuVQLKcGeN+aXiTEileb3pAl2RC0CQQC2ZDtDb+1OmLmRNugp29Pmm8MM8KpktfqiBFi92Q747XwEeMgLi3qetq1wDT4dgvyURs2McsbF7diVtFv7DMXrAkAoYzXj3mYF86k+ps+DyZOrVF2PCOlauE4k3RIVz8TXcy1iAolzRalzbastNWqjIgZ1F3wwYtdzDyYlhifi03BZAkEArkgidPMbwDGhiAf+WhkrZz1JaTECsM9PGcergGVLsENFcQR0qstxtPz7x4lv5EVI0urA+Man93OptIsuJTr0VwJAd86EbHyOn5Lah7ptPGsmsqkrdMZcJ3chRj6pDtvb0A2lhaJfDRxmAiWCnviPhTApH6/1WRzBqc1ZTymyRTF9kA==";
|
|
|
private final static String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCgHPo86lSh7IzXcrgxi+7us2UeeY/O5ftBhk+P8hFfivGbS9RqCIDg+r7+nhINojsJeloeoavF0eHCMs1crzGd+XSMN6BjfPTm7bgoWu4CzplmFCBlZ5FAZCxXiHcHuBfG6tateaO2s7E1XpEsjSX/8J8VjKfIm7bzuNU/AyM2TwIDAQAB";
|
|
|
RSA idCardRsa = new RSA(privateKey, publicKey);
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- test();
|
|
|
- }
|
|
|
-
|
|
|
- public static void test() {
|
|
|
- String url = "D:\\.a1.world\\1.txt";
|
|
|
- String s = FileUtil.readString(url, StandardCharsets.UTF_8);
|
|
|
- JSONObject entries = JSONUtil.parseObj(s);
|
|
|
- String handSign = entries.getStr("pdf");
|
|
|
- byte[] decode = Base64.decode(handSign);
|
|
|
- FileUtil.writeBytes(decode, "D:\\.a1.world\\1.pdf");
|
|
|
- log.info("数据:{}\ndecode:{}", s, decode);
|
|
|
+ private String getRedisKey(String documentId) {
|
|
|
+ return "ca-emr-" + documentId;
|
|
|
}
|
|
|
|
|
|
- public CaServer(CaData caData, RedisLikeService redisLikeService, EmrServer emrServer, EmrPatientDao dao, RedisServer redisServer, EmrCaSignDao emrCaSignDao, EmrPatientDao emrPatientDao) {
|
|
|
+ public CaServer(CaData caData, RedisLikeService redisLikeService, EmrServer emrServer, EmrPatientDao dao, RedisServer redisServer, EmrCaSignDao emrCaSignDao, EmrPatientDao emrPatientDao, Archive archive) {
|
|
|
this.caData = caData;
|
|
|
this.redisLikeService = redisLikeService;
|
|
|
this.emrServer = emrServer;
|
|
@@ -84,18 +76,10 @@ public class CaServer implements Assertion {
|
|
|
this.redisServer = redisServer;
|
|
|
this.emrCaSignDao = emrCaSignDao;
|
|
|
this.emrPatientDao = emrPatientDao;
|
|
|
+ this.archive = archive;
|
|
|
}
|
|
|
|
|
|
- @EqualsAndHashCode(callSuper = true)
|
|
|
- @Data
|
|
|
- public static class Send extends CaSendParams {
|
|
|
- private String id;
|
|
|
- private String msg;
|
|
|
- private String desc;
|
|
|
- private Integer count = 1;
|
|
|
- }
|
|
|
-
|
|
|
- public List<CaReturn.CaData> sendBatchByCode(Send send) {
|
|
|
+ public List<CaReturn.CaData> sendBatchByCode(CaSignClass.Send send) {
|
|
|
List<CaReturn.CaData> returnValue = new ArrayList<>();
|
|
|
for (int i = 0; i < send.getCount(); i++) {
|
|
|
returnValue.add(sendByCode(send));
|
|
@@ -103,7 +87,7 @@ public class CaServer implements Assertion {
|
|
|
return returnValue;
|
|
|
}
|
|
|
|
|
|
- public CaReturn.CaData sendByCode(Send send) {
|
|
|
+ public CaReturn.CaData sendByCode(CaSignClass.Send send) {
|
|
|
UserInfo userInfoByCode = redisLikeService.getUserInfoByCode(send.getId());
|
|
|
send.setBizSn(IdUtil.simpleUUID());
|
|
|
String msg = CaUtils.GetSHA256FormString(send.getMsg());
|
|
@@ -124,7 +108,7 @@ public class CaServer implements Assertion {
|
|
|
* @param send
|
|
|
* @return 返回值
|
|
|
*/
|
|
|
- private CaReturn push(Send send, String msg) {
|
|
|
+ private CaReturn push(CaSignClass.Send send, String msg) {
|
|
|
CaData.MobileApp app = caData.getMobileApp();
|
|
|
|
|
|
CaSendParams params = CaSendParams
|
|
@@ -272,36 +256,12 @@ public class CaServer implements Assertion {
|
|
|
return ResultVoUtil.success(ExceptionEnum.LOGICAL_ERROR, execute.getMsg());
|
|
|
}
|
|
|
|
|
|
- @Data
|
|
|
- public static class MoreEventSignData {
|
|
|
- private String content;
|
|
|
-
|
|
|
- /**
|
|
|
- * 签署人身份类型。例如患者本人、亲属、朋友
|
|
|
- * 、伴侣。进行 URLEncode 编码的数据,并且中
|
|
|
- * 文长度不得大于 8
|
|
|
- */
|
|
|
- private String signType;
|
|
|
- private String signTypeName;
|
|
|
- private String signName;
|
|
|
- private String idCard;
|
|
|
- private String name;
|
|
|
- private String signOpinion;
|
|
|
- }
|
|
|
-
|
|
|
- @Data
|
|
|
- public static class MoreEventSign {
|
|
|
- private String documentId;
|
|
|
- private String sendCode;
|
|
|
- private String sendCodeName;
|
|
|
- private List<MoreEventSignData> data;
|
|
|
- }
|
|
|
|
|
|
private void verifyMedicalRecordStatus(String documentId, EmrSignType type) {
|
|
|
EmrPatientData emrData = emrPatientDao.selectById(documentId);
|
|
|
- if (emrData == null || emrData.getDelFlag() == 1) {
|
|
|
- throw new BizException(ExceptionEnum.LOGICAL_ERROR, "病历已被删除。");
|
|
|
- }
|
|
|
+// if (emrData == null || emrData.getDelFlag() == 1) {
|
|
|
+// throw new BizException(ExceptionEnum.LOGICAL_ERROR, "病历已被删除。");
|
|
|
+// }
|
|
|
isTrueErr(emrData.getSignComplete(), "扫码流程已完成请勿重复点击");
|
|
|
if (emrData.getSignType() != null && !Objects.equals(type.getCode(), emrData.getSignType())) {
|
|
|
throw new BizException(ExceptionEnum.LOGICAL_ERROR, "请使用上次选择的方式完成CA流程中途不得修改。");
|
|
@@ -319,7 +279,7 @@ public class CaServer implements Assertion {
|
|
|
* @param moreEventSign 数据
|
|
|
* @return 暂无
|
|
|
*/
|
|
|
- public ResultVo<JSONObject> sendMoreEventSign(MoreEventSign moreEventSign) {
|
|
|
+ public ResultVo<JSONObject> sendMoreEventSign(CaSignClass.MoreEventSign moreEventSign) {
|
|
|
verifyMedicalRecordStatus(moreEventSign.getDocumentId(), EmrSignType.MOVE);
|
|
|
moreEventSign.getData().forEach(item -> {
|
|
|
isBlank(item.getIdCard(), "身份证不能为空。");
|
|
@@ -327,35 +287,31 @@ public class CaServer implements Assertion {
|
|
|
isBlank(item.getSignType(), "与患者的关系不能为空。");
|
|
|
item.setIdCard(idCardRsa.decryptStr(item.getIdCard(), KeyType.PrivateKey));
|
|
|
});
|
|
|
- EmrCaSign emrCaSign = emrCaSignDao.selectById(moreEventSign.getDocumentId());
|
|
|
- if (emrCaSign != null) {
|
|
|
- cancelSignature(emrCaSign.getData());
|
|
|
+ String redisKey = getRedisKey(moreEventSign.getDocumentId());
|
|
|
+ String redisData = redisServer.getData(redisKey, () -> null);
|
|
|
+ if (redisData != null) {
|
|
|
+ cancelSignature(redisData);
|
|
|
}
|
|
|
- redisServer.delData("emr-" + moreEventSign.getDocumentId());
|
|
|
+ redisServer.delData(redisKey);
|
|
|
String uuid = IdUtil.simpleUUID();
|
|
|
JSONObject data = getMoreEventSignData(moreEventSign, uuid);
|
|
|
- String execute = Forest.post(caData.getHBoardSign().getUrl() + "/mobile/hBoardSign").addBody(data).bodyType(ForestDataType.JSON).execute(String.class);
|
|
|
+ String execute = Forest.post(caData.getHBoardSign().getUrl() + "/mobile/hBoardSign")
|
|
|
+ .addBody(data)
|
|
|
+ .bodyType(ForestDataType.JSON)
|
|
|
+ .execute(String.class);
|
|
|
JSONObject rst = JSONUtil.parseObj(execute);
|
|
|
String msg = rst.getByPath("ret_msg", String.class);
|
|
|
String decode = URLUtil.decode(msg);
|
|
|
log.info("返回值:{},\n错误信息:{}", execute, decode);
|
|
|
if (rst.getInt("ret_code") == 0) {
|
|
|
- EmrCaSign newCaSign = EmrCaSign.builder()
|
|
|
- .documentId(moreEventSign.getDocumentId())
|
|
|
- .data(uuid)
|
|
|
- .build();
|
|
|
- if (emrCaSign == null) {
|
|
|
- emrCaSignDao.insert(newCaSign);
|
|
|
- } else {
|
|
|
- emrCaSignDao.updateById(newCaSign);
|
|
|
- }
|
|
|
+ redisServer.setData(redisKey, uuid, 30);
|
|
|
return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_EL_MESSAGE, "发送成功。");
|
|
|
} else {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请联系管理员" + decode);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private JSONObject getMoreEventSignData(MoreEventSign moreEventSign, String uuid) {
|
|
|
+ private JSONObject getMoreEventSignData(CaSignClass.MoreEventSign moreEventSign, String uuid) {
|
|
|
JSONObject ret = new JSONObject();
|
|
|
CaData.HBoardSign app = caData.getHBoardSign();
|
|
|
ret.set("api_key", app.getApiKey());
|
|
@@ -363,12 +319,12 @@ public class CaServer implements Assertion {
|
|
|
JSONObject data = new JSONObject();
|
|
|
data.set("document_no", uuid);
|
|
|
data.set("pdf", emrServer.getPdfBase(moreEventSign.getDocumentId()));
|
|
|
- data.set("return_url", URLUtil.encode(app.getReturnUrl() + "/" + moreEventSign.getDocumentId() + "/" + uuid));
|
|
|
+ data.set("return_url", URLUtil.encode(app.getReturnUrl() + "/" + moreEventSign.getDocumentId()));
|
|
|
|
|
|
JSONArray signature = new JSONArray();
|
|
|
|
|
|
for (int i = 0; i < moreEventSign.getData().size(); i++) {
|
|
|
- MoreEventSignData item = moreEventSign.getData().get(i);
|
|
|
+ CaSignClass.MoreEventSignData item = moreEventSign.getData().get(i);
|
|
|
JSONObject entries = new JSONObject();
|
|
|
entries.set("type", "keyword");
|
|
|
entries.set("sign_type", URLUtil.encode(item.getSignTypeName()));
|
|
@@ -392,15 +348,12 @@ public class CaServer implements Assertion {
|
|
|
.set("informed_tip", URLUtil.encode("签名意见"))
|
|
|
.set("informed_num", i + 1)
|
|
|
.set("informed_keyword", informed_keyword);
|
|
|
-
|
|
|
entries.set("informed_stamp", informed_stamp);
|
|
|
}
|
|
|
-
|
|
|
entries.set("user_info", user_info);
|
|
|
signature.put(entries);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 签署信息
|
|
|
data.set("signature", signature);
|
|
|
data.set("doctor_info", new JSONObject() {{
|
|
@@ -416,33 +369,14 @@ public class CaServer implements Assertion {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
- @Data
|
|
|
- public static class H5EventSign {
|
|
|
- private String documentId;
|
|
|
- private String content;
|
|
|
- private String idCard;
|
|
|
- private Integer signType;
|
|
|
- private Boolean clear = true;
|
|
|
- private String name;
|
|
|
- private String signOpinion;
|
|
|
- }
|
|
|
-
|
|
|
- @Data
|
|
|
- @Builder
|
|
|
- @AllArgsConstructor
|
|
|
- @NoArgsConstructor
|
|
|
- public static class H5Return {
|
|
|
- private String id;
|
|
|
- private String result;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* h5 签名返回一个http连接
|
|
|
*
|
|
|
* @param value
|
|
|
* @return
|
|
|
+ * @deprecated 没啥用
|
|
|
*/
|
|
|
- public ResultVo<H5Return> h5EventSign(H5EventSign value) {
|
|
|
+ public ResultVo<CaSignClass.H5Return> h5EventSign(CaSignClass.H5EventSign value) {
|
|
|
JSONObject ret = new JSONObject();
|
|
|
String uuid = IdUtil.simpleUUID();
|
|
|
CaData.HBoardSign app = caData.getHBoardSign();
|
|
@@ -463,7 +397,7 @@ public class CaServer implements Assertion {
|
|
|
.bodyType(ForestDataType.JSON)
|
|
|
.execute(String.class);
|
|
|
|
|
|
- return getStringResultVo(execute, uuid);
|
|
|
+ return getStringResultVo(execute, uuid, "");
|
|
|
}
|
|
|
|
|
|
@Getter
|
|
@@ -480,7 +414,6 @@ public class CaServer implements Assertion {
|
|
|
this.code = code;
|
|
|
this.name = name;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -489,25 +422,22 @@ public class CaServer implements Assertion {
|
|
|
* @param value
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultVo<H5Return> hBoardSignV2(H5EventSign value) {
|
|
|
+ public ResultVo<CaSignClass.H5Return> hBoardSignV2(CaSignClass.H5EventSign value) {
|
|
|
isNoll(value.getSignType(), "请选择和患者的关系");
|
|
|
isBlank(value.getIdCard(), "身份证不能为空。");
|
|
|
isBlank(value.getName(), "姓名不能为空。");
|
|
|
-
|
|
|
JSONObject ret = new JSONObject();
|
|
|
- String uuid = IdUtil.simpleUUID();
|
|
|
+ String caDocumentId = IdUtil.simpleUUID();
|
|
|
verifyMedicalRecordStatus(value.getDocumentId(), EmrSignType.QR);
|
|
|
- String idCard = idCardRsa.decryptStr(value.getIdCard(), KeyType.PrivateKey);
|
|
|
- if (value.getClear()) {
|
|
|
- redisServer.delData("emr-" + value.getDocumentId());
|
|
|
- emrCaSignDao.deleteById(value.getDocumentId());
|
|
|
- }
|
|
|
|
|
|
+ CaSignClass.H5EventSignRedis redisData = clearHBoardSignV2Data(value);
|
|
|
+
|
|
|
+ String idCard = idCardRsa.decryptStr(value.getIdCard(), KeyType.PrivateKey);
|
|
|
ret.set("api_key", caData.getHBoardSign().getApiKey());
|
|
|
ret.set("api_secret", caData.getHBoardSign().getApiSecret());
|
|
|
ret.set("data", new JSONObject() {{
|
|
|
- set("document_no", uuid);
|
|
|
- set("pdf", emrServer.getPdfBase(value.getDocumentId()));
|
|
|
+ set("document_no", caDocumentId);
|
|
|
+ set("pdf", redisData.getPdf());
|
|
|
set("sign_way", "face,hand_sign");
|
|
|
set("keyword", new JSONObject() {{
|
|
|
set("page", "0");
|
|
@@ -534,17 +464,44 @@ public class CaServer implements Assertion {
|
|
|
.addBody(ret)
|
|
|
.bodyType(ForestDataType.JSON)
|
|
|
.execute(String.class);
|
|
|
- return getStringResultVo(execute, uuid);
|
|
|
+
|
|
|
+ redisData.setUuid(value.getUuid());
|
|
|
+
|
|
|
+ redisServer.setData("ca-emr-" + value.getDocumentId(), redisData, 30);
|
|
|
+ return getStringResultVo(execute, caDocumentId, value.getUuid());
|
|
|
+ }
|
|
|
+
|
|
|
+ private CaSignClass.H5EventSignRedis clearHBoardSignV2Data(CaSignClass.H5EventSign value) {
|
|
|
+ CaSignClass.H5EventSignRedis redisData = new CaSignClass.H5EventSignRedis();
|
|
|
+ String redisKey = getRedisKey(value.getDocumentId());
|
|
|
+ // 如果 uuid 是空的就是第一次
|
|
|
+ if (StrUtil.isBlank(value.getUuid())) {
|
|
|
+ value.setUuid(IdUtil.simpleUUID());
|
|
|
+ redisServer.delData(redisKey);
|
|
|
+ redisData.setPdf(emrServer.getPdfBase(value.getDocumentId()));
|
|
|
+ } else {
|
|
|
+ redisData = redisServer.getData(redisKey);
|
|
|
+ if (redisData == null) {
|
|
|
+ throw new BizException(ExceptionEnum.LOGICAL_ERROR, "签名超时请重新签名。");
|
|
|
+ }
|
|
|
+ if (!redisData.getUuid().equals(value.getUuid())) {
|
|
|
+ throw new BizException(ExceptionEnum.LOGICAL_ERROR, "有其他人正在签署,本次签名失效。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return redisData;
|
|
|
}
|
|
|
|
|
|
@NotNull
|
|
|
- private ResultVo<H5Return> getStringResultVo(String execute, String id) {
|
|
|
+ private ResultVo<CaSignClass.H5Return> getStringResultVo(String execute,
|
|
|
+ String caDocumentId,
|
|
|
+ String uuid) {
|
|
|
JSONObject rst = JSONUtil.parseObj(execute);
|
|
|
String msg = URLUtil.decode(rst.getByPath("ret_msg", String.class));
|
|
|
if (0 == rst.getByPath("ret_code", Integer.class)) {
|
|
|
- H5Return build = H5Return.builder()
|
|
|
+ CaSignClass.H5Return build = CaSignClass.H5Return.builder()
|
|
|
.result(rst.getByPath("sign_url", String.class))
|
|
|
- .id(id)
|
|
|
+ .caDocumentId(caDocumentId)
|
|
|
+ .uuid(uuid)
|
|
|
.build();
|
|
|
return ResultVoUtil.success(build);
|
|
|
}
|
|
@@ -576,40 +533,34 @@ public class CaServer implements Assertion {
|
|
|
*
|
|
|
* @return 提示
|
|
|
*/
|
|
|
- public ResultVo<Boolean> scanCodeVerification(String id, String documentId) {
|
|
|
+ public ResultVo<Boolean> scanCodeVerification(String id, String documentId, String uuid) {
|
|
|
ResultVo<JSONObject> res = downloadSealV2(id, documentId);
|
|
|
if (!res.getCode().equals(ExceptionEnum.SUCCESS.getCode())) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, res.getMessage());
|
|
|
}
|
|
|
JSONObject rst = res.getData();
|
|
|
- redisServer.setData("emr-" + documentId, rst.getByPath("pdf", String.class), 60, TimeUnit.MINUTES);
|
|
|
+ String key = getRedisKey(documentId);
|
|
|
+ CaSignClass.H5EventSignRedis redisData = redisServer.getData(key);
|
|
|
+ if (redisData == null) {
|
|
|
+ throw new BizException(ExceptionEnum.LOGICAL_ERROR, "签名错误,文书不存在。");
|
|
|
+ }
|
|
|
|
|
|
+ if (!redisData.getUuid().equals(uuid)) {
|
|
|
+ throw new BizException(ExceptionEnum.LOGICAL_ERROR, "有其他人正在签署,本次签名失效。");
|
|
|
+ }
|
|
|
+
|
|
|
+ redisData.setPdf(rst.getByPath("pdf", String.class));
|
|
|
JSONObject saveData = new JSONObject();
|
|
|
saveData.set("hand_sign", rst.get("hand_sign"));
|
|
|
saveData.set("fingerprint", rst.get("hand_sign"));
|
|
|
saveData.set("informed_img", rst.get("hand_sign"));
|
|
|
saveData.set("face_photo", rst.get("hand_sign"));
|
|
|
saveData.set("biz_sn", id);
|
|
|
- JSONArray js = new JSONArray();
|
|
|
- boolean update = false;
|
|
|
- EmrCaSign emrCaSign = emrCaSignDao.selectById(documentId);
|
|
|
- if (emrCaSign != null) {
|
|
|
- js = JSONUtil.parseArray(emrCaSign.getData());
|
|
|
- update = true;
|
|
|
- } else {
|
|
|
- emrCaSign = EmrCaSign.builder()
|
|
|
- .documentId(documentId)
|
|
|
- .build();
|
|
|
- }
|
|
|
-
|
|
|
- js.put(saveData);
|
|
|
- emrCaSign.setData(js.toJSONString(0));
|
|
|
-
|
|
|
- if (update) {
|
|
|
- emrCaSignDao.updateById(emrCaSign);
|
|
|
- } else {
|
|
|
- emrCaSignDao.insert(emrCaSign);
|
|
|
+ if (null == redisData.getData()) {
|
|
|
+ redisData.setData(new ArrayList<>());
|
|
|
}
|
|
|
+ redisData.getData().add(saveData);
|
|
|
+ redisServer.setData(key, redisData, 30);
|
|
|
return ResultVoUtil.success(true);
|
|
|
}
|
|
|
|
|
@@ -617,8 +568,23 @@ public class CaServer implements Assertion {
|
|
|
* 扫码流程完成
|
|
|
*/
|
|
|
public void completeQrCode(String documentId) {
|
|
|
- // TODO 完成H5签名的时候,需要保存一下PDF
|
|
|
- EmrPatientData build = EmrPatientData.builder().emrDocumentId(documentId).signComplete(true).build();
|
|
|
+ EmrPatientData data = emrPatientDao.selectById(documentId);
|
|
|
+ CaSignClass.H5EventSignRedis redisServerData = redisServer.getData(getRedisKey(documentId));
|
|
|
+ CaSignClass.Upload upload = CaSignClass.Upload.builder()
|
|
|
+ .file(redisServerData.getPdf())
|
|
|
+ .fileName(documentId)
|
|
|
+ .patNo(data.getPatNo())
|
|
|
+ .times(data.getTimes())
|
|
|
+ .caData(JSONUtil.toJsonStr(redisServerData))
|
|
|
+ .build();
|
|
|
+
|
|
|
+ String path = uploadBase64(upload);
|
|
|
+ EmrPatientData build = EmrPatientData
|
|
|
+ .builder()
|
|
|
+ .emrDocumentId(documentId)
|
|
|
+ .signComplete(true)
|
|
|
+ .archivePath(path)
|
|
|
+ .build();
|
|
|
emrPatientDao.updateById(build);
|
|
|
}
|
|
|
|
|
@@ -637,25 +603,54 @@ public class CaServer implements Assertion {
|
|
|
.execute(JSONObject.class);
|
|
|
}
|
|
|
|
|
|
- public JSONObject hBoardSignReturnUrl(String document, String bizSn, JSONObject data) {
|
|
|
+ /**
|
|
|
+ * 签名回调
|
|
|
+ *
|
|
|
+ * @param document 文档id
|
|
|
+ * @param data 签名数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject hBoardSignReturnUrl(String document, JSONObject data) {
|
|
|
// TODO 完成一定手写板签名的时候,需要保存一下PDF
|
|
|
- log.info("回调:{},biz:{},数据:{}", document, bizSn, data);
|
|
|
-//
|
|
|
-// String url = "D:\\.a1.world\\1.txt";
|
|
|
-// String s = FileUtil.readString(url, StandardCharsets.UTF_8);
|
|
|
-// JSONObject entries = JSONUtil.parseObj(s);
|
|
|
-// String handSign = entries.getStr("pdf");
|
|
|
-// byte[] decode = Base64.decode(handSign);
|
|
|
-// FileUtil.writeBytes(decode, "D:\\.a1.world\\1.pdf");
|
|
|
-// log.info("数据:{}\ndecode:{}", s, decode);
|
|
|
+ log.info("回调:{},数据:{}", document, data);
|
|
|
+ EmrPatientData emrData = emrPatientDao.selectById(document);
|
|
|
+ String redisKey = getRedisKey(document);
|
|
|
+ String redisData = redisServer.getData(redisKey, () -> null);
|
|
|
+ if (emrData == null || redisData == null) {
|
|
|
+ return R(-1, "病历文档不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject signData = appDownload(redisData);
|
|
|
+
|
|
|
+ CaSignClass.Upload build = CaSignClass.Upload
|
|
|
+ .builder()
|
|
|
+ .patNo(emrData.getPatNo())
|
|
|
+ .times(emrData.getTimes())
|
|
|
+ .file(signData.getStr("pdf"))
|
|
|
+ .fileName(document)
|
|
|
+ .caData(signData.getStr("signed"))
|
|
|
+ .build();
|
|
|
+
|
|
|
+ String path = uploadBase64(build);
|
|
|
+
|
|
|
+ EmrPatientData update = EmrPatientData.builder()
|
|
|
+ .emrDocumentId(document)
|
|
|
+ .signComplete(true)
|
|
|
+ .archivePath(path)
|
|
|
+ .build();
|
|
|
+ redisServer.delData(redisKey);
|
|
|
+ emrPatientDao.updateById(update);
|
|
|
+ return R(1, "success");
|
|
|
+ }
|
|
|
|
|
|
+ private JSONObject R(Integer code, String msg) {
|
|
|
return new JSONObject() {{
|
|
|
- set("ret_code", 1);
|
|
|
- set("res_msg", "success");
|
|
|
+ set("ret_code", code);
|
|
|
+ set("res_msg", msg);
|
|
|
}};
|
|
|
}
|
|
|
|
|
|
- public ResultVo<String> appDownload(String documentId, String bizSn) {
|
|
|
+ public JSONObject appDownload(String bizSn) {
|
|
|
JSONObject data = new JSONObject() {{
|
|
|
set("api_key", caData.getHBoardSign().getApiKey());
|
|
|
set("api_secret", caData.getHBoardSign().getApiSecret());
|
|
@@ -671,10 +666,34 @@ public class CaServer implements Assertion {
|
|
|
.execute(JSONObject.class);
|
|
|
|
|
|
execute.set("ret_msg", URLUtil.decode(execute.getStr("ret_msg")));
|
|
|
-
|
|
|
log.info("返回:{}", execute);
|
|
|
|
|
|
- return ResultVoUtil.success();
|
|
|
+ if (execute.getInt("code") != 0) {
|
|
|
+ throw new BizException(ExceptionEnum.LOGICAL_ERROR, execute.getStr("ret_msg"));
|
|
|
+ }
|
|
|
+
|
|
|
+ return execute;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String uploadBase64(CaSignClass.Upload upload) {
|
|
|
+ byte[] file = Base64.decode(upload.getFile());
|
|
|
+
|
|
|
+ String tmpPath = "/" + upload.getPatNo()
|
|
|
+ + "/" + upload.getTimes()
|
|
|
+ + "/" + upload.getFileName();
|
|
|
+
|
|
|
+ String pdfPath = tmpPath + ".pdf";
|
|
|
+
|
|
|
+ String caPath = "/" + upload.getPatNo()
|
|
|
+ + "/" + upload.getTimes()
|
|
|
+ + "/ca/" + upload.getFileName()
|
|
|
+ + ".txt";
|
|
|
+
|
|
|
+ // 写入CA数据
|
|
|
+ FileUtil.writeString(upload.getCaData(), archive.getPath() + caPath, StandardCharsets.UTF_8);
|
|
|
+ // 写入pdf
|
|
|
+ FileUtil.writeBytes(file, archive.getPath() + pdfPath);
|
|
|
+ return archive.getUrlPrefix() + pdfPath;
|
|
|
}
|
|
|
|
|
|
|