@Slf4j
@Validated
@RestController
@RequestMapping("/elderlyReferralInfo")
@Api(value = "elderlyReferralInfo", tags = "康养联合体转介转养")
public class ElderlyReferralInfoController {
@Autowired
private EchoService echoService;
@Value("${kylht.baseUrl}")
private String kylhtBaseUrl;
@ApiOperation(value = "康养联合体-机构列表")
@GetMapping(value = "/getHealthDeptList")
public R<List<HealthDeptDTO>> getHealthDeptList(HttpServletResponse servletResponse, HealthDeptDTO dto) {
try {
String body = HttpUtil.createGet(kylhtBaseUrl + "/health-care/data/healthDept/queryDeptByName")
.form("deptName",dto.getDeptName())
.form("idcard",dto.getIdCard())
.execute().body();
JSONObject jsonObject = JSONUtil.parseObj(body);
List<HealthDeptDTO> list = new ArrayList<>();
if (jsonObject.getStr("success").equals("true")) {
JSONArray object = jsonObject.getJSONArray("result");
list = JSONUtil.toList (object, HealthDeptDTO.class);
}
return R.success(list);
} catch (Exception e) {
return R.success(Collections.emptyList());
}
}
@ApiOperation("康养联合体-历史记录列表")
@GetMapping("/getReferralInfoList")
public R<IPage<ReferralInfoDTO>> getReferralInfoList(HttpServletResponse response, ReferralInfoDTO dto,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
IPage<ReferralInfoDTO> iPage = new Page<>(pageNo,pageSize);
try {
String body = HttpUtil.createGet(kylhtBaseUrl + "/health-care/data/referralInfo/list")
.form("idcard", dto.getIdcard())
.execute().body();
JSONObject jsonObject = JSONUtil.parseObj(body);
if (jsonObject.getStr("success").equals("true")) {
JSONObject result = jsonObject.getJSONObject("result");
Object records = result.get("records");
JSONArray objects = new JSONArray(records);
List<ReferralInfoDTO> toList = JSONUtil.toList(objects,
ReferralInfoDTO.class);
iPage.setRecords(toList);
iPage.setTotal(toList.size());
}
return R.success(iPage);
} catch (Exception e) {
return R.success(iPage);
}
}
@ApiOperation("历史记录详情")
@GetMapping("/getReferralInfoById")
public ReferralInfoDTO getReferralInfoById(HttpServletResponse response,@RequestParam String id){
ReferralInfoDTO infoDTO = new ReferralInfoDTO();
try {
String body = HttpUtil.createGet(
kylhtBaseUrl + "/health-care/data/referralInfo/queryById")
.form("id",id).execute().body();
JSONObject jsonObject = JSONUtil.parseObj(body);
if (jsonObject.getStr("success").equals("true")) {
JSONObject result = jsonObject.getJSONObject("result");
infoDTO = JSONUtil.toBean(result, ReferralInfoDTO.class);
JSONObject oldPerson = result.getJSONObject("oldPerson");
infoDTO.setDepart(oldPerson.getStr("depart"));;
}
return infoDTO;
}catch (Exception e){
return infoDTO;
}
}
@ApiOperation("转介转养申请")
@PostMapping("/apply")
public R<String> apply(HttpServletResponse response,@RequestBody ReferralInfoDTO dto){
String str = null;
try {
HashMap<Object, Object> map = new HashMap<>();
map.put("applyDept", dto.getApplyDept());
map.put("applyTime", dto.getApplyTime());
map.put("applyItem", dto.getApplyItem());
map.put("applyReason", dto.getApplyReason());
map.put("applyType", dto.getApplyType());
map.put("depart", dto.getDepart());
map.put("idcard", dto.getIdcard());
map.put("name", dto.getName());
map.put("approvalProgress","待审核");
String body = HttpUtil.createPost(kylhtBaseUrl + "/health-care/data/referralInfo/add")
.body(JSONUtil.toJsonStr(map))
.execute().body();
JSONObject jsonObject = JSONUtil.parseObj(body);
if (jsonObject.getStr("success").equals("true")){
str = jsonObject.getStr("result");
}
return R.success(str);
}catch (Exception e){
return R.success(str);
}
}
}