|
@@ -17,11 +17,13 @@ import thyyxxk.wxservice_server.entity.analyzeidcard.UploadIdCardParam;
|
|
|
import thyyxxk.wxservice_server.entity.hrgresponse.CreateCardResponse;
|
|
|
import thyyxxk.wxservice_server.entity.patientcards.BindPatientIdParam;
|
|
|
import thyyxxk.wxservice_server.entity.patientcards.CreatCardParam;
|
|
|
+import thyyxxk.wxservice_server.entity.wxapi.PushMessageParam;
|
|
|
import thyyxxk.wxservice_server.utils.DateUtil;
|
|
|
import thyyxxk.wxservice_server.utils.ResultVoUtil;
|
|
|
import thyyxxk.wxservice_server.utils.StringUtil;
|
|
|
|
|
|
import java.util.Base64;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -37,14 +39,16 @@ public class IdCardAnalyzeService {
|
|
|
|
|
|
private final IdCardAnalyzeDao dao;
|
|
|
private final PatientCardsDao cardsDao;
|
|
|
+ private final PushWxMessageService pushWxMessageService;
|
|
|
|
|
|
@Value("${hrgApiUrl}")
|
|
|
private String hrgApiUrl;
|
|
|
|
|
|
@Autowired
|
|
|
- public IdCardAnalyzeService(IdCardAnalyzeDao dao, PatientCardsDao cardsDao) {
|
|
|
+ public IdCardAnalyzeService(IdCardAnalyzeDao dao, PatientCardsDao cardsDao, PushWxMessageService pushWxMessageService) {
|
|
|
this.dao = dao;
|
|
|
this.cardsDao = cardsDao;
|
|
|
+ this.pushWxMessageService = pushWxMessageService;
|
|
|
}
|
|
|
|
|
|
public ResultVo<IdCardAnalyzeResult> readImage(UploadIdCardParam param) {
|
|
@@ -90,7 +94,7 @@ public class IdCardAnalyzeService {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请上传正确的身份证图像!");
|
|
|
}
|
|
|
|
|
|
- public ResultVo<Object> readInput(IdCardAnalyzeResult param) throws Exception {
|
|
|
+ public ResultVo<HashMap<String, Object>> readInput(IdCardAnalyzeResult param) throws Exception {
|
|
|
if (StringUtil.isBlank(param.getSocialNo())) {
|
|
|
String birth = DateUtil.matchDate(param.getBirthday(), "yyyyMMdd");
|
|
|
if (null == birth) {
|
|
@@ -98,6 +102,33 @@ public class IdCardAnalyzeService {
|
|
|
}
|
|
|
param.setBirthday(birth);
|
|
|
}
|
|
|
+ BindPatientIdParam toBeBound = new BindPatientIdParam();
|
|
|
+ toBeBound.setRelation(param.getRelation());
|
|
|
+ toBeBound.setName(param.getName());
|
|
|
+ toBeBound.setSocialNo(param.getSocialNo());
|
|
|
+ toBeBound.setPhone(param.getPhone());
|
|
|
+ toBeBound.setProvince(param.getProvince());
|
|
|
+ toBeBound.setCity(param.getCity());
|
|
|
+ toBeBound.setDistrict(param.getDistrict());
|
|
|
+ toBeBound.setStreet(param.getStreet());
|
|
|
+ toBeBound.setOpenId(param.getOpenId());
|
|
|
+ toBeBound.setGuardName(param.getGuardName());
|
|
|
+ toBeBound.setGuardIdNo(param.getGuardIdNo());
|
|
|
+ toBeBound.setIsDefault(param.getRelation() == 1 ? 1 :0);
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
+ com.alibaba.fastjson.JSONObject obj = new com.alibaba.fastjson.JSONObject();
|
|
|
+ obj.put("patIdType", "11");
|
|
|
+ obj.put("patIdNo", param.getSocialNo());
|
|
|
+ String result = template.postForObject(hrgApiUrl + "/queryPatientInfo", obj, String.class);
|
|
|
+ log.info("在绑卡前查询患者信息:\n参数:{}\n结果:{}", obj, result);
|
|
|
+ if (null != result) {
|
|
|
+ com.alibaba.fastjson.JSONObject resobj = com.alibaba.fastjson.JSONObject.parseObject(result);
|
|
|
+ if (resobj.getInteger("resultCode") == 0) {
|
|
|
+ toBeBound.setPatientId(resobj.getString("patHisNo"));
|
|
|
+ toBeBound.setIcCardNo(resobj.getString("patCardNo"));
|
|
|
+ return bindExistCard(toBeBound);
|
|
|
+ }
|
|
|
+ }
|
|
|
CreatCardParam card = new CreatCardParam();
|
|
|
card.setPatName(param.getName());
|
|
|
card.setPatIdType(1);
|
|
@@ -118,7 +149,6 @@ public class IdCardAnalyzeService {
|
|
|
String cityName = dao.selectRegionName(param.getCity());
|
|
|
String districtName = dao.selectRegionName(param.getDistrict());
|
|
|
card.setPatAddress(provinceName + cityName + districtName + param.getStreet());
|
|
|
- RestTemplate template = new RestTemplate();
|
|
|
CreateCardResponse hrgResponse = template.postForObject(hrgApiUrl + "/savePatientInfo", card, CreateCardResponse.class);
|
|
|
log.info("首诊患者建档:\n参数:{},\n结果:{}", card, hrgResponse);
|
|
|
if (null == hrgResponse) {
|
|
@@ -127,29 +157,9 @@ public class IdCardAnalyzeService {
|
|
|
if (hrgResponse.getResultCode() == -1) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, hrgResponse.getResultMessage());
|
|
|
}
|
|
|
- BindPatientIdParam toBeBound = new BindPatientIdParam();
|
|
|
- List<BindPatientIdParam> boundCards = cardsDao.getBindPatientCard(param.getOpenId());
|
|
|
- if (null == boundCards || boundCards.isEmpty()) {
|
|
|
- toBeBound.setIsDefault(1);
|
|
|
- toBeBound.setRelation(1);
|
|
|
- } else {
|
|
|
- toBeBound.setIsDefault(0);
|
|
|
- toBeBound.setRelation(2);
|
|
|
- }
|
|
|
- toBeBound.setName(param.getName());
|
|
|
toBeBound.setPatientId(hrgResponse.getData());
|
|
|
- toBeBound.setSocialNo(param.getSocialNo());
|
|
|
- toBeBound.setPhone(param.getPhone());
|
|
|
- toBeBound.setProvince(param.getProvince());
|
|
|
- toBeBound.setCity(param.getCity());
|
|
|
- toBeBound.setDistrict(param.getDistrict());
|
|
|
- toBeBound.setStreet(param.getStreet());
|
|
|
- toBeBound.setOpenId(param.getOpenId());
|
|
|
toBeBound.setIcCardNo(toBeBound.getPatientId());
|
|
|
- toBeBound.setGuardName(param.getGuardName());
|
|
|
- toBeBound.setGuardIdNo(param.getGuardIdNo());
|
|
|
- cardsDao.bindPatientCard(toBeBound);
|
|
|
- return ResultVoUtil.success(hrgResponse.getData());
|
|
|
+ return bindExistCard(toBeBound);
|
|
|
}
|
|
|
|
|
|
private Integer calculatePatType(Integer age) {
|
|
@@ -158,4 +168,32 @@ public class IdCardAnalyzeService {
|
|
|
}
|
|
|
return age > 12 ? 1 : 2;
|
|
|
}
|
|
|
+
|
|
|
+ private ResultVo<HashMap<String, Object>> bindExistCard(BindPatientIdParam temp) {
|
|
|
+ HashMap<String, Object> map = new HashMap<>(Constants.Capacity.TWO);
|
|
|
+ final int count = cardsDao.isThisCardBindBefore(temp.getPatientId(), temp.getOpenId());
|
|
|
+ if (count > 0) {
|
|
|
+ cardsDao.bindPatientCardAgain(temp);
|
|
|
+ } else {
|
|
|
+ cardsDao.bindPatientCard(temp);
|
|
|
+ }
|
|
|
+ map.put("code", 0);
|
|
|
+ map.put("cards", cardsDao.getBindPatientCard(temp.getOpenId()));
|
|
|
+ log.info("绑定就诊卡成功:{}", temp);
|
|
|
+ String msgContent = "{\"touser\":\"\",\"data\":" +
|
|
|
+ "{\"keyword3\":{\"color\":\"#173177\",\"value\":\"" + temp.getIcCardNo() + "\"}," +
|
|
|
+ "\"keyword4\":{\"color\":\"#173177\",\"value\":\"" +
|
|
|
+ DateUtil.formatDatetime(new Date(), "yyyy-MM-dd HH:mm:ss") + "\"}," +
|
|
|
+ "\"keyword1\":{\"color\":\"#173177\",\"value\":\"" + temp.getName() + "\"}," +
|
|
|
+ "\"keyword2\":{\"color\":\"#173177\",\"value\":\"门诊就诊卡\"}," +
|
|
|
+ "\"remark\":{\"color\":\"#FF0000\",\"value\":\"感谢您的使用,祝您健康!\"}," +
|
|
|
+ "\"first\":{\"color\":\"#FF0000\",\"value\":\"您好,您已成功绑定就诊卡!\"}}," +
|
|
|
+ "\"template_id\":\"3bXASQD7J9t8qkJ1x-zIrutOCIadP9neI-dXQOBIQQk\"," +
|
|
|
+ "\"url\":\"\"}";
|
|
|
+ PushMessageParam pojo = new PushMessageParam();
|
|
|
+ pojo.setCardNo(temp.getIcCardNo());
|
|
|
+ pojo.setMsgContext(com.alibaba.fastjson.JSONObject.parseObject(msgContent));
|
|
|
+ pushWxMessageService.pushMessage(pojo);
|
|
|
+ return ResultVoUtil.success(map);
|
|
|
+ }
|
|
|
}
|