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;
import com.alibaba.fastjson.JSONObject;
import com.cftech.cdfortis.model.FbusiDetail;
import com.cftech.prescription.model.Prescription;
import com.cftech.product.model.Product;
import java.util.List;
......@@ -14,21 +16,13 @@ import java.util.List;
*/
public interface CdfortisService {
/**
* 获取微问诊token
*
* @return
*/
JSONObject getTokenResult();
/**
* 药品清单上传
*
* @param productList
* @return
*/
JSONObject uploadDrugInfo(List<Product> productList);
JSONObject uploadDrugInfo(List<Product> productList) throws Exception;
/**
* 获取图文处方列表
......@@ -39,7 +33,7 @@ public interface CdfortisService {
* @param endTime
* @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 {
* @param presId
* @return
*/
JSONObject getFbusiDetail(String presId);
FbusiDetail getFbusiDetail(String presId) throws Exception;
/**
* 获取图文处方图片
......@@ -55,5 +49,5 @@ public interface CdfortisService {
* @param presId
* @return
*/
JSONObject getFbusiPicture(String presId);
String getFbusiPictureUrl(String presId) throws Exception;
}
package com.cftech.cdfortis.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cftech.cdfortis.constants.CdfortisConstant;
import com.cftech.cdfortis.model.CdfortisDrugInfo;
import com.cftech.cdfortis.model.FbusiDetail;
import com.cftech.cdfortis.service.CdfortisService;
import com.cftech.cdfortis.util.CdfortisResponseUtil;
import com.cftech.cdfortis.util.CdfortisTokenUtil;
import com.cftech.core.util.SystemConfig;
import com.cftech.prescription.model.Prescription;
import com.cftech.product.model.Product;
import lombok.extern.slf4j.Slf4j;
import okhttp3.MediaType;
......@@ -15,6 +18,7 @@ import okhttp3.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -38,23 +42,6 @@ public class CdfortisServiceImpl implements CdfortisService {
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 {
* @return
*/
@Override
public JSONObject uploadDrugInfo(List<Product> productList) {
JSONObject rtnJson = new JSONObject();
public JSONObject uploadDrugInfo(List<Product> productList) throws Exception {
String uploadUrl = SystemConfig.p.getProperty("cdfortis.drug_upload_url");
try {
// 构建参数
JSONObject param = new JSONObject();
param.put("appid", appid);
......@@ -77,32 +61,10 @@ public class CdfortisServiceImpl implements CdfortisService {
param.put("drugInfo", cdfortisDrugList);
RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, param.toJSONString());
// 请求获取数据
Object data = CdfortisResponseUtil.request(uploadUrl, CdfortisConstant.METHOD_POST,
null, null, body, rtnJson);
if (data == null) {
return rtnJson;
}
String data = CdfortisResponseUtil.request(uploadUrl, CdfortisConstant.METHOD_POST,
null, null, body);
// 判断数据是否正确
if (data instanceof JSONObject) {
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;
return JSONObject.parseObject(data);
}
......@@ -116,10 +78,8 @@ public class CdfortisServiceImpl implements CdfortisService {
* @return
*/
@Override
public JSONObject getFbusiList(int page, int rows, String startTime, String endTime) {
JSONObject rtnJson = new JSONObject();
public List<Prescription> getFbusiList(int page, int rows, String startTime, String endTime) throws Exception {
String getFbusiListUrl = SystemConfig.p.getProperty("cdfortis.get_fbusi_list_url");
try {
// 构建URL参数
Map<String, String> urlParam = new HashMap<>(6);
urlParam.put("appid", appid);
......@@ -129,17 +89,15 @@ public class CdfortisServiceImpl implements CdfortisService {
urlParam.put("startTime", startTime);
urlParam.put("endTime", endTime);
// 请求获取数据
Object data = CdfortisResponseUtil.request(getFbusiListUrl, CdfortisConstant.METHOD_GET, urlParam,
null, null, rtnJson);
if (data == null) {
return rtnJson;
}
rtnJson.put("errorNo", "0");
rtnJson.put("data", data);
} catch (Exception e) {
handleException(rtnJson, e);
String dataStr = CdfortisResponseUtil.request(getFbusiListUrl, CdfortisConstant.METHOD_GET, urlParam,
null, null);
JSONObject dataObject = JSON.parseObject(dataStr);
int count = dataObject.getIntValue("count");
if (count == 0) {
return new ArrayList<>();
}
return rtnJson;
String datalistStr = dataObject.getString("list");
return JSONArray.parseArray(datalistStr, Prescription.class);
}
/**
......@@ -149,27 +107,17 @@ public class CdfortisServiceImpl implements CdfortisService {
* @return
*/
@Override
public JSONObject getFbusiDetail(String presId) {
JSONObject rtnJson = new JSONObject();
public FbusiDetail getFbusiDetail(String presId) throws Exception {
String getFbusiInfoUrl = SystemConfig.p.getProperty("cdfortis.get_fbusi_info_url");
try {
// 构建URL参数
Map<String, String> urlParam = new HashMap<>(3);
urlParam.put("appid", appid);
urlParam.put("token", cdfortisTokenUtil.getToken());
urlParam.put("presId", presId);
// 请求获取数据
Object data = CdfortisResponseUtil.request(getFbusiInfoUrl, CdfortisConstant.METHOD_GET, urlParam,
null, null, rtnJson);
if (data == null) {
return rtnJson;
}
rtnJson.put("errorNo", "0");
rtnJson.put("data", data);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
String data = CdfortisResponseUtil.request(getFbusiInfoUrl, CdfortisConstant.METHOD_GET, urlParam,
null, null);
return JSONObject.parseObject(data, FbusiDetail.class);
}
/**
......@@ -179,27 +127,17 @@ public class CdfortisServiceImpl implements CdfortisService {
* @return
*/
@Override
public JSONObject getFbusiPicture(String presId) {
JSONObject rtnJson = new JSONObject();
public String getFbusiPictureUrl(String presId) throws Exception {
String getFbusiPicUrl = SystemConfig.p.getProperty("cdfortis.get_fbusi_pic_url");
try {
// 构建URL参数
Map<String, String> urlParam = new HashMap<>(3);
urlParam.put("appid", appid);
urlParam.put("token", cdfortisTokenUtil.getToken());
urlParam.put("presId", presId);
// 请求获取数据
Object data = CdfortisResponseUtil.request(getFbusiPicUrl, CdfortisConstant.METHOD_GET, urlParam,
null, null, rtnJson);
if (data == null) {
return rtnJson;
}
rtnJson.put("errorNo", "0");
rtnJson.put("data", data);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
String picUrl = CdfortisResponseUtil.request(getFbusiPicUrl, CdfortisConstant.METHOD_GET, urlParam,
null, null);
return picUrl;
}
......@@ -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 {
* @param queryParams
* @param headers
* @param body
* @param rtnJson
* @return
* @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();
// 处理query参数
if (queryParams != null) {
......@@ -75,15 +74,11 @@ public class CdfortisResponseUtil {
builder.post(body);
}
OkHttpClient client = getClient();
try {
Response response = client.newCall(builder.build()).execute();
// 判断http状态值
if (CdfortisConstant.HTTP_SUCC != response.code()) {
log.error(response.message());
rtnJson.put("errorNo", "1");
rtnJson.put("errorMsg", "微问诊请求失败");
rtnJson.put("errorEnMsg", "request failure");
return null;
throw new Exception("微问诊请求失败");
}
ResponseBody responseBody = response.body();
String retStr = responseBody.string();
......@@ -92,10 +87,7 @@ public class CdfortisResponseUtil {
JSONObject retObj = JSONObject.parseObject(retStr);
// 插件结果
checkResponse(retObj);
return retObj.get("data");
} catch (Exception e) {
throw new Exception(e.getMessage());
}
return retObj.getString("data");
}
}
package com.cftech.cdfortis.web;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cftech.cdfortis.model.FbusiDetail;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -24,6 +28,9 @@ public class CdfortisController {
@Autowired
CdfortisService cdfortisService;
@Autowired
CdfortisTokenUtil cdfortisTokenUtil;
/**
* 获取微问诊token
*
......@@ -31,7 +38,15 @@ public class CdfortisController {
*/
@GetMapping("/get/token")
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 {
*/
@PostMapping("/upload/druginfo")
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 {
*/
@GetMapping("/get/fbusi/list")
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 {
*/
@GetMapping("/get/fbusi/detail")
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 {
*/
@GetMapping("/get/fbusi/picture")
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
Content-Type: application/json
[{
"apprNumber": "国药准字Z10910006",
"spec": "10g/袋",
"approveNumber": "国药准字Z10910006",
"format": "10g/袋",
"price": "39.80",
"drugErpNo": "test_erp_001",
"name": "番泻叶颗粒",
"drugCompay": "江苏艾迪药业股份有限公司"
"productNumber": "PD202011040006",
"productName": "番泻叶颗粒",
"manufacturer": "江苏艾迪药业股份有限公司"
}]
### 获取图文处方列表接口
......
......@@ -346,6 +346,12 @@
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.cftech</groupId>
<artifactId>prescription-module-web</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<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