ReportService.java 3.01 KB
package com.xkl.service;

import com.alibaba.fastjson.JSONObject;
import com.xkl.domain.AMPReport;
import com.xkl.domain.AMPReportDetail;
import com.xkl.domain.ReportData;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhao yue on 2016/11/13.
 */
@Service
public class ReportService {
    /*
    1. 验证md5
    3. 获取report
    4. 获取detail
    5. 评判detail
    1. 验证member
    2. 获取admin
     */
    // 需要程喆增加 title,account字段,String,修改set字段为int,0男,1女。
    public ReportData parseReport(String reportJson, String md5) {
        ReportData reportData = new ReportData();
        AMPReport ampReport = new AMPReport();
        List<AMPReportDetail> detailList = new ArrayList<>();
        /*
         * 获取report基础信息
         */
        try {
            JSONObject rpJson = JSONObject.parseObject(reportJson);
            ampReport.setReport(rpJson.getString("name"),
                    rpJson.getString("title"),///                    "AMP快速无创身心健康评估报告",
                    rpJson.getTimestamp("report_date"),
                    new Timestamp(System.currentTimeMillis()),
                    rpJson.getString("account"),///
                    rpJson.getInteger("sex").intValue(),///
                    rpJson.getInteger("age").intValue(),
                    rpJson.getInteger("weight").intValue(),
                    rpJson.getInteger("pulse").intValue(),
                    rpJson.getInteger("respiratory_rate").intValue(),
                    rpJson.getInteger("atmospheric_pressure").intValue(),
                    rpJson.getFloat("LCA").floatValue(),
                    rpJson.getFloat("RCA").floatValue(),
                    rpJson.getFloat("LAC").floatValue(),
                    rpJson.getFloat("RAC").floatValue(),
                    rpJson.getFloat("ABD").floatValue(),
                    rpJson.getFloat("total").floatValue(),
                    rpJson.getInteger("stable").intValue(),
                    md5, rpJson.getString("basic_result"));
            /*
             * 获取detail信息
             */
            JSONObject rpDetails = rpJson.getJSONObject("detail");
            for (int item_id = 1; item_id <= 125; item_id++) {
                String val = rpDetails.getString(String.valueOf(item_id));
                if (val == null || val.equals("")) {
                    continue;
                }
                val = val.trim().replace(" ", "").replace("``", "").replace("`", ".");
                float valFloat = Float.parseFloat(val);
                AMPReportDetail detail = new AMPReportDetail();
                detail.setItem_value(valFloat);
                detail.setItem_id(item_id);
                detailList.add(detail);
            }
        } catch (Exception e) {
            return null;
        }
        reportData.setAmpReport(ampReport);
        reportData.setRpDetailList(detailList);
        return reportData;
    }
}