Commit abb93711deae95f95152fb93cdd36bcb547e4510

Authored by yangfei
1 parent 168e4afe24

增值服务同步

Showing 3 changed files with 141 additions and 133 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/PatientServiceController.java View file @ abb9371
... ... @@ -67,16 +67,23 @@
67 67 @RequestMapping(value = "/patSer", method = RequestMethod.POST)
68 68 public BaseResponse addOrUpdatePatientService(PatientService ps, HttpServletRequest request) {
69 69 LoginContext loginState = (LoginContext) request.getAttribute("loginContext");
70   -
71   - if (StringUtils.isEmpty(ps.getId())) {
72   - BaseResponse baseResponse = validatePatient(ps);
73   - if(baseResponse.getErrorcode()!=ErrorCodeConstants.SUCCESS){
74   - return baseResponse;
  70 + try {
  71 + if (StringUtils.isEmpty(ps.getId())) {
  72 + BaseResponse baseResponse = validatePatient(ps);
  73 + if (baseResponse.getErrorcode() != ErrorCodeConstants.SUCCESS) {
  74 + return baseResponse;
  75 + }
  76 + return patientServiceFacade.addPatientService(ps, loginState.getId());
  77 + } else {
  78 + return patientServiceFacade.updatePatientService(ps, loginState.getId());
75 79 }
76   - return patientServiceFacade.addPatientService(ps, loginState.getId());
77   - } else {
78   - return patientServiceFacade.updatePatientService(ps, loginState.getId());
  80 + }catch (Exception e){
  81 + BaseResponse baseResponse = new BaseResponse();
  82 + baseResponse.setErrorcode(ErrorCodeConstants.SYSTEM_ERROR);
  83 + baseResponse.setErrormsg(ErrorCodeConstants.SYSTEM_ERROR_DESCRIPTION);
  84 + return baseResponse;
79 85 }
  86 +
80 87 }
81 88  
82 89 /**
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientServiceFacade.java View file @ abb9371
1 1 package com.lyms.platform.operate.web.facade;
2 2  
3 3 import com.alibaba.fastjson.JSONObject;
4   -import com.lyms.platform.biz.RemoteUrlEnum;
5 4 import com.lyms.platform.biz.service.AntExRecordService;
6 5 import com.lyms.platform.biz.service.AntenatalExaminationService;
7 6 import com.lyms.platform.biz.service.CommonService;
8 7  
... ... @@ -14,10 +13,10 @@
14 13 import com.lyms.platform.common.result.BaseResponse;
15 14 import com.lyms.platform.common.utils.Config;
16 15 import com.lyms.platform.common.utils.DateUtil;
17   -import com.lyms.platform.common.utils.HttpClientUtil;
18 16 import com.lyms.platform.common.utils.StringUtils;
19 17 import com.lyms.platform.operate.web.request.BasePageQueryRequest;
20 18 import com.lyms.platform.operate.web.result.PatientSerResult;
  19 +import com.lyms.platform.permission.model.Organization;
21 20 import com.lyms.platform.permission.model.PatientService;
22 21 import com.lyms.platform.permission.model.PatientServiceQuery;
23 22 import com.lyms.platform.permission.model.Users;
... ... @@ -126,7 +125,7 @@
126 125 * @param id
127 126 * @return
128 127 */
129   - public BaseResponse addPatientService(PatientService ps, Integer id) {
  128 + public BaseResponse addPatientService(PatientService ps, Integer id) throws Exception {
130 129 //根据用户id获取医院ID
131 130 String hospitalId = autoMatchFacade.getHospitalId(id);
132 131 String[] serTypes = ps.getSerTypes().split(",");
... ... @@ -149,6 +148,7 @@
149 148 ps.setPid(patients.getPid());
150 149 }
151 150 ps.setId(UUID.randomUUID().toString().replace("-", ""));
  151 +
152 152 ps.setHospitalId(hospitalId);
153 153 //默认开通状态
154 154 ps.setSerStatus(PatientSerEnums.SerStatusEnums.kt.getId());
... ... @@ -173,8 +173,6 @@
173 173 patientServiceList.add(ps);
174 174 }
175 175  
176   - // synPatientService(patientServiceList.toArray(new PatientService[patientServiceList.size()]));
177   -
178 176 BaseResponse baseResponse = new BaseResponse();
179 177 baseResponse.setObject(ps.getId());
180 178 baseResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
... ... @@ -207,7 +205,6 @@
207 205  
208 206 PatientService after = patientServiceService.getPatientService(ps.getId());
209 207 operateLogFacade.addModifyOptLog(id, Integer.valueOf(hospitalId), before, after, OptActionEnums.UPDATE.getId(), "修复服务");
210   - // synPatientService(ps);
211 208 BaseResponse baseResponse = new BaseResponse();
212 209 baseResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
213 210 baseResponse.setErrormsg("成功");
... ... @@ -243,7 +240,24 @@
243 240 //高危等级颜色
244 241 result.setrLevel(commonService.findRiskLevel(patients.getRiskLevelId()));
245 242 }
246   -
  243 + if (StringUtils.isNotEmpty(patients.getHospitalId())) {//查询医院名称
  244 + //判断ID是否存在
  245 + Organization organization = organizationService.getOrganization(Integer.parseInt(patients.getHospitalId()));
  246 + if (organization != null) {
  247 + //设置医院名称
  248 + result.setHospitalName(organization.getName());
  249 + }
  250 + }
  251 + if (StringUtils.isNotEmpty(ps.getUpdateUser())) {
  252 + try {
  253 + Users users = usersService.getUsers(Integer.parseInt(ps.getUpdateUser()));
  254 + if (users != null) {
  255 + result.setUpdateUser(users.getName());
  256 + }
  257 + } catch (Exception e) {
  258 + result.setSerDoctStr("产检医生");
  259 + }
  260 + }
247 261 result.setParentid(ps.getParentid());
248 262 result.setCreateDate(DateUtil.getyyyy_MM_dd(ps.getCreateDate()));
249 263 result.setPid(ps.getPid());
250 264  
... ... @@ -259,14 +273,15 @@
259 273 result.setSerCode(ps.getSerCode());
260 274 result.setCreateUser(ps.getCreateUser());
261 275 result.setUpdateDate(DateUtil.getyyyy_MM_dd(ps.getUpdateDate()));
262   -
263   - try {
264   - Users users = usersService.getUsers(Integer.parseInt(ps.getSerDoct()));
265   - if (users != null) {
266   - result.setSerDoctStr(users.getName());
  276 + if (ps.getSerDoct() != null) {
  277 + try {
  278 + Users users = usersService.getUsers(Integer.parseInt(ps.getSerDoct()));
  279 + if (users != null) {
  280 + result.setSerDoctStr(users.getName());
  281 + }
  282 + } catch (Exception e) {
  283 + result.setSerDoctStr("产检医生");
267 284 }
268   - }catch (Exception e){
269   - result.setSerDoctStr("产检医生");
270 285 }
271 286  
272 287 if (StringUtils.isNotEmpty(ps.getCreateUser())) {
273 288  
... ... @@ -275,10 +290,10 @@
275 290 if (users != null) {
276 291 result.setCreateUserStr(users.getName());
277 292 }
278   - }catch (Exception e){
  293 + } catch (Exception e) {
279 294 result.setCreateUserStr("产检医生");
280 295 }
281   - }else{
  296 + } else {
282 297 result.setCreateUserStr("小程序开通");
283 298 }
284 299 result.setBackDate(DateUtil.getyyyy_MM_dd(ps.getBackDate()));
285 300  
286 301  
... ... @@ -395,52 +410,8 @@
395 410 return baseResponse;
396 411 }
397 412  
398   - /**
399   - * 小程序调用:获取已经领取设备,但是还未同步的数据
400   - */
401   - public BaseResponse getAlreaRece(){
402   - PatientServiceQuery patientQuery = new PatientServiceQuery();
403   - //待同步默认不需要同步、1-待同步、2-已同步
404   - patientQuery.setSynStatus(1);
405   - List<PatientService> patientServices = patientServiceService.queryPatientService(patientQuery);
406   - List<String> orders = new ArrayList<>();
407   - for(PatientService ps :patientServices){
408   - orders.add(ps.getOrderId());
409   - }
410 413  
411   - BaseResponse baseResponse = new BaseResponse();
412   - baseResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
413   - baseResponse.setObject(orders);
414   - baseResponse.setErrormsg("成功");
415   - return baseResponse;
416   - }
417   -
418 414 /**
419   - * 小程序调用:修改同步状态为已同步
420   - *
421   - * @param orderIds 订单号集合
422   - * @return
423   - */
424   - public BaseResponse receivePatientService(String orderIds) {
425   - PatientServiceQuery patientQuery = new PatientServiceQuery();
426   - patientQuery.setSql("and order_id in ("+orderIds+")");
427   -
428   - List<PatientService> patientServices = patientServiceService.queryPatientService(patientQuery);
429   - if(CollectionUtils.isNotEmpty(patientServices)){
430   - for(PatientService ps :patientServices){
431   - ps.setSynStatus(2);
432   - patientServiceService.updatePatientService(ps);
433   - }
434   - }
435   -
436   - BaseResponse baseResponse = new BaseResponse();
437   - baseResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
438   - baseResponse.setErrormsg("成功");
439   - return baseResponse;
440   - }
441   -
442   -
443   - /**
444 415 * 修改状态为领取
445 416 *
446 417 * @param psId 服务记录Id
... ... @@ -476,7 +447,6 @@
476 447 PatientService before = patientServiceService.getPatientService(ps.getId());
477 448  
478 449 patientServiceService.updatePatientService(ps);
479   -// synReceiveData(ps.getOrderId());
480 450 operateLogFacade.addModifyOptLog(id, Integer.valueOf(hospitalId), before, ps, OptActionEnums.UPDATE.getId(), "领取设备状态修改");
481 451  
482 452 BaseResponse baseResponse = new BaseResponse();
483 453  
484 454  
485 455  
486 456  
487 457  
488 458  
489 459  
490 460  
491 461  
... ... @@ -486,80 +456,110 @@
486 456 }
487 457  
488 458 /**
489   - * 新增或修改同步到小程序
  459 + * 小程序调用:获取已经领取设备,但是还未同步的数据
  460 + */
  461 + public BaseResponse getAlreaRece() {
  462 + PatientServiceQuery patientQuery = new PatientServiceQuery();
  463 + //待同步默认不需要同步、1-待同步、2-已同步
  464 + patientQuery.setSynStatus(1);
  465 + patientQuery.setSql("and order_id is not null");
  466 + List<PatientService> patientServices = patientServiceService.queryPatientService(patientQuery);
  467 + List<String> orders = new ArrayList<>();
  468 + for (PatientService ps : patientServices) {
  469 + orders.add(ps.getOrderId());
  470 + }
  471 +
  472 + BaseResponse baseResponse = new BaseResponse();
  473 + baseResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
  474 + baseResponse.setObject(orders);
  475 + baseResponse.setErrormsg("成功");
  476 + return baseResponse;
  477 + }
  478 +
  479 + /**
  480 + * 小程序调用:修改领取设备同步状态为已同步
490 481 *
491   - * @param patientServices 数据
  482 + * @param orderIds 订单号集合
492 483 * @return
493 484 */
494   - public boolean synPatientService(final PatientService... patientServices) {
  485 + public BaseResponse receivePatientService(String orderIds) {
  486 + PatientServiceQuery patientQuery = new PatientServiceQuery();
  487 + patientQuery.setSql("and order_id in (" + orderIds + ")");
  488 +
  489 + List<PatientService> patientServices = patientServiceService.queryPatientService(patientQuery);
  490 + if (CollectionUtils.isNotEmpty(patientServices)) {
  491 + for (PatientService ps : patientServices) {
  492 + ps.setSynStatus(2);
  493 + patientServiceService.updatePatientService(ps);
  494 + }
  495 + }
  496 +
  497 + BaseResponse baseResponse = new BaseResponse();
  498 + baseResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
  499 + baseResponse.setErrormsg("成功");
  500 + return baseResponse;
  501 + }
  502 +
  503 + /**
  504 + * 小程序调用:新增或修改的服务同步到小程序
  505 + *
  506 + * @return
  507 + */
  508 + public BaseResponse synPatientService() {
  509 + BaseResponse baseResponse = new BaseResponse();
495 510 try {
496   - new Thread(new Runnable() {
497   - @Override
498   - public void run() {
499   - Map<String, String> params = new HashMap<>();
500   - JSONArray jsonArray = new JSONArray();
501   - for (PatientService ps : patientServices) {
502   - JSONObject jsonObject = new JSONObject();
503   - jsonObject.put("parentid", ps.getParentid());
504   - jsonObject.put("pid", ps.getPid());
505   - jsonObject.put("serType", ps.getSerType());
506   - jsonObject.put("serDoct", ps.getSerDoct());
507   - jsonObject.put("serStatus", ps.getSerStatus());
508   - jsonObject.put("hospitalId", ps.getHospitalId());
509   - jsonObject.put("createDate", DateUtil.getyyyy_MM_dd_hms(ps.getCreateDate()));
510   - jsonArray.add(jsonObject);
511   - }
512   - params.put("data", jsonArray.toString());
513   - System.out.println("增值服务数据同步参数:" + jsonArray.toString());
514   - String rest = HttpClientUtil.doPost(patSer_sync_url + RemoteUrlEnum.RECEIVE_PATSER_SYNC_URL.getUrl(), params, "utf-8");
515   - System.out.println("增值服务数据同步结果:" + rest);
516   - }
517   - }).start();
518   - } catch (Exception e) {
519   - e.printStackTrace();
520   - try {
521   - //休眠10分钟继续调用同步
522   - Thread.sleep(600000);
523   - } catch (InterruptedException e1) {
524   - e1.printStackTrace();
  511 + PatientServiceQuery patientQuery = new PatientServiceQuery();
  512 + patientQuery.setSql("and order_id is null");
  513 + patientQuery.setSynStatus(1);
  514 + List<PatientService> patientServices = patientServiceService.queryPatientService(patientQuery);
  515 + Map<String, String> params = new HashMap<>();
  516 + JSONArray jsonArray = new JSONArray();
  517 + for (PatientService ps : patientServices) {
  518 + JSONObject jsonObject = new JSONObject();
  519 + jsonObject.put("id", ps.getId());
  520 + jsonObject.put("parentid", ps.getParentid());
  521 + jsonObject.put("pid", ps.getPid());
  522 + jsonObject.put("serType", ps.getSerType());
  523 + jsonObject.put("serDoct", ps.getSerDoct());
  524 + jsonObject.put("serStatus", ps.getSerStatus());
  525 + jsonObject.put("hospitalId", ps.getHospitalId());
  526 + jsonObject.put("createDate", DateUtil.getyyyy_MM_dd_hms(ps.getCreateDate()));
  527 + jsonArray.add(jsonObject);
525 528 }
526   - //迭代继续同步
527   - // synPatientService(patientServices);
  529 + params.put("data", jsonArray.toString());
  530 +
  531 + baseResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
  532 + baseResponse.setErrormsg("成功");
  533 + return baseResponse;
  534 + } catch (Exception e){
  535 + baseResponse.setErrorcode(ErrorCodeConstants.SYSTEM_ERROR);
  536 + baseResponse.setErrormsg(e.getMessage());
  537 + return baseResponse;
528 538 }
529   - return true;
530 539 }
531 540  
532 541 /**
533   - * 领取结果同步到小程序
  542 + * 小程序调用:修改新增、修改服务同步状态为已同步
534 543 *
535   - * @param orderId
  544 + * @param ids id集合
536 545 */
537   - public boolean synReceiveData(final String orderId) {
538   - /* try {
539   - new Thread(new Runnable() {
540   - @Override
541   - public void run() {
542   - Map<String, String> params = new HashMap<>();
543   - JSONObject jsonObject = new JSONObject();
544   - jsonObject.put("orderId", orderId);
545   - params.put("data", jsonObject.toString());
546   - params.put("action", "verCodeHandler");
547   - System.out.println("领取设备请求参数:" + jsonObject.toString());
548   - String rest = HttpClientUtil.doPost(patSer_sync_url + RemoteUrlEnum.RECEIVE_PATSER_SYNC_URL.getUrl(), params, "utf-8");
549   - System.out.println("领取设备结果:" + rest);
550   - }
551   - }).start();
552   - } catch (Exception e) {
553   - e.printStackTrace();
554   - try {
555   - //休眠10分钟继续调用同步
556   - Thread.sleep(600000);
557   - } catch (InterruptedException e1) {
558   - e1.printStackTrace();
  546 + public BaseResponse synReceiveData(String ids) {
  547 +
  548 + PatientServiceQuery patientQuery = new PatientServiceQuery();
  549 + patientQuery.setSql("and id in (" + ids + ")");
  550 +
  551 + List<PatientService> patientServices = patientServiceService.queryPatientService(patientQuery);
  552 + if (CollectionUtils.isNotEmpty(patientServices)) {
  553 + for (PatientService ps : patientServices) {
  554 + ps.setSynStatus(2);
  555 + patientServiceService.updatePatientService(ps);
559 556 }
560   - synReceiveData(orderId);
561   - }*/
562   - return true;
  557 + }
  558 +
  559 + BaseResponse baseResponse = new BaseResponse();
  560 + baseResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
  561 + baseResponse.setErrormsg("成功");
  562 + return baseResponse;
563 563 }
564 564 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/result/PatientSerResult.java View file @ abb9371
... ... @@ -61,11 +61,11 @@
61 61 */
62 62 private String createUser;
63 63 /**
64   - * 修改时间
  64 + * 操作时间
65 65 */
66 66 private String updateDate;
67 67 /**
68   - * 修改
  68 + * 操作
69 69 */
70 70 private String updateUser;
71 71 /**
... ... @@ -76,6 +76,7 @@
76 76 * 开通医生名称
77 77 */
78 78 private String createUserStr;
  79 +
79 80 /**
80 81 * 服务状态(1-开通、2-退订、3-过期、4-暂停)
81 82 */