|
|
@@ -0,0 +1,268 @@
|
|
|
+package thyyxxk.wxservice_server.impl.wechat;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
|
|
|
+import thyyxxk.wxservice_server.dao.wechat.WeChatOfficialDao;
|
|
|
+import thyyxxk.wxservice_server.pojo.XxkRet;
|
|
|
+import thyyxxk.wxservice_server.pojo.assessment.CovidPojo;
|
|
|
+import thyyxxk.wxservice_server.pojo.wechat.*;
|
|
|
+import thyyxxk.wxservice_server.service.wechat.WeChatOfficialService;
|
|
|
+import thyyxxk.wxservice_server.utils.DecimalTool;
|
|
|
+import thyyxxk.wxservice_server.utils.HrgHttp;
|
|
|
+import thyyxxk.wxservice_server.utils.PropertiesUtil;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class WeChatOfficialImpl implements WeChatOfficialService {
|
|
|
+ private final WeChatOfficialDao dao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public WeChatOfficialImpl(WeChatOfficialDao dao) {
|
|
|
+ this.dao = dao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getOpenId(String code) {
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
+ String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx19fc85fd5bfcc164&" +
|
|
|
+ "secret=ffdf6f4ae704d374966dfb82bc300257&code="+code+"&grant_type=authorization_code";
|
|
|
+ String str = template.getForObject(url, String.class);
|
|
|
+ JSONObject json = JSONObject.parseObject(str);
|
|
|
+ String openid = json.getString("openid");
|
|
|
+ if (openid != null) {
|
|
|
+ return XxkRet.success(openid);
|
|
|
+ } else {
|
|
|
+ return XxkRet.fail(ExceptionEnum.LOGICAL_ERROR, json.getString("errmsg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getPatientIdByOpenId(String openId) {
|
|
|
+ return XxkRet.success(dao.getBindPatientCard(openId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet bindPatientId(BindPatientIdParam param) {
|
|
|
+ log.info("绑定就诊卡:{}", param);
|
|
|
+ final List<BindPatientIdParam> list = param.getCardType() == 1 ?
|
|
|
+ dao.getPatientBaseInfoByPatientId(param.getCardNo())
|
|
|
+ : dao.getPatientBaseInfoBySocialNo(param.getCardNo());
|
|
|
+ if (null == list || list.isEmpty()) {
|
|
|
+ return XxkRet.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到对应的就诊卡信息!");
|
|
|
+ } else {
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ if (list.size() == 1) {
|
|
|
+ BindPatientIdParam temp = list.get(0);
|
|
|
+ if (param.getName().trim().equals(temp.getName())) {
|
|
|
+ param.setPatientId(temp.getPatientId());
|
|
|
+ param.setSocialNo(temp.getSocialNo());
|
|
|
+ final int count = dao.isThisCardBindBefore(param.getPatientId(), param.getOpenId());
|
|
|
+ if (count > 0) {
|
|
|
+ dao.bindPatientCardAgain(param);
|
|
|
+ } else {
|
|
|
+ if (dao.validBindCount(param.getOpenId()) == 0) {
|
|
|
+ param.setIsDefault(1);
|
|
|
+ } else {
|
|
|
+ param.setIsDefault(0);
|
|
|
+ }
|
|
|
+ dao.bindPatientCard(param);
|
|
|
+ }
|
|
|
+ map.put("code", 0);
|
|
|
+ map.put("cards", dao.getBindPatientCard(param.getOpenId()));
|
|
|
+ log.info("绑定就诊卡成功。");
|
|
|
+ return XxkRet.success(map);
|
|
|
+ } else {
|
|
|
+ return XxkRet.fail(ExceptionEnum.LOGICAL_ERROR, "就诊卡姓名信息不匹配!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ map.put("code", 1);
|
|
|
+ map.put("cards", list);
|
|
|
+ log.info("绑定就诊卡: 身份证{} 有多张就诊卡:{}", param.getCardNo(), list);
|
|
|
+ return XxkRet.success(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet setDefaultCard(String patientId, String openId) {
|
|
|
+ String temp = "%%";
|
|
|
+ dao.updateDefaultCard(temp, openId, 0);
|
|
|
+ temp = "%" + patientId + "%";
|
|
|
+ dao.updateDefaultCard(temp, openId, 1);
|
|
|
+ return XxkRet.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet relieveBindCard(BindPatientIdParam param) {
|
|
|
+ log.info("解除就诊卡绑定:{}", param);
|
|
|
+ dao.unBindPatientCard(param.getPatientId(), param.getOpenId());
|
|
|
+ return XxkRet.success(dao.getBindPatientCard(param.getOpenId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getAllDepartments() {
|
|
|
+ List<MzClassPojo> mzClasses = dao.getAllMzClasses();
|
|
|
+ for (MzClassPojo mzClass : mzClasses) {
|
|
|
+ mzClass.setChildren(dao.getMzDeptsByMzClass(mzClass.getId()));
|
|
|
+ }
|
|
|
+ return XxkRet.success(mzClasses);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getSourcesByDate(GetSourcesByDateParam param) {
|
|
|
+ String url = String.format("http://webhis.thyy.cn:81/thmz/api/v1/getNumByDateAndDept?" +
|
|
|
+ "beginDate=%s&endDate=%s&unitCode=%s", param.getStart(), param.getEnd(), param.getDept());
|
|
|
+ return HrgHttp.getResponseFromHrg(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getDoctorSources(GetDoctorSourcesParam param) {
|
|
|
+ String url = String.format("http://webhis.thyy.cn:81/thmz/api/v1/getDoctorByDateAndDept?" +
|
|
|
+ "requestDay=%s&unitCode=%s", param.getDate(), param.getDeptCode());
|
|
|
+ return HrgHttp.getResponseFromHrg(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getDoctorArrangement(GetDoctorSourcesParam param) {
|
|
|
+ String url = String.format("http://webhis.thyy.cn:81/thmz/api/v1/getRequestByDateAndDeptAndDoctor?" +
|
|
|
+ "requestDay=%s&unitCode=%s&doctorCode=%s", param.getDate(), param.getDeptCode(), param.getDoctorCode());
|
|
|
+ return HrgHttp.getResponseFromHrg(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getDoctorInfo(String doctorCode, String openId) {
|
|
|
+ return XxkRet.success(dao.getDoctorInfo(doctorCode, openId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getSourcesByDateAndDoctor(GetDoctorSourcesParam param) {
|
|
|
+ int[] source = new int[7];
|
|
|
+ source[0] = getDoctorArrangement(param).getCode();
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ for (int i = 1; i < 7; i++) {
|
|
|
+ calendar.add(Calendar.DATE, 1);
|
|
|
+ param.setDate(dateFormat.format(calendar.getTime()));
|
|
|
+ source[i] = getDoctorArrangement(param).getCode();
|
|
|
+ }
|
|
|
+ return XxkRet.success(source);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet hasDoneCovidAssessment(String patientId) {
|
|
|
+ CovidPojo covid = dao.validCovidAssessment(patientId);
|
|
|
+ if (null == covid) {
|
|
|
+ return XxkRet.success("no valid assessment");
|
|
|
+ } else {
|
|
|
+ if (covid.getTemperature() == 2 ||
|
|
|
+ covid.getItem1() != 14 ||
|
|
|
+ covid.getItem2() != 24 ||
|
|
|
+ covid.getItem3() != 32 ||
|
|
|
+ covid.getItem4() != 42 ||
|
|
|
+ covid.getItem5() != 52) {
|
|
|
+ return XxkRet.fail(ExceptionEnum.LOGICAL_ERROR, "您新型冠状病毒感染流行病学史问卷未通过,请挂发热门诊。");
|
|
|
+ } else {
|
|
|
+ return XxkRet.success("valid assessment");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet collectDoctor(CollectDoctorParam param) {
|
|
|
+ dao.collectDoctor(param);
|
|
|
+ return XxkRet.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet disCollectDoctor(CollectDoctorParam param) {
|
|
|
+ dao.disCollectDoctor(param);
|
|
|
+ return XxkRet.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getMyCollections(String openId) {
|
|
|
+ return XxkRet.success(dao.getCollections(openId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getDoctorQrCode(String doctorCode) {
|
|
|
+ final String token = PropertiesUtil.getProperty("qywxToken");
|
|
|
+ final String url = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=" + token +
|
|
|
+ "&userid=" + dao.getCodeRsByCode(doctorCode);
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ final String result = restTemplate.getForObject(url, String.class);
|
|
|
+ JSONObject json = JSONObject.parseObject(result);
|
|
|
+ return XxkRet.success(json.getString("qr_code"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getUnPaidFee(String patientId) {
|
|
|
+ String url = "http://webhis.thyy.cn:81/thmz/api/v1/getMzChargeDetailForUnPaid";
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("patCardType", "1");
|
|
|
+ obj.put("patCardNo", patientId.trim());
|
|
|
+ return HrgHttp.postResponseFromHrg(url, obj);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getUnPaidDetail(String patientId, String hisOrdNum) {
|
|
|
+ String url = "http://webhis.thyy.cn:81/thmz/api/v1/getChargeDetailByHisOrdNum";
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("patCardType", "1");
|
|
|
+ obj.put("patCardNo", patientId.trim());
|
|
|
+ obj.put("hisOrdNum", hisOrdNum.trim());
|
|
|
+ return HrgHttp.postResponseFromHrg(url, obj);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getInpatientInfo(String patientId) {
|
|
|
+ InpatientInfo info = dao.getInpatientInfo(patientId.trim());
|
|
|
+ if (null != info && null != info.getInpatientNo()) {
|
|
|
+ return XxkRet.success(info);
|
|
|
+ } else {
|
|
|
+ return XxkRet.fail(ExceptionEnum.NULL_POINTER, "没有找到此卡号的在院信息。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getZyFees(GetZyFeeParam param) {
|
|
|
+ dao.receiveProjectFees(param.getInpatientNo(), param.getAdmissTimes());
|
|
|
+ dao.receiveMedicineFees(param.getInpatientNo(), param.getAdmissTimes());
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<ZyFee> fees = dao.getZyFees(param);
|
|
|
+ map.put("fees", fees);
|
|
|
+ map.put("totalCost", getZyTotalCost(fees));
|
|
|
+ return XxkRet.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getZyTotalCost(List<ZyFee> fees) {
|
|
|
+ String total = "0.00";
|
|
|
+ if (null == fees || fees.isEmpty()) {
|
|
|
+ return total;
|
|
|
+ }
|
|
|
+ for (ZyFee fee : fees) {
|
|
|
+ total = DecimalTool.add(total, fee.getJe());
|
|
|
+ }
|
|
|
+ return total;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public XxkRet getPrepaidHistory(String patientId) {
|
|
|
+ InpatientInfo info = dao.getInpatientInfo(patientId.trim());
|
|
|
+ if (null != info && null != info.getInpatientNo()) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("baseInfo", info);
|
|
|
+ map.put("prepaid", dao.getPrepaidHistory(info.getInpatientNo(), info.getAdmissTimes()));
|
|
|
+ return XxkRet.success(map);
|
|
|
+ } else {
|
|
|
+ return XxkRet.fail(ExceptionEnum.NULL_POINTER, "没有找到此卡号的在院信息。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|