Commit e65f1e0c authored by 马超's avatar 马超

feat(微问诊): 列表接口添加业务逻辑

parent a735366f
......@@ -15,6 +15,7 @@ public class CdfortisConstant {
* 成功的返回值
*/
public static String RESULT_SUCC_CODE = "C00010000";
public static String RESULT_NO_DATA_CODE = "C00030016";
/**
......
......@@ -9,6 +9,7 @@ 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.StringUtils;
import com.cftech.core.util.SystemConfig;
import com.cftech.prescription.model.Prescription;
import com.cftech.product.model.Product;
......@@ -91,12 +92,18 @@ public class CdfortisServiceImpl implements CdfortisService {
// 请求获取数据
String dataStr = CdfortisResponseUtil.request(getFbusiListUrl, CdfortisConstant.METHOD_GET, urlParam,
null, null);
// 没数据时的解决方案 C00030016
if (StringUtils.isEmpty(dataStr)) {
return new ArrayList<>();
}
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);
}
......
......@@ -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));
}
......@@ -85,7 +87,12 @@ public class CdfortisResponseUtil {
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");
}
......
......@@ -6,6 +6,7 @@ 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;
......@@ -31,6 +32,9 @@ public class CdfortisController {
@Autowired
CdfortisTokenUtil cdfortisTokenUtil;
@Autowired
PrescriptionService prescriptionService;
/**
* 获取微问诊token
*
......@@ -85,11 +89,11 @@ public class CdfortisController {
* @return
*/
@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) {
JSONObject rtnJson = new JSONObject();
try {
List<Prescription> fbusiList = cdfortisService.getFbusiList(iDisplayStart, iDisplayLength, startTime, endTime);
setSuccResult(rtnJson, fbusiList);
List<Prescription> preScriptionList = prescriptionService.findPreScriptionList(iDisplayStart, iDisplayLength, startTime, endTime);
setSuccResult(rtnJson, preScriptionList);
} catch (Exception e) {
handleException(rtnJson, e);
}
......
......@@ -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,27 @@ 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;
}
package com.cftech.prescription.service.impl;
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.prescription.model.Prescription;
import com.cftech.prescription.dao.PrescriptionMapper;
import com.cftech.prescription.service.PrescriptionService;
......@@ -9,6 +13,14 @@ import com.cftech.core.sql.Conds;
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.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 处方单列表ServiceImpl
......@@ -23,9 +35,70 @@ public class PrescriptionServiceImpl extends GenericServiceImpl<Prescription> im
@Qualifier("prescriptionMapper")
private PrescriptionMapper prescriptionMapper;
@Autowired
CdfortisService cdfortisService;
@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);
// 查询在时间范围内的数据
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;
}
}
\ No newline at end of file
......@@ -15,7 +15,8 @@ Content-Type: application/json
}]
### 获取图文处方列表接口
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
......
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