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 {
* 成功的返回值
*/
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;
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;
}
......@@ -2,6 +2,7 @@ package com.cftech.cdfortis.util;
import com.alibaba.fastjson.JSONObject;
import com.cftech.cdfortis.constants.CdfortisConstant;
import com.cftech.core.util.SystemConfig;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
......@@ -37,7 +38,8 @@ public class CdfortisResponseUtil {
*/
public static void checkResponse(JSONObject retObj) throws Exception {
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());
throw new Exception(returnCode.getString(CdfortisConstant.RETURN_CODE_CONTENT));
}
......@@ -52,11 +54,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,27 +76,25 @@ 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;
}
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());
Response response = client.newCall(builder.build()).execute();
// 判断http状态值
if (CdfortisConstant.HTTP_SUCC != response.code()) {
log.error(response.message());
throw new Exception("微问诊请求失败");
}
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;
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.prescription.service.PrescriptionService;
import com.cftech.product.model.Product;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -24,6 +29,12 @@ public class CdfortisController {
@Autowired
CdfortisService cdfortisService;
@Autowired
CdfortisTokenUtil cdfortisTokenUtil;
@Autowired
PrescriptionService prescriptionService;
/**
* 获取微问诊token
*
......@@ -31,7 +42,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 +62,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;
}
......@@ -57,8 +89,15 @@ public class CdfortisController {
* @return
*/
@GetMapping("/get/fbusi/list")
public JSONObject getFbusiList(int iDisplayStart, int iDisplayLength, @RequestParam String startTime, @RequestParam String endTime) {
return cdfortisService.getFbusiList(iDisplayStart, iDisplayLength, startTime, endTime);
public JSONObject getFbusiList(int iDisplayStart, int iDisplayLength, String startTime, String 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 {
*/
@GetMapping("/get/fbusi/detail")
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 {
*/
@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());
}
......
......@@ -11,7 +11,7 @@
<result column="spec" property="spec"/>
<result column="appr_number" property="apprNumber"/>
<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="drug_id" property="drugId"/>
<result column="parent_id" property="parentId"/>
......@@ -62,7 +62,7 @@
spec,
appr_number,
drug_num,
drug_compay,
drug_company,
name,
drug_id,
parent_id,
......@@ -94,7 +94,7 @@
#{spec, jdbcType=VARCHAR},
#{apprNumber, jdbcType=VARCHAR},
#{drugNum, jdbcType=BIGINT},
#{drugCompay, jdbcType=VARCHAR},
#{drugCompany, jdbcType=VARCHAR},
#{name, jdbcType=VARCHAR},
#{drugId, jdbcType=VARCHAR},
#{parentId, jdbcType=BIGINT},
......@@ -159,8 +159,8 @@
<if test="drugNum != null">
drug_num = #{drugNum, jdbcType=BIGINT},
</if>
<if test="drugCompay != null">
drug_compay = #{drugCompay, jdbcType=VARCHAR},
<if test="drugCompany != null">
drug_company = #{drugCompany, jdbcType=VARCHAR},
</if>
<if test="name != null">
name = #{name, jdbcType=VARCHAR},
......
......@@ -43,7 +43,7 @@ public class PreDrugs implements Serializable {
private String price;
/* 药品生产厂家 */
@ExportConfig(value = "药品生产厂家", width = 100, showLevel = 1)
private String drugCompay;
private String drugCompany;
/* 药品名称 */
@ExportConfig(value = "药品名称", width = 100, showLevel = 1)
private String name;
......
......@@ -3,6 +3,8 @@ package com.cftech.prescription.service;
import com.cftech.prescription.model.Prescription;
import com.cftech.core.generic.GenericService;
import java.util.List;
/**
* 处方单列表Service
*
......@@ -11,5 +13,34 @@ import com.cftech.core.generic.GenericService;
*/
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;
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.dao.PrescriptionMapper;
import com.cftech.prescription.service.PrescriptionService;
import com.cftech.core.generic.GenericDao;
import com.cftech.core.generic.GenericServiceImpl;
import com.cftech.core.sql.Conds;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* 处方单列表ServiceImpl
......@@ -23,9 +37,134 @@ public class PrescriptionServiceImpl extends GenericServiceImpl<Prescription> im
@Qualifier("prescriptionMapper")
private PrescriptionMapper prescriptionMapper;
@Autowired
CdfortisService cdfortisService;
@Autowired
PreDrugsService preDrugsService;
@Override
public GenericDao<Prescription> getGenericMapper() {
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
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": "江苏艾迪药业股份有限公司"
}]
### 获取图文处方列表接口
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
......
......@@ -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