Commit ad3b61bc authored by 马超's avatar 马超

Merge branch 'develop-mc' into 'master'

Develop mc

See merge request !3
parents 72f5fc94 c0793357
...@@ -15,6 +15,7 @@ public class CdfortisConstant { ...@@ -15,6 +15,7 @@ public class CdfortisConstant {
* 成功的返回值 * 成功的返回值
*/ */
public static String RESULT_SUCC_CODE = "C00010000"; public static String RESULT_SUCC_CODE = "C00010000";
public static String RESULT_NO_DATA_CODE = "C00030016";
/** /**
......
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 Long 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.StringUtils;
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 +19,7 @@ import okhttp3.RequestBody; ...@@ -15,6 +19,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 +43,6 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -38,23 +43,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,46 +51,21 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -63,46 +51,21 @@ 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();
// 构建参数 param.put("appid", appid);
JSONObject param = new JSONObject(); param.put("token", cdfortisTokenUtil.getToken());
param.put("appid", appid); // 转换药品类型为微问诊需要的结构
param.put("token", cdfortisTokenUtil.getToken()); List<CdfortisDrugInfo> cdfortisDrugList = productList.stream().map(this::fromProduct).collect(Collectors.toList());
// 转换药品类型为微问诊需要的结构 param.put("drugInfo", cdfortisDrugList);
List<CdfortisDrugInfo> cdfortisDrugList = productList.stream().map(this::fromProduct).collect(Collectors.toList()); RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, param.toJSONString());
param.put("drugInfo", cdfortisDrugList); // 请求获取数据
RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, param.toJSONString()); String data = CdfortisResponseUtil.request(uploadUrl, CdfortisConstant.METHOD_POST,
// 请求获取数据 null, null, body);
Object data = CdfortisResponseUtil.request(uploadUrl, CdfortisConstant.METHOD_POST, // 判断数据是否正确
null, null, body, rtnJson); return JSONObject.parseObject(data);
if (data == null) {
return rtnJson;
}
// 判断数据是否正确
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;
} }
...@@ -116,30 +79,32 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -116,30 +79,32 @@ 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); urlParam.put("token", cdfortisTokenUtil.getToken());
urlParam.put("token", cdfortisTokenUtil.getToken()); urlParam.put("page", page + "");
urlParam.put("page", page + ""); urlParam.put("rows", rows + "");
urlParam.put("rows", rows + ""); urlParam.put("startTime", startTime);
urlParam.put("startTime", startTime); urlParam.put("endTime", endTime);
urlParam.put("endTime", endTime); // 请求获取数据
// 请求获取数据 String dataStr = CdfortisResponseUtil.request(getFbusiListUrl, CdfortisConstant.METHOD_GET, urlParam,
Object data = CdfortisResponseUtil.request(getFbusiListUrl, CdfortisConstant.METHOD_GET, urlParam, null, null);
null, null, rtnJson); // 没数据时的解决方案 C00030016
if (data == null) { if (StringUtils.isEmpty(dataStr)) {
return rtnJson; return new ArrayList<>();
}
rtnJson.put("errorNo", "0");
rtnJson.put("data", data);
} catch (Exception e) {
handleException(rtnJson, e);
} }
return rtnJson; JSONObject dataObject = JSON.parseObject(dataStr);
int count = dataObject.getIntValue("count");
if (count == 0) {
return new ArrayList<>();
}
String datalistStr = dataObject.getString("list");
//TODO 结果映射
return JSONArray.parseArray(datalistStr, Prescription.class);
} }
/** /**
...@@ -149,27 +114,17 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -149,27 +114,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); // 请求获取数据
// 请求获取数据 String data = CdfortisResponseUtil.request(getFbusiInfoUrl, CdfortisConstant.METHOD_GET, urlParam,
Object data = CdfortisResponseUtil.request(getFbusiInfoUrl, CdfortisConstant.METHOD_GET, urlParam, null, null);
null, null, rtnJson); return JSONObject.parseObject(data, FbusiDetail.class);
if (data == null) {
return rtnJson;
}
rtnJson.put("errorNo", "0");
rtnJson.put("data", data);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
} }
/** /**
...@@ -179,27 +134,17 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -179,27 +134,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); // 请求获取数据
// 请求获取数据 String picUrl = CdfortisResponseUtil.request(getFbusiPicUrl, CdfortisConstant.METHOD_GET, urlParam,
Object data = CdfortisResponseUtil.request(getFbusiPicUrl, CdfortisConstant.METHOD_GET, urlParam, null, null);
null, null, rtnJson); return picUrl;
if (data == null) {
return rtnJson;
}
rtnJson.put("errorNo", "0");
rtnJson.put("data", data);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
} }
...@@ -222,18 +167,4 @@ public class CdfortisServiceImpl implements CdfortisService { ...@@ -222,18 +167,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());
}
} }
...@@ -2,6 +2,7 @@ package com.cftech.cdfortis.util; ...@@ -2,6 +2,7 @@ package com.cftech.cdfortis.util;
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.core.util.SystemConfig;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.*; import okhttp3.*;
...@@ -37,7 +38,8 @@ public class CdfortisResponseUtil { ...@@ -37,7 +38,8 @@ public class CdfortisResponseUtil {
*/ */
public static void checkResponse(JSONObject retObj) throws Exception { public static void checkResponse(JSONObject retObj) throws Exception {
JSONObject returnCode = retObj.getJSONObject(CdfortisConstant.RETURN_CODE); JSONObject returnCode = retObj.getJSONObject(CdfortisConstant.RETURN_CODE);
if (!CdfortisConstant.RESULT_SUCC_CODE.equals(returnCode.getString(CdfortisConstant.RETURN_CODE_KEY))) { String codeValue = returnCode.getString(CdfortisConstant.RETURN_CODE_KEY);
if (!CdfortisConstant.RESULT_SUCC_CODE.equals(codeValue)) {
log.error(returnCode.toJSONString()); log.error(returnCode.toJSONString());
throw new Exception(returnCode.getString(CdfortisConstant.RETURN_CODE_CONTENT)); throw new Exception(returnCode.getString(CdfortisConstant.RETURN_CODE_CONTENT));
} }
...@@ -52,11 +54,10 @@ public class CdfortisResponseUtil { ...@@ -52,11 +54,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,27 +76,25 @@ public class CdfortisResponseUtil { ...@@ -75,27 +76,25 @@ 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()); throw new Exception("微问诊请求失败");
rtnJson.put("errorNo", "1");
rtnJson.put("errorMsg", "微问诊请求失败");
rtnJson.put("errorEnMsg", "request failure");
return null;
}
ResponseBody responseBody = response.body();
String retStr = responseBody.string();
log.debug("request result: {}", retStr);
// 转换结果
JSONObject retObj = JSONObject.parseObject(retStr);
// 插件结果
checkResponse(retObj);
return retObj.get("data");
} catch (Exception e) {
throw new Exception(e.getMessage());
} }
ResponseBody responseBody = response.body();
String retStr = responseBody.string();
log.debug("request result: {}", retStr);
// 转换结果
JSONObject retObj = JSONObject.parseObject(retStr);
// 列表接口没有数据的特殊处理(理论上没有数据应该是一个空数组,但是微问诊返回结果是错误)
if (SystemConfig.p.getProperty("cdfortis.get_fbusi_list_url").equals(url)
&& CdfortisConstant.RESULT_NO_DATA_CODE.equals(retObj.getJSONObject(CdfortisConstant.RETURN_CODE).getString(CdfortisConstant.RETURN_CODE_KEY))) {
return "";
}
// 检查结果
checkResponse(retObj);
return retObj.getString("data");
} }
} }
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.prescription.service.PrescriptionService;
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 +29,12 @@ public class CdfortisController { ...@@ -24,6 +29,12 @@ public class CdfortisController {
@Autowired @Autowired
CdfortisService cdfortisService; CdfortisService cdfortisService;
@Autowired
CdfortisTokenUtil cdfortisTokenUtil;
@Autowired
PrescriptionService prescriptionService;
/** /**
* 获取微问诊token * 获取微问诊token
* *
...@@ -31,7 +42,15 @@ public class CdfortisController { ...@@ -31,7 +42,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 +62,20 @@ public class CdfortisController { ...@@ -43,7 +62,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;
} }
...@@ -57,8 +89,15 @@ public class CdfortisController { ...@@ -57,8 +89,15 @@ public class CdfortisController {
* @return * @return
*/ */
@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, String startTime, String endTime) {
return cdfortisService.getFbusiList(iDisplayStart, iDisplayLength, startTime, endTime); JSONObject rtnJson = new JSONObject();
try {
List<Prescription> preScriptionList = prescriptionService.findPreScriptionList(iDisplayStart, iDisplayLength, startTime, endTime);
setSuccResult(rtnJson, preScriptionList);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
} }
...@@ -70,7 +109,14 @@ public class CdfortisController { ...@@ -70,7 +109,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 {
Prescription preScription = prescriptionService.findPreScription(presId);
setSuccResult(rtnJson, preScription);
} catch (Exception e) {
handleException(rtnJson, e);
}
return rtnJson;
} }
...@@ -82,7 +128,49 @@ public class CdfortisController { ...@@ -82,7 +128,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());
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<result column="spec" property="spec"/> <result column="spec" property="spec"/>
<result column="appr_number" property="apprNumber"/> <result column="appr_number" property="apprNumber"/>
<result column="drug_num" property="drugNum"/> <result column="drug_num" property="drugNum"/>
<result column="drug_compay" property="drugCompay"/> <result column="drug_compay" property="drugCompany"/>
<result column="name" property="name"/> <result column="name" property="name"/>
<result column="drug_id" property="drugId"/> <result column="drug_id" property="drugId"/>
<result column="parent_id" property="parentId"/> <result column="parent_id" property="parentId"/>
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
spec, spec,
appr_number, appr_number,
drug_num, drug_num,
drug_compay, drug_company,
name, name,
drug_id, drug_id,
parent_id, parent_id,
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
#{spec, jdbcType=VARCHAR}, #{spec, jdbcType=VARCHAR},
#{apprNumber, jdbcType=VARCHAR}, #{apprNumber, jdbcType=VARCHAR},
#{drugNum, jdbcType=BIGINT}, #{drugNum, jdbcType=BIGINT},
#{drugCompay, jdbcType=VARCHAR}, #{drugCompany, jdbcType=VARCHAR},
#{name, jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR},
#{drugId, jdbcType=VARCHAR}, #{drugId, jdbcType=VARCHAR},
#{parentId, jdbcType=BIGINT}, #{parentId, jdbcType=BIGINT},
...@@ -159,8 +159,8 @@ ...@@ -159,8 +159,8 @@
<if test="drugNum != null"> <if test="drugNum != null">
drug_num = #{drugNum, jdbcType=BIGINT}, drug_num = #{drugNum, jdbcType=BIGINT},
</if> </if>
<if test="drugCompay != null"> <if test="drugCompany != null">
drug_compay = #{drugCompay, jdbcType=VARCHAR}, drug_company = #{drugCompany, jdbcType=VARCHAR},
</if> </if>
<if test="name != null"> <if test="name != null">
name = #{name, jdbcType=VARCHAR}, name = #{name, jdbcType=VARCHAR},
......
...@@ -43,7 +43,7 @@ public class PreDrugs implements Serializable { ...@@ -43,7 +43,7 @@ public class PreDrugs implements Serializable {
private String price; private String price;
/* 药品生产厂家 */ /* 药品生产厂家 */
@ExportConfig(value = "药品生产厂家", width = 100, showLevel = 1) @ExportConfig(value = "药品生产厂家", width = 100, showLevel = 1)
private String drugCompay; private String drugCompany;
/* 药品名称 */ /* 药品名称 */
@ExportConfig(value = "药品名称", width = 100, showLevel = 1) @ExportConfig(value = "药品名称", width = 100, showLevel = 1)
private String name; private String name;
......
...@@ -3,6 +3,8 @@ package com.cftech.prescription.service; ...@@ -3,6 +3,8 @@ package com.cftech.prescription.service;
import com.cftech.prescription.model.Prescription; import com.cftech.prescription.model.Prescription;
import com.cftech.core.generic.GenericService; import com.cftech.core.generic.GenericService;
import java.util.List;
/** /**
* 处方单列表Service * 处方单列表Service
* *
...@@ -11,5 +13,34 @@ import com.cftech.core.generic.GenericService; ...@@ -11,5 +13,34 @@ import com.cftech.core.generic.GenericService;
*/ */
public interface PrescriptionService extends GenericService<Prescription> { public interface PrescriptionService extends GenericService<Prescription> {
/**
* 获取处方单列表(从距今日7天内的数据)
*
* @param iDisplayStart
* @param iDisplayLength
* @return
* @throws Exception
*/
List<Prescription> findPreScriptionList(int iDisplayStart, int iDisplayLength) throws Exception;
/**
* 获取处方单列表(从开始时间到结束时间的数据、间隔不能超过7天)
*
* @param iDisplayStart
* @param iDisplayLength
* @param startTime
* @param endTime
* @return
* @throws Exception
*/
List<Prescription> findPreScriptionList(int iDisplayStart, int iDisplayLength, String startTime, String endTime) throws Exception;
/**
* 获取Prescription详情
* @param presId
* @return
*/
Prescription findPreScription(String presId) throws Exception;
} }
package com.cftech.prescription.service.impl; package com.cftech.prescription.service.impl;
import com.cftech.cdfortis.model.FbusiDetail;
import com.cftech.cdfortis.model.FbusiDrug;
import com.cftech.cdfortis.service.CdfortisService;
import com.cftech.core.scope.OrderType;
import com.cftech.core.sql.Sort;
import com.cftech.core.util.DateUtils;
import com.cftech.predrugs.model.PreDrugs;
import com.cftech.predrugs.service.PreDrugsService;
import com.cftech.prescription.model.Prescription; import com.cftech.prescription.model.Prescription;
import com.cftech.prescription.dao.PrescriptionMapper; import com.cftech.prescription.dao.PrescriptionMapper;
import com.cftech.prescription.service.PrescriptionService; import com.cftech.prescription.service.PrescriptionService;
import com.cftech.core.generic.GenericDao; import com.cftech.core.generic.GenericDao;
import com.cftech.core.generic.GenericServiceImpl; import com.cftech.core.generic.GenericServiceImpl;
import com.cftech.core.sql.Conds; import com.cftech.core.sql.Conds;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.*;
import java.util.stream.Collectors;
/** /**
* 处方单列表ServiceImpl * 处方单列表ServiceImpl
...@@ -23,9 +37,134 @@ public class PrescriptionServiceImpl extends GenericServiceImpl<Prescription> im ...@@ -23,9 +37,134 @@ public class PrescriptionServiceImpl extends GenericServiceImpl<Prescription> im
@Qualifier("prescriptionMapper") @Qualifier("prescriptionMapper")
private PrescriptionMapper prescriptionMapper; private PrescriptionMapper prescriptionMapper;
@Autowired
CdfortisService cdfortisService;
@Autowired
PreDrugsService preDrugsService;
@Override @Override
public GenericDao<Prescription> getGenericMapper() { public GenericDao<Prescription> getGenericMapper() {
return prescriptionMapper; return prescriptionMapper;
} }
@Override
public List<Prescription> findPreScriptionList(int iDisplayStart, int iDisplayLength) throws Exception {
return findPreScriptionList(iDisplayStart, iDisplayLength);
}
@Override
public List<Prescription> findPreScriptionList(int iDisplayStart, int iDisplayLength, String startTime, String endTime) throws Exception {
// 时间为空,则取当天时间,并向前推7天
if (StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime)) {
// 获取当天时间、往前推7天
Date endDate = new Date();
Date startDate = DateUtils.addDays(endDate, -7);
// 修改开始时间为00:00:00,结束时间为23:59:59
startDate = DateUtils.getDateStart(startDate);
endDate = DateUtils.getDateEnd(endDate);
// 给开始时间和结束时间赋值
startTime = DateUtils.formatDateTime(startDate);
endTime = DateUtils.formatDateTime(endDate);
}
Sort sort = new Sort("create_time", OrderType.DESC);
// TODO 查询在时间范围内的数据
Conds listConds = new Conds();
// listConds.between("start_time", startTime, endTime);
List<Prescription> prescriptions = fetchSearchByPage(listConds, sort, iDisplayStart, iDisplayLength);
// 如果数据存在,则直接返回,如果不存在,则返回空数组
if (!CollectionUtils.isEmpty(prescriptions)) {
return prescriptions;
}
// 获取微问诊数据
List<Prescription> onLineList = cdfortisService.getFbusiList(iDisplayStart, iDisplayLength, startTime, endTime);
// 如果线上数据不存在则直接返回空数组
if (CollectionUtils.isEmpty(onLineList)) {
return new ArrayList<>();
}
// 构建查询参数
Long[] idArr = onLineList.stream().map(Prescription::getId).toArray(Long[]::new);
Conds idConds = new Conds();
idConds.in("id", idArr);
// 将db里面数据查询出来转成Set,数据为id
Set<Long> dbIdSet = fetchSearchByPage(idConds, sort, iDisplayStart, iDisplayLength)
.stream()
.map(Prescription::getId)
.collect(Collectors.toSet());
// 遍历接口返回数据,如果存在db中则调用更新,如果不存在则调用保存
for (Prescription prescription : onLineList) {
// 存在db中,则更新
if (dbIdSet.contains(prescription.getId())) {
update(prescription);
} else {
save(prescription);
}
}
return onLineList;
}
@Override
public Prescription findPreScription(String presId) throws Exception {
Prescription prescription = fetchById(presId);
if (prescription != null && !StringUtils.isEmpty(prescription.getSymptom())) {
return prescription;
}
FbusiDetail fbusiDetail = cdfortisService.getFbusiDetail(presId);
if (fbusiDetail == null) {
throw new Exception("找不到对应的处方数据");
}
if (prescription == null) {
// save数据
prescription = new Prescription();
BeanUtils.copyProperties(fbusiDetail, prescription);
save(prescription);
} else {
// update 数据
BeanUtils.copyProperties(fbusiDetail, prescription);
update(prescription);
}
handleFrug(fbusiDetail, prescription);
return prescription;
}
/**
* 处理处方单中的药品信息逻辑(存在则更新,不存在则新增)
*
* @param fbusiDetail
* @param prescription
*/
private void handleFrug(FbusiDetail fbusiDetail, Prescription prescription) {
List<FbusiDrug> drugs = fbusiDetail.getDrugs();
List<PreDrugs> preDrugsList = new ArrayList<>();
if (CollectionUtils.isEmpty(drugs)) {
return;
}
Conds drugConds = new Conds();
drugConds.equal("parent_id", prescription.getId());
int count = preDrugsService.count(drugConds);
if (count != 0) {
Sort sort = new Sort("create_time", OrderType.DESC);
preDrugsList = preDrugsService.fetchSearchByPage(drugConds, sort, 0, count);
}
Map<String, PreDrugs> preDrugMap = preDrugsList.stream().collect(Collectors.toMap(PreDrugs::getDrugId, preDrugs -> preDrugs));
for (FbusiDrug fbusiDrug : drugs) {
PreDrugs preDrug = new PreDrugs();
if (preDrugMap.containsKey(fbusiDrug.getDrugId())) {
preDrug = preDrugMap.get(fbusiDrug.getDrugId());
BeanUtils.copyProperties(fbusiDrug, preDrug);
preDrug.setName(fbusiDrug.getDrugName());
preDrug.setParentId(prescription.getId());
preDrugsService.update(preDrug);
} else {
BeanUtils.copyProperties(fbusiDrug, preDrug);
preDrug.setName(fbusiDrug.getDrugName());
preDrug.setParentId(prescription.getId());
preDrugsService.save(preDrug);
}
}
}
} }
\ No newline at end of file
...@@ -6,16 +6,17 @@ POST http://localhost:8080/aidea/mobile/auth/cdfortis/upload/druginfo ...@@ -6,16 +6,17 @@ 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": "江苏艾迪药业股份有限公司"
}] }]
### 获取图文处方列表接口 ### 获取图文处方列表接口
GET http://localhost:8080/aidea/mobile/auth/cdfortis/get/fbusi/list?iDisplayStart=1&iDisplayLength=10&startTime=2021-08-03 00:00:00&endTime=2021-08-03 20:59:59 GET http://localhost:8080/aidea/mobile/auth/cdfortis/get/fbusi/list?iDisplayStart=0&iDisplayLength=10&startTime=2021-08-03 00:00:00&endTime=2021-08-03 20:59:59
#GET http://localhost:8080/aidea/mobile/auth/cdfortis/get/fbusi/list?iDisplayStart=1&iDisplayLength=10
### 获取图文处方图片 ### 获取图文处方图片
GET http://localhost:8080/aidea/mobile/auth/cdfortis/get/fbusi/picture?presId=11264635 GET http://localhost:8080/aidea/mobile/auth/cdfortis/get/fbusi/picture?presId=11264635
......
...@@ -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