PrescribeController.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package com.fs.app.controller;
  2. import cn.hutool.json.JSONUtil;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.fs.app.annotation.Login;
  6. import com.fs.app.vo.PrescribeV2VO;
  7. import com.fs.common.core.domain.R;
  8. import com.fs.common.event.TemplateBean;
  9. import com.fs.common.event.TemplateEvent;
  10. import com.fs.common.event.TemplateListenEnum;
  11. import com.fs.common.utils.ParseUtils;
  12. import com.fs.store.domain.FsStoreOrder;
  13. import com.fs.wx.pay.config.WxPayProperties;
  14. import com.fs.store.domain.FsPrescribe;
  15. import com.fs.store.param.*;
  16. import com.fs.store.service.IFsPrescribeService;
  17. import com.fs.store.service.IFsStoreOrderItemService;
  18. import com.fs.store.service.IFsStoreOrderService;
  19. import com.fs.store.vo.FsPrescribeVO;
  20. import com.fs.store.vo.PrescribeVO;
  21. import com.github.binarywang.wxpay.service.WxPayService;
  22. import com.github.pagehelper.PageHelper;
  23. import com.github.pagehelper.PageInfo;
  24. import io.swagger.annotations.Api;
  25. import io.swagger.annotations.ApiOperation;
  26. import lombok.extern.slf4j.Slf4j;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.context.ApplicationEventPublisher;
  29. import org.springframework.validation.annotation.Validated;
  30. import org.springframework.web.bind.annotation.*;
  31. import javax.servlet.http.HttpServletRequest;
  32. import java.util.Date;
  33. import java.util.List;
  34. @Slf4j
  35. @Api("处方接口")
  36. @RestController
  37. @RequestMapping(value="/app/prescribe")
  38. public class PrescribeController extends AppBaseController {
  39. @Autowired
  40. private WxPayProperties wxPayProperties;
  41. @Autowired
  42. private WxPayService wxPayService;
  43. @Autowired
  44. private IFsStoreOrderService orderService;
  45. @Autowired
  46. private ApplicationEventPublisher publisher;
  47. @Autowired
  48. private IFsStoreOrderItemService itemService;
  49. @Autowired
  50. private IFsPrescribeService prescribeService;
  51. @Login
  52. @ApiOperation("获取我的处方列表")
  53. @GetMapping("/getMyPrescribeList")
  54. public R getMyPrescribeList(FsPrescribeQueryParam param, HttpServletRequest request){
  55. PageHelper.startPage(param.getPage(), param.getPageSize());
  56. param.setUserId(Long.parseLong(getUserId()));
  57. List<FsPrescribeVO> list=prescribeService.selectFsPrescribeListQuery(param);
  58. for(FsPrescribeVO vo : list){
  59. vo.setUserPhone(ParseUtils.parsePhone(vo.getUserPhone()));
  60. vo.setPatientTel(ParseUtils.parsePhone(vo.getPatientTel()));
  61. }
  62. PageInfo<FsPrescribeVO> listPageInfo=new PageInfo<>(list);
  63. return R.ok().put("data",listPageInfo);
  64. }
  65. @Login
  66. @ApiOperation("开处方")
  67. @PostMapping("/doPrescribe")
  68. public R doPrescribe(@Validated @RequestBody FsPrescribeParam param, HttpServletRequest request){
  69. return prescribeService.doPrescribe(Long.parseLong(getUserId()),param);
  70. }
  71. @ApiOperation("通知地址")
  72. @PostMapping(value="/presribeNotify")
  73. public String presribeNotify(HttpServletRequest request,@RequestBody String jsonBody) throws Exception
  74. {
  75. // 封装JSON请求
  76. //{"msg":"成功","code":1000,"data":{"rp_id":"202203151003300001","order_id":null,"depart_name":"内科","doctor_name":"测试账号","pharmacist_name":null,"rp_url":"https://asset.nxk520.com/202203-go/C2203151057038646.png","diagnose":"眼睑带状疱疹","rp_msg":"已开方","audit_reason":null,"drugInfo":[{"drug_name":"维力青 恩替卡韦分散片 0.5mg*7片","sale_amount":1,"drug_specification":"0.5mg*7片"}],"create_date":"2022-03-15 10:03:30","pharmacy_code":"00001","pharmacy_name":"测试门店","doctor_id":"383"}}
  77. log.info("处方回调:{}", jsonBody);
  78. JSONObject json = JSON.parseObject(jsonBody);
  79. PrescribeV2VO vo= JSONUtil.toBean(jsonBody, PrescribeV2VO.class);
  80. if(vo.getCode().equals("1000")){
  81. if(vo.getData().getStatus().equals("已开方")){
  82. FsPrescribe fsPrescribe=prescribeService.selectFsPrescribeByRpId(vo.getData().getOnlyId());
  83. fsPrescribe.setRpUrl(vo.getData().getPrescriptionUrl());
  84. fsPrescribe.setRpCreateTime(new Date());
  85. fsPrescribe.setDoctorName(vo.getData().getDoctorName());
  86. fsPrescribe.setDiagnose(vo.getData().getDiagnose());
  87. fsPrescribe.setDrugs(JSONUtil.toJsonStr(vo.getData().getDrugInfo()));
  88. fsPrescribe.setStatus(1);
  89. fsPrescribe.setAuditReason(vo.getData().getAuditReason());
  90. prescribeService.updateFsPrescribe(fsPrescribe);
  91. //创建OMS订单
  92. FsStoreOrder order= orderService.selectFsStoreOrderById(fsPrescribe.getOrderId());
  93. if(order!=null&&order.getStatus()>0){
  94. orderService.createOmsOrder(fsPrescribe.getOrderId());
  95. }
  96. TemplateBean templateBean = TemplateBean.builder()
  97. .rpId(fsPrescribe.getRpId())
  98. .orderId(fsPrescribe.getOrderId().toString())
  99. .rpCreateTime(fsPrescribe.getRpCreateTime())
  100. .rpStatus("已开方")
  101. .userId(fsPrescribe.getUserId())
  102. .templateType(TemplateListenEnum.TYPE_4.getValue())
  103. .build();
  104. publisher.publishEvent(new TemplateEvent(this, templateBean));
  105. }
  106. else if(vo.getData().getStatus().equals("已拒绝")){
  107. FsPrescribe fsPrescribe=prescribeService.selectFsPrescribeByRpId(vo.getData().getOnlyId());
  108. fsPrescribe.setRpUrl(vo.getData().getPrescriptionUrl());
  109. fsPrescribe.setRpCreateTime(new Date());
  110. fsPrescribe.setDoctorName(vo.getData().getDoctorName());
  111. fsPrescribe.setDiagnose(vo.getData().getDiagnose());
  112. fsPrescribe.setDrugs(JSONUtil.toJsonStr(vo.getData().getDrugInfo()));
  113. fsPrescribe.setStatus(2);
  114. fsPrescribe.setAuditReason(vo.getData().getAuditReason());
  115. prescribeService.updateFsPrescribe(fsPrescribe);
  116. //自动退款
  117. orderService.refundPrescribeOrder(fsPrescribe.getOrderId());
  118. TemplateBean templateBean = TemplateBean.builder()
  119. .rpId(fsPrescribe.getRpId())
  120. .orderId(fsPrescribe.getOrderId().toString())
  121. .rpCreateTime(fsPrescribe.getRpCreateTime())
  122. .rpStatus("已拒绝")
  123. .userId(fsPrescribe.getUserId())
  124. .templateType(TemplateListenEnum.TYPE_4.getValue())
  125. .build();
  126. publisher.publishEvent(new TemplateEvent(this, templateBean));
  127. }
  128. }
  129. return "success";
  130. }
  131. }