Commit a735366f authored by 马超's avatar 马超

feat(微问诊): 修改微问诊访问服务层返回结果及方式(待集成到业务模块中

parent be52cd5b
package com.cftech.cdfortis.model;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class FbusiDetail implements Serializable {
private String id;
private String storeId;
private String hospitalName;
private String storeName;
private String custName;
private String weight;
private String custSex;
private String custPhone;
private String symptom;
private String syptmFlag;
private String doctorName;
private String docStatus;
private String docResult;
private String doctorDpmtName;
private String pharmName;
private String status;
private String result;
private String auditDate;
private String startTime;
private String guoms;
private String age;
private String presUrl;
private List<FbusiDrug> drugs;
}
package com.cftech.cdfortis.model;
import lombok.Data;
import java.io.Serializable;
@Data
public class FbusiDrug implements Serializable {
private String drugId;
private String drugName;
private String drugCompany;
private String drugNum;
private String apprNumber;
private String spec;
private String dosage;
private String drugUnit;
private String otc;
private String drugErpNo;
}
...@@ -2,6 +2,8 @@ package com.cftech.cdfortis.service; ...@@ -2,6 +2,8 @@ package com.cftech.cdfortis.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.cftech.cdfortis.model.FbusiDetail;
import com.cftech.prescription.model.Prescription;
import com.cftech.product.model.Product; import com.cftech.product.model.Product;
import java.util.List; import java.util.List;
...@@ -14,21 +16,13 @@ import java.util.List; ...@@ -14,21 +16,13 @@ import java.util.List;
*/ */
public interface CdfortisService { public interface CdfortisService {
/**
* 获取微问诊token
*
* @return
*/
JSONObject getTokenResult();
/** /**
* 药品清单上传 * 药品清单上传
* *
* @param productList * @param productList
* @return * @return
*/ */
JSONObject uploadDrugInfo(List<Product> productList); JSONObject uploadDrugInfo(List<Product> productList) throws Exception;
/** /**
* 获取图文处方列表 * 获取图文处方列表
...@@ -39,7 +33,7 @@ public interface CdfortisService { ...@@ -39,7 +33,7 @@ public interface CdfortisService {
* @param endTime * @param endTime
* @return * @return
*/ */
JSONObject getFbusiList(int page, int rows, String startTime, String endTime); List<Prescription> getFbusiList(int page, int rows, String startTime, String endTime) throws Exception;
/** /**
* 获取图文处方详情 * 获取图文处方详情
...@@ -47,7 +41,7 @@ public interface CdfortisService { ...@@ -47,7 +41,7 @@ public interface CdfortisService {
* @param presId * @param presId
* @return * @return
*/ */
JSONObject getFbusiDetail(String presId); FbusiDetail getFbusiDetail(String presId) throws Exception;
/** /**
* 获取图文处方图片 * 获取图文处方图片
...@@ -55,5 +49,5 @@ public interface CdfortisService { ...@@ -55,5 +49,5 @@ public interface CdfortisService {
* @param presId * @param presId
* @return * @return
*/ */
JSONObject getFbusiPicture(String presId); String getFbusiPictureUrl(String presId) throws Exception;
} }
package com.cftech.cdfortis.service.impl; package com.cftech.cdfortis.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.cftech.cdfortis.constants.CdfortisConstant; import com.cftech.cdfortis.constants.CdfortisConstant;
import com.cftech.cdfortis.model.CdfortisDrugInfo; import com.cftech.cdfortis.model.CdfortisDrugInfo;
import com.cftech.cdfortis.model.FbusiDetail;
import com.cftech.cdfortis.service.CdfortisService; import com.cftech.cdfortis.service.CdfortisService;
import com.cftech.cdfortis.util.CdfortisResponseUtil; import com.cftech.cdfortis.util.CdfortisResponseUtil;
import com.cftech.cdfortis.util.CdfortisTokenUtil; import com.cftech.cdfortis.util.CdfortisTokenUtil;
import com.cftech.core.util.SystemConfig; import com.cftech.core.util.SystemConfig;
import com.cftech.prescription.model.Prescription;
import com.cftech.product.model.Product; import com.cftech.product.model.Product;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.MediaType; import okhttp3.MediaType;
...@@ -15,6 +18,7 @@ import okhttp3.RequestBody; ...@@ -15,6 +18,7 @@ import okhttp3.RequestBody;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -38,23 +42,6 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -38,23 +42,6 @@ public class CdfortisServiceImpl implements CdfortisService {
private static String appid = SystemConfig.p.getProperty("cdfortis.appid"); private static String appid = SystemConfig.p.getProperty("cdfortis.appid");
/**
* 获取token
*
* @return
*/
@Override
public JSONObject getTokenResult() {
JSONObject rtnJson = new JSONObject();
try {
String token = cdfortisTokenUtil.getToken();
rtnJson.put("errorNo", "0");
rtnJson.put("data", token);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
}
/** /**
* 上传药品清单 * 上传药品清单
...@@ -63,11 +50,8 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -63,11 +50,8 @@ public class CdfortisServiceImpl implements CdfortisService {
* @return * @return
*/ */
@Override @Override
public JSONObject uploadDrugInfo(List<Product> productList) { public JSONObject uploadDrugInfo(List<Product> productList) throws Exception {
JSONObject rtnJson = new JSONObject();
String uploadUrl = SystemConfig.p.getProperty("cdfortis.drug_upload_url"); String uploadUrl = SystemConfig.p.getProperty("cdfortis.drug_upload_url");
try {
// 构建参数 // 构建参数
JSONObject param = new JSONObject(); JSONObject param = new JSONObject();
param.put("appid", appid); param.put("appid", appid);
...@@ -77,32 +61,10 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -77,32 +61,10 @@ public class CdfortisServiceImpl implements CdfortisService {
param.put("drugInfo", cdfortisDrugList); param.put("drugInfo", cdfortisDrugList);
RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, param.toJSONString()); RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, param.toJSONString());
// 请求获取数据 // 请求获取数据
Object data = CdfortisResponseUtil.request(uploadUrl, CdfortisConstant.METHOD_POST, String data = CdfortisResponseUtil.request(uploadUrl, CdfortisConstant.METHOD_POST,
null, null, body, rtnJson); null, null, body);
if (data == null) {
return rtnJson;
}
// 判断数据是否正确 // 判断数据是否正确
if (data instanceof JSONObject) { return JSONObject.parseObject(data);
JSONObject dataJsonObj = (JSONObject) data;
boolean isAllSuccess = dataJsonObj.getBooleanValue("isAllSuccess");
if (!isAllSuccess) {
JSONArray failedDataArr = dataJsonObj.getJSONArray("failedData");
//TODO 更新药物上传状态
rtnJson.put("errorNo", "0");
rtnJson.put("data", failedDataArr);
return rtnJson;
}
}
rtnJson.put("errorNo", "0");
rtnJson.put("data", "");
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
} }
...@@ -116,10 +78,8 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -116,10 +78,8 @@ public class CdfortisServiceImpl implements CdfortisService {
* @return * @return
*/ */
@Override @Override
public JSONObject getFbusiList(int page, int rows, String startTime, String endTime) { public List<Prescription> getFbusiList(int page, int rows, String startTime, String endTime) throws Exception {
JSONObject rtnJson = new JSONObject();
String getFbusiListUrl = SystemConfig.p.getProperty("cdfortis.get_fbusi_list_url"); String getFbusiListUrl = SystemConfig.p.getProperty("cdfortis.get_fbusi_list_url");
try {
// 构建URL参数 // 构建URL参数
Map<String, String> urlParam = new HashMap<>(6); Map<String, String> urlParam = new HashMap<>(6);
urlParam.put("appid", appid); urlParam.put("appid", appid);
...@@ -129,17 +89,15 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -129,17 +89,15 @@ public class CdfortisServiceImpl implements CdfortisService {
urlParam.put("startTime", startTime); urlParam.put("startTime", startTime);
urlParam.put("endTime", endTime); urlParam.put("endTime", endTime);
// 请求获取数据 // 请求获取数据
Object data = CdfortisResponseUtil.request(getFbusiListUrl, CdfortisConstant.METHOD_GET, urlParam, String dataStr = CdfortisResponseUtil.request(getFbusiListUrl, CdfortisConstant.METHOD_GET, urlParam,
null, null, rtnJson); null, null);
if (data == null) { JSONObject dataObject = JSON.parseObject(dataStr);
return rtnJson; int count = dataObject.getIntValue("count");
} if (count == 0) {
rtnJson.put("errorNo", "0"); return new ArrayList<>();
rtnJson.put("data", data);
} catch (Exception e) {
handleException(rtnJson, e);
} }
return rtnJson; String datalistStr = dataObject.getString("list");
return JSONArray.parseArray(datalistStr, Prescription.class);
} }
/** /**
...@@ -149,27 +107,17 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -149,27 +107,17 @@ public class CdfortisServiceImpl implements CdfortisService {
* @return * @return
*/ */
@Override @Override
public JSONObject getFbusiDetail(String presId) { public FbusiDetail getFbusiDetail(String presId) throws Exception {
JSONObject rtnJson = new JSONObject();
String getFbusiInfoUrl = SystemConfig.p.getProperty("cdfortis.get_fbusi_info_url"); String getFbusiInfoUrl = SystemConfig.p.getProperty("cdfortis.get_fbusi_info_url");
try {
// 构建URL参数 // 构建URL参数
Map<String, String> urlParam = new HashMap<>(3); Map<String, String> urlParam = new HashMap<>(3);
urlParam.put("appid", appid); urlParam.put("appid", appid);
urlParam.put("token", cdfortisTokenUtil.getToken()); urlParam.put("token", cdfortisTokenUtil.getToken());
urlParam.put("presId", presId); urlParam.put("presId", presId);
// 请求获取数据 // 请求获取数据
Object data = CdfortisResponseUtil.request(getFbusiInfoUrl, CdfortisConstant.METHOD_GET, urlParam, String data = CdfortisResponseUtil.request(getFbusiInfoUrl, CdfortisConstant.METHOD_GET, urlParam,
null, null, rtnJson); null, null);
if (data == null) { return JSONObject.parseObject(data, FbusiDetail.class);
return rtnJson;
}
rtnJson.put("errorNo", "0");
rtnJson.put("data", data);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
} }
/** /**
...@@ -179,27 +127,17 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -179,27 +127,17 @@ public class CdfortisServiceImpl implements CdfortisService {
* @return * @return
*/ */
@Override @Override
public JSONObject getFbusiPicture(String presId) { public String getFbusiPictureUrl(String presId) throws Exception {
JSONObject rtnJson = new JSONObject();
String getFbusiPicUrl = SystemConfig.p.getProperty("cdfortis.get_fbusi_pic_url"); String getFbusiPicUrl = SystemConfig.p.getProperty("cdfortis.get_fbusi_pic_url");
try {
// 构建URL参数 // 构建URL参数
Map<String, String> urlParam = new HashMap<>(3); Map<String, String> urlParam = new HashMap<>(3);
urlParam.put("appid", appid); urlParam.put("appid", appid);
urlParam.put("token", cdfortisTokenUtil.getToken()); urlParam.put("token", cdfortisTokenUtil.getToken());
urlParam.put("presId", presId); urlParam.put("presId", presId);
// 请求获取数据 // 请求获取数据
Object data = CdfortisResponseUtil.request(getFbusiPicUrl, CdfortisConstant.METHOD_GET, urlParam, String picUrl = CdfortisResponseUtil.request(getFbusiPicUrl, CdfortisConstant.METHOD_GET, urlParam,
null, null, rtnJson); null, null);
if (data == null) { return picUrl;
return rtnJson;
}
rtnJson.put("errorNo", "0");
rtnJson.put("data", data);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
} }
...@@ -222,18 +160,4 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -222,18 +160,4 @@ public class CdfortisServiceImpl implements CdfortisService {
} }
/**
* 处理异常
*
* @param rtnJson
* @param e
*/
private void handleException(JSONObject rtnJson, Exception e) {
log.error(e.getMessage(), e);
rtnJson.put("errorNo", "1");
rtnJson.put("errorMsg", e.getMessage());
rtnJson.put("errorEnMsg", e.getMessage());
}
} }
...@@ -52,11 +52,10 @@ public class CdfortisResponseUtil { ...@@ -52,11 +52,10 @@ public class CdfortisResponseUtil {
* @param queryParams * @param queryParams
* @param headers * @param headers
* @param body * @param body
* @param rtnJson
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static Object request(String url, String method, Map<String, String> queryParams, Map<String, String> headers, RequestBody body, JSONObject rtnJson) throws Exception { public static String request(String url, String method, Map<String, String> queryParams, Map<String, String> headers, RequestBody body) throws Exception {
HttpUrl.Builder urlBuild = HttpUrl.parse(url).newBuilder(); HttpUrl.Builder urlBuild = HttpUrl.parse(url).newBuilder();
// 处理query参数 // 处理query参数
if (queryParams != null) { if (queryParams != null) {
...@@ -75,15 +74,11 @@ public class CdfortisResponseUtil { ...@@ -75,15 +74,11 @@ public class CdfortisResponseUtil {
builder.post(body); builder.post(body);
} }
OkHttpClient client = getClient(); OkHttpClient client = getClient();
try {
Response response = client.newCall(builder.build()).execute(); Response response = client.newCall(builder.build()).execute();
// 判断http状态值 // 判断http状态值
if (CdfortisConstant.HTTP_SUCC != response.code()) { if (CdfortisConstant.HTTP_SUCC != response.code()) {
log.error(response.message()); log.error(response.message());
rtnJson.put("errorNo", "1"); throw new Exception("微问诊请求失败");
rtnJson.put("errorMsg", "微问诊请求失败");
rtnJson.put("errorEnMsg", "request failure");
return null;
} }
ResponseBody responseBody = response.body(); ResponseBody responseBody = response.body();
String retStr = responseBody.string(); String retStr = responseBody.string();
...@@ -92,10 +87,7 @@ public class CdfortisResponseUtil { ...@@ -92,10 +87,7 @@ public class CdfortisResponseUtil {
JSONObject retObj = JSONObject.parseObject(retStr); JSONObject retObj = JSONObject.parseObject(retStr);
// 插件结果 // 插件结果
checkResponse(retObj); checkResponse(retObj);
return retObj.get("data"); return retObj.getString("data");
} catch (Exception e) {
throw new Exception(e.getMessage());
}
} }
} }
package com.cftech.cdfortis.web; package com.cftech.cdfortis.web;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.cftech.cdfortis.model.FbusiDetail;
import com.cftech.cdfortis.service.CdfortisService; import com.cftech.cdfortis.service.CdfortisService;
import com.cftech.cdfortis.util.CdfortisTokenUtil;
import com.cftech.prescription.model.Prescription;
import com.cftech.product.model.Product; import com.cftech.product.model.Product;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -24,6 +28,9 @@ public class CdfortisController { ...@@ -24,6 +28,9 @@ public class CdfortisController {
@Autowired @Autowired
CdfortisService cdfortisService; CdfortisService cdfortisService;
@Autowired
CdfortisTokenUtil cdfortisTokenUtil;
/** /**
* 获取微问诊token * 获取微问诊token
* *
...@@ -31,7 +38,15 @@ public class CdfortisController { ...@@ -31,7 +38,15 @@ public class CdfortisController {
*/ */
@GetMapping("/get/token") @GetMapping("/get/token")
public JSONObject getToken() { public JSONObject getToken() {
return cdfortisService.getTokenResult(); JSONObject rtnJson = new JSONObject();
try {
String token = cdfortisTokenUtil.getToken();
setSuccResult(rtnJson, token);
} catch (Exception e) {
log.error(e.getMessage());
handleException(rtnJson, e);
}
return rtnJson;
} }
...@@ -43,7 +58,20 @@ public class CdfortisController { ...@@ -43,7 +58,20 @@ public class CdfortisController {
*/ */
@PostMapping("/upload/druginfo") @PostMapping("/upload/druginfo")
public JSONObject uploadDrugInfo(@RequestBody List<Product> productList) { public JSONObject uploadDrugInfo(@RequestBody List<Product> productList) {
return cdfortisService.uploadDrugInfo(productList); JSONObject rtnJson = new JSONObject();
try {
JSONObject dataJsonObj = cdfortisService.uploadDrugInfo(productList);
boolean isAllSuccess = dataJsonObj.getBooleanValue("isAllSuccess");
Object data = "";
if (!isAllSuccess) {
JSONArray failedDataArr = dataJsonObj.getJSONArray("failedData");
data = failedDataArr;
}
setSuccResult(rtnJson, data);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
} }
...@@ -58,7 +86,14 @@ public class CdfortisController { ...@@ -58,7 +86,14 @@ public class CdfortisController {
*/ */
@GetMapping("/get/fbusi/list") @GetMapping("/get/fbusi/list")
public JSONObject getFbusiList(int iDisplayStart, int iDisplayLength, @RequestParam String startTime, @RequestParam String endTime) { public JSONObject getFbusiList(int iDisplayStart, int iDisplayLength, @RequestParam String startTime, @RequestParam String endTime) {
return cdfortisService.getFbusiList(iDisplayStart, iDisplayLength, startTime, endTime); JSONObject rtnJson = new JSONObject();
try {
List<Prescription> fbusiList = cdfortisService.getFbusiList(iDisplayStart, iDisplayLength, startTime, endTime);
setSuccResult(rtnJson, fbusiList);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
} }
...@@ -70,7 +105,14 @@ public class CdfortisController { ...@@ -70,7 +105,14 @@ public class CdfortisController {
*/ */
@GetMapping("/get/fbusi/detail") @GetMapping("/get/fbusi/detail")
public JSONObject getFbusiDetail(@RequestParam String presId) { public JSONObject getFbusiDetail(@RequestParam String presId) {
return cdfortisService.getFbusiDetail(presId); JSONObject rtnJson = new JSONObject();
try {
FbusiDetail fbusiDetail = cdfortisService.getFbusiDetail(presId);
setSuccResult(rtnJson, fbusiDetail);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
} }
...@@ -82,7 +124,49 @@ public class CdfortisController { ...@@ -82,7 +124,49 @@ public class CdfortisController {
*/ */
@GetMapping("/get/fbusi/picture") @GetMapping("/get/fbusi/picture")
public JSONObject getFbusiPicture(@RequestParam String presId) { public JSONObject getFbusiPicture(@RequestParam String presId) {
return cdfortisService.getFbusiPicture(presId); JSONObject rtnJson = new JSONObject();
try {
String pictureUrl = cdfortisService.getFbusiPictureUrl(presId);
setSuccResult(rtnJson, pictureUrl);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
}
/**
* 成功的结果
*
* @return
*/
private void setSuccResult(JSONObject rtnJson, Object data) {
rtnJson.put("errorNo", "0");
rtnJson.put("data", data);
}
/**
* 失败的结果
*
* @return
*/
private void errorResult(String errorMsg) {
JSONObject rtnJson = new JSONObject();
rtnJson.put("errorNo", "1");
rtnJson.put("errorMsg", errorMsg);
}
/**
* 处理异常
*
* @param rtnJson
* @param e
*/
private void handleException(JSONObject rtnJson, Exception e) {
log.error(e.getMessage(), e);
rtnJson.put("errorNo", "1");
rtnJson.put("errorMsg", e.getMessage());
rtnJson.put("errorEnMsg", e.getMessage());
} }
......
...@@ -6,12 +6,12 @@ POST http://localhost:8080/aidea/mobile/auth/cdfortis/upload/druginfo ...@@ -6,12 +6,12 @@ POST http://localhost:8080/aidea/mobile/auth/cdfortis/upload/druginfo
Content-Type: application/json Content-Type: application/json
[{ [{
"apprNumber": "国药准字Z10910006", "approveNumber": "国药准字Z10910006",
"spec": "10g/袋", "format": "10g/袋",
"price": "39.80", "price": "39.80",
"drugErpNo": "test_erp_001", "productNumber": "PD202011040006",
"name": "番泻叶颗粒", "productName": "番泻叶颗粒",
"drugCompay": "江苏艾迪药业股份有限公司" "manufacturer": "江苏艾迪药业股份有限公司"
}] }]
### 获取图文处方列表接口 ### 获取图文处方列表接口
......
...@@ -346,6 +346,12 @@ ...@@ -346,6 +346,12 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<type>war</type> <type>war</type>
</dependency> </dependency>
<dependency>
<groupId>com.cftech</groupId>
<artifactId>prescription-module-web</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>portal-web</finalName> <finalName>portal-web</finalName>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment