package com.docus.server.ws;

import com.docus.server.collect.service.CollectService;
import com.docus.server.collect.service.IParseService;
import com.docus.server.record.pojo.entity.MedicalRecord;
import com.docus.server.record.service.IMedicalRecordService;
import com.docus.server.sys.common.pojo.dto.DeptDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class WsCollect {
    @Autowired
    private IMedicalRecordService medicalRecordService;
    @Autowired
    private IParseService parseService;
    @Autowired
    private CollectService collectService;
    @Autowired
    private IWsResult wsResult;


    //接收xml。并且下载病案。
    public String receiveHandNumbness(String handNumbness) {
        log.info("收到手麻消息：{}", handNumbness);
        try {
            MedicalRecord medicalRecord = parseService.parseHandNumbness(handNumbness);
            medicalRecordService.receive(medicalRecord);
            return wsResult.ok(medicalRecord.getParams());
        } catch (Exception e) {
            return wsResult.fail(e.getMessage());
        }
    }

    public String receiveDept(String deptXml) {
        log.info("收到科室消息：{}", deptXml);
        try {
            DeptDTO dept = parseService.parseDeptXml(deptXml);

            //此处需要存储原xml内容。
            collectService.receiveDept(dept);
            return wsResult.ok(dept.getParams());
        } catch (Exception e) {
            return wsResult.fail(e.getMessage(), dept.getParams());
        }
    }


}
