Prechádzať zdrojové kódy

Merge branch 'dev' of yeshijie/patient-co-management into dev

lyr 8 rokov pred
rodič
commit
4e03a771d7

+ 139 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/httpLog/HttpLog.java

@ -0,0 +1,139 @@
package com.yihu.wlyy.entity.httpLog;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/** http交互日志
 * Created by yeshijie on 2017/1/12.
 */
@Entity
@Table(name = "wlyy_http_log")
public class HttpLog extends IdEntity{
    // 接口类型 0对外接口 1基卫接口 2健康网接口
    private String type;
    // 业务内容
    private String content;
    // 调用接口
    private String api;
    // 调用方式
    private String method;
    // 调用参数
    private String params;
    // 调用头部信息
    private String header;
    // 返回结果
    private String response;
    // 状态 0失败 1成功 2已重试
    private String status;
    // 重试次数
    private Integer retryTimes;
    // 创建时间
    private Date createTime;
    //异常信息
    private String error;
    @Column(name = "type")
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    @Column(name = "content")
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    @Column(name = "api")
    public String getApi() {
        return api;
    }
    public void setApi(String api) {
        this.api = api;
    }
    @Column(name = "method")
    public String getMethod() {
        return method;
    }
    public void setMethod(String method) {
        this.method = method;
    }
    @Column(name = "params")
    public String getParams() {
        return params;
    }
    public void setParams(String params) {
        this.params = params;
    }
    @Column(name = "header")
    public String getHeader() {
        return header;
    }
    public void setHeader(String header) {
        this.header = header;
    }
    @Column(name = "response")
    public String getResponse() {
        return response;
    }
    public void setResponse(String response) {
        this.response = response;
    }
    @Column(name = "status")
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    @Column(name = "retry_times")
    public Integer getRetryTimes() {
        return retryTimes;
    }
    public void setRetryTimes(Integer retryTimes) {
        this.retryTimes = retryTimes;
    }
    @Column(name = "create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    @Column(name = "error")
    public String getError() {
        return error;
    }
    public void setError(String error) {
        this.error = error;
    }
}

+ 12 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/httplog/HttpLogDao.java

@ -0,0 +1,12 @@
package com.yihu.wlyy.repository.httplog;
import com.yihu.wlyy.entity.httpLog.HttpLog;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by yeshijie on 2017/1/12.
 */
public interface HttpLogDao extends PagingAndSortingRepository<HttpLog, Long>,JpaSpecificationExecutor<HttpLog> {
}

+ 25 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/system/SystemDictService.java

@ -2,9 +2,7 @@ package com.yihu.wlyy.service.system;
import com.yihu.wlyy.entity.dict.SystemDict;
import com.yihu.wlyy.repository.dict.SystemDictDao;
import com.yihu.wlyy.repository.dict.SystemDictListDao;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
@ -25,6 +23,7 @@ public class SystemDictService {
        return systemDictDao.findByDictName(name);
    }
    private String dictName =  "SYSTEM_PARAMS";
    /**
     * 字典转译
@ -67,4 +66,28 @@ public class SystemDictService {
        }
        return re;
    }
    /************************************** 其他参数 ****************************************/
    /**
     * http_log是否记录成功消息
     * @return
     */
    public Boolean getSaveSuccessLog()
    {
        try{
            String re = systemDictDao.findByDictNameAndCode(dictName, "SAVE_SUCCESS_LOG");
            if("1".equals(re))
            {
                return true;
            }
            else{
                return false;
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            return false;
        }
    }
}

+ 198 - 110
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/guahao/GuahaoXMService.java

@ -9,6 +9,7 @@ import com.yihu.wlyy.repository.patient.PatientReservationDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.app.consult.ConsultService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.third.httplog.LogService;
import com.yihu.wlyy.service.third.jw.JwSmjkService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.SOAPUtil;
@ -54,6 +55,9 @@ public class GuahaoXMService implements IGuahaoService {
    @Autowired
    SignFamilyDao signFamilyDao;
    @Autowired
    private LogService logService;
    @Autowired
    private ConsultService consultService;
@ -192,6 +196,37 @@ public class GuahaoXMService implements IGuahaoService {
    /***********************************************************************************************************************************************/
    /**
     * xml验证,并保存日志
     * @param url
     * @param content
     * @param method
     * @param msgBody
     * @param res
     */
    private void  verificationXml(String xml,String title,String url,String content,String method,String msgBody,String res) throws Exception{
        String error = "";
        Boolean isSuccess = false;
        if (StringUtils.isEmpty(xml)) {
            // 请求失败
            //保存http日志
            error = title;
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,"2");
            throw new Exception(error);
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            //保存http日志
            error = xml.substring(xml.indexOf(":") + 1, xml.length());
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,"2");
            throw new Exception(error);
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            //保存http日志
            error = xml.substring(xml.indexOf(":") + 1, xml.length());
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,"2");
            throw new Exception(error);
        }
    }
    /**
     * 获取医院列表
     */
@ -226,17 +261,18 @@ public class GuahaoXMService implements IGuahaoService {
            param3.put("value", values[2]);
            params.put(param3);
            //新增日志
            String method = "POST";
            String content = "获取医院列表";
            Long startTime = System.currentTimeMillis();
            String xml = SOAPUtil.post(ORG_LIST, params);
            if (StringUtils.isEmpty(xml)) {
                // 请求失败
                throw new Exception("获取机构列表失败!");
            } else if (StringUtils.startsWith(xml, "System-Error")) {
                // 调用失败
                throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
            } else if (StringUtils.startsWith(xml, "Error")) {
                // 调用失败
                throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
            }
            Long spendTime = (System.currentTimeMillis()-startTime)/1000;//计算请求时间
            String res = "耗时:"+spendTime+"s,xml="+xml;
            String msgBody = params.toString();
            //xml验证
            verificationXml(xml,"获取机构列表失败!",ORG_LIST,content,method,msgBody,res);
            Document document = DocumentHelper.parseText(xml);
            Element root = document.getRootElement();
            List<?> child = root.elements();
@ -254,6 +290,9 @@ public class GuahaoXMService implements IGuahaoService {
                re.add(map);
            }
            //保存http日志
            logService.saveHttpLog(true,ORG_LIST,content,method,null,msgBody,res,null,"2");
        }
        return re;
    }
@ -270,17 +309,17 @@ public class GuahaoXMService implements IGuahaoService {
        param1.put("value", hospitalId);
        params.put(param1);
        //新增日志
        String method = "POST";
        String content = "获取科室接口";
        Long startTime = System.currentTimeMillis();
        String xml = SOAPUtil.post(DEP_LIST, params);
        if (StringUtils.isEmpty(xml)) {
            // 请求失败
            throw new Exception("获取可预约科室列表失败!");
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        Long spendTime = (System.currentTimeMillis()-startTime)/1000;//计算请求时间
        String res = "耗时:"+spendTime+"s,xml="+xml;
        String msgBody = params.toString();
        //xml验证
        verificationXml(xml,"获取可预约科室列表失败!",DEP_LIST,content,method,msgBody,res);
        Document document = DocumentHelper.parseText(xml);
        Element root = document.getRootElement();
        List<?> child = root.elements();
@ -296,6 +335,10 @@ public class GuahaoXMService implements IGuahaoService {
                re.add(map);
            }
        }
        //保存http日志
        logService.saveHttpLog(true,DEP_LIST,content,method,null,msgBody,res,null,"2");
        return re;
    }
@ -327,17 +370,17 @@ public class GuahaoXMService implements IGuahaoService {
        param4.put("value", DateUtil.getNextDay(nowDate, nextDays));  //一周后时间
        params.put(param4);
        //新增日志
        String method = "POST";
        String content = "获取医生列表接口";
        Long startTime = System.currentTimeMillis();
        String xml = SOAPUtil.post(DOCTOR_LIST, params);
        if (StringUtils.isEmpty(xml)) {
            // 请求失败
            throw new Exception("获取医生列表失败!");
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        Long spendTime = (System.currentTimeMillis()-startTime)/1000;//计算请求时间
        String res = "耗时:"+spendTime+"s,xml="+xml;
        String msgBody = params.toString();
        //xml验证
        verificationXml(xml,"获取医生列表失败!",DOCTOR_LIST,content,method,msgBody,res);
        Document document = DocumentHelper.parseText(xml);
        Element root = document.getRootElement();
        List<?> child = root.elements();
@ -385,6 +428,10 @@ public class GuahaoXMService implements IGuahaoService {
            doctor.setHospitalName(orgname);
            re.add(doctor);
        }
        //保存http日志
        logService.saveHttpLog(true,DOCTOR_LIST,content,method,null,msgBody,res,null,"2");
        return re;
    }
@ -421,7 +468,19 @@ public class GuahaoXMService implements IGuahaoService {
        param5.put("value", DateUtil.getNextDay(nowDate, nextDays));  //一周后时间
        params.put(param5);
        //新增日志
        String method = "POST";
        String content = "获取医生排班接口(包含排班详细)";
        Long startTime = System.currentTimeMillis();
        String xml = SOAPUtil.post(DOCTOR_ARRANGE, params);
        Long spendTime = (System.currentTimeMillis()-startTime)/1000;//计算请求时间
        String res = "耗时:"+spendTime+"s,xml="+xml;
        String msgBody = params.toString();
        //xml验证
        verificationXml(xml,"获取医生排班表失败!",DOCTOR_ARRANGE,content,method,msgBody,res);
        //保存http日志
        logService.saveHttpLog(true,DOCTOR_ARRANGE,content,method,null,msgBody,res,null,"2");
        return xmlToList(xml);
    }
@ -460,17 +519,17 @@ public class GuahaoXMService implements IGuahaoService {
        param5.put("value", DateUtil.getNextDay(nowDate, nextDays));  //一周后时间
        params.put(param5);
        //新增日志
        String method = "POST";
        String content = "获取医生排班接口(一级)";
        Long startTime = System.currentTimeMillis();
        String xml = SOAPUtil.post(DOCTOR_ARRANGE_SIMPLE, params);
        if (StringUtils.isEmpty(xml)) {
            // 请求失败
            throw new Exception("获取医生排班表失败!");
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        Long spendTime = (System.currentTimeMillis()-startTime)/1000;//计算请求时间
        String res = "耗时:"+spendTime+"s,xml="+xml;
        String msgBody = params.toString();
        //xml验证
        verificationXml(xml,"获取医生排班表失败!",DOCTOR_ARRANGE_SIMPLE,content,method,msgBody,res);
        Document document = DocumentHelper.parseText(xml);
        Element root = document.getRootElement();
        List<?> child = root.elements();
@ -495,6 +554,10 @@ public class GuahaoXMService implements IGuahaoService {
            re.add(map);
        }
        //保存http日志
        logService.saveHttpLog(true,DOCTOR_ARRANGE_SIMPLE,content,method,null,msgBody,res,null,"2");
        return re;
    }
@ -550,18 +613,18 @@ public class GuahaoXMService implements IGuahaoService {
            param3.put("value", values[2]);
            params.put(param3);
            //新增日志
            String method = "POST";
            String content = "创建挂号单";
            Long startTimes = System.currentTimeMillis();
            String response = SOAPUtil.post(ORDER_CREATE, params);
            if (StringUtils.isEmpty(response)) {
                // 请求失败
                throw new Exception("请求失败!");
            } else if (StringUtils.startsWith(response, "System-Error")) {
                // 调用失败
                throw new Exception(response.substring(response.indexOf(":") + 1, response.length()));
            } else if (StringUtils.startsWith(response, "Error")) {
                // 调用失败
                throw new Exception(response.substring(response.indexOf(":") + 1, response.length()));
            }
            Long spendTime = (System.currentTimeMillis()-startTimes)/1000;//计算请求时间
            String res = "耗时:"+spendTime+"s,xml="+response;
            String msgBody = params.toString();
            //xml验证
            verificationXml(response,"获取医生排班表失败!",ORDER_CREATE,content,method,msgBody,res);
            //保存http日志
            logService.saveHttpLog(true,ORDER_CREATE,content,method,null,msgBody,res,null,"2");
            re = CreateOrderAfter(response, hospitalId, hospitalName, hosDeptId, hosDeptName, doctorId, doctorName, sectionType, startTime, endTime, patient, patientName, cardNo, clinicCard, patientPhone, null, null);
        } else {
            throw new Exception("该排班信息错误或者不存在!");
@ -599,23 +662,26 @@ public class GuahaoXMService implements IGuahaoService {
        param4.put("value", values[2]);
        params.put(param4);
        //新增日志
        String method = "POST";
        String content = "取消挂号单";
        Long startTime = System.currentTimeMillis();
        String xml = SOAPUtil.post(ORDER_CANCEL, params);
        if (StringUtils.isEmpty(xml)) {
            // 请求失败
            throw new Exception("取消挂号失败!");
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        if (xml.toLowerCase().startsWith("ok")) {
        Long spendTime = (System.currentTimeMillis()-startTime)/1000;//计算请求时间
        String res = "耗时:"+spendTime+"s,xml="+xml;
        String msgBody = params.toString();
        //xml验证
        verificationXml(xml,"取消挂号失败!",ORDER_CANCEL,content,method,msgBody,res);
            return true;
        } else {
            return false;
        Boolean isOk = false;
        if (xml.toLowerCase().startsWith("ok")) {
            isOk =  true;
        }
        //保存http日志
        logService.saveHttpLog(isOk,ORDER_CANCEL,content,method,null,msgBody,res,null,"2");
        return isOk;
    }
    /**
@ -643,17 +709,17 @@ public class GuahaoXMService implements IGuahaoService {
        param4.put("value", DateUtil.getNextDay(nowDate, nextDays));  //一周后时间
        params.put(param4);
        //新增日志
        String method = "POST";
        String content = "获取医生信息";
        Long startTime = System.currentTimeMillis();
        String xml = SOAPUtil.post(DOCTOR_LIST, params);
        if (StringUtils.isEmpty(xml)) {
            // 请求失败
            throw new Exception("获取医生列表失败!");
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        Long spendTime = (System.currentTimeMillis()-startTime)/1000;//计算请求时间
        String res = "耗时:"+spendTime+"s,xml="+xml;
        String msgBody = params.toString();
        //xml验证
        verificationXml(xml,"获取医生列表失败!",DOCTOR_LIST,content,method,msgBody,res);
        Document document = DocumentHelper.parseText(xml);
        Element root = document.getRootElement();
        List<?> child = root.elements();
@ -704,6 +770,10 @@ public class GuahaoXMService implements IGuahaoService {
                break;
            }
        }
        //保存http日志
        logService.saveHttpLog(true,DOCTOR_LIST,content,method,null,msgBody,res,null,"2");
        return doctor;
    }
@ -741,17 +811,17 @@ public class GuahaoXMService implements IGuahaoService {
            param3.put("value", values[2]);
            params.put(param3);
            //新增日志
            String method = "POST";
            String content = "获取预约状态";
            Long startTime = System.currentTimeMillis();
            String xml = SOAPUtil.post(ORDER_INFO, params);
            if (StringUtils.isEmpty(xml)) {
                // 请求失败
                throw new Exception("获取预约状态失败!");
            } else if (StringUtils.startsWith(xml, "System-Error")) {
                // 调用失败
                throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
            } else if (StringUtils.startsWith(xml, "Error")) {
                // 调用失败
                throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
            }
            Long spendTime = (System.currentTimeMillis()-startTime)/1000;//计算请求时间
            String res = "耗时:"+spendTime+"s,xml="+xml;
            String msgBody = params.toString();
            String errMsg = "获取预约状态失败!";
            //xml验证
            verificationXml(xml,errMsg,ORDER_INFO,content,method,msgBody,res);
            Document document = DocumentHelper.parseText(xml);
            Element root = document.getRootElement();
@ -778,8 +848,13 @@ public class GuahaoXMService implements IGuahaoService {
                        break;
                    }
                }
                //保存http日志
                logService.saveHttpLog(true,ORDER_INFO,content,method,null,msgBody,res,null,"2");
            } else {
                throw new Exception("获取预约状态失败!");
                //保存http日志
                logService.saveHttpLog(false,ORDER_INFO,content,method,null,msgBody,res,errMsg,"2");
                throw new Exception(errMsg);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
@ -821,17 +896,19 @@ public class GuahaoXMService implements IGuahaoService {
        param5.put("key", "?strKey");
        param5.put("value", values[2]);  //一周后时间
        params.put(param5);
        //新增日志
        String method = "POST";
        String content = "根据患者医保卡获取近三个月的预约记录";
        Long startTime = System.currentTimeMillis();
        String xml = SOAPUtil.post(REG_LIST, params);
        if (StringUtils.isEmpty(xml)) {
            // 请求失败
            throw new Exception("获取挂号信息失败!");
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        Long spendTime = (System.currentTimeMillis()-startTime)/1000;//计算请求时间
        String res = "耗时:"+spendTime+"s,xml="+xml;
        String msgBody = params.toString();
        String errMsg = "获取挂号信息失败!";
        //xml验证
        verificationXml(xml,errMsg,REG_LIST,content,method,msgBody,res);
        Document document = DocumentHelper.parseText(xml);
        Element root = document.getRootElement();
        List<?> child = root.elements();
@ -900,6 +977,10 @@ public class GuahaoXMService implements IGuahaoService {
                patientRegList.add(patientReservation);
            }
        }
        //保存http日志
        logService.saveHttpLog(true,REG_LIST,content,method,null,msgBody,res,null,"2");
        return patientRegList;
    }
@ -909,6 +990,10 @@ public class GuahaoXMService implements IGuahaoService {
    public PatientReservation getRegDetail(String patientCode, String orgCode, String regCode) throws Exception {
        //获取签名信息
        Patient patient = patientService.findByCode(patientCode);
        if (patient == null) {
            throw new Exception("获取挂号人员信息失败!");
        }
        StringBuffer sb = new StringBuffer();
        sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        sb.append("<root>");
@ -933,25 +1018,22 @@ public class GuahaoXMService implements IGuahaoService {
        param3.put("value", values[2]);
        params.put(param3);
        //新增日志
        String method = "POST";
        String content = "获取单条记录预约记录";
        Long startTime = System.currentTimeMillis();
        String xml = SOAPUtil.post(ORDER_INFO, params);
        if (StringUtils.isEmpty(xml)) {
            // 请求失败
            throw new Exception("获取挂号信息失败!");
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            throw new Exception(xml.substring(xml.indexOf(":") + 1, xml.length()));
        }
        Long spendTime = (System.currentTimeMillis()-startTime)/1000;//计算请求时间
        String res = "耗时:"+spendTime+"s,xml="+xml;
        String msgBody = params.toString();
        String errMsg = "获取挂号信息失败!";
        //xml验证
        verificationXml(xml,errMsg,ORDER_INFO,content,method,msgBody,res);
        Document document = DocumentHelper.parseText(xml);
        Element root = document.getRootElement();
        List<?> child = root.elements();
        if (patient == null) {
            throw new Exception("获取挂号人员信息失败!");
        }
        if (child.size() > 0) {
            Element e = (Element) child.get(0);
            // 医生编码
@ -1011,8 +1093,14 @@ public class GuahaoXMService implements IGuahaoService {
            GuahaoDoctor guahaoDoctor = GetDoctorInfo(DoctorCode, OrgCode, DeptCode);
            patientReservation.setDoctorPhoto(guahaoDoctor.getPhoto());//照片
            patientReservation.setDoctorJob(guahaoDoctor.getTitle());//职称
            //保存http日志
            logService.saveHttpLog(true,ORDER_INFO,content,method,null,msgBody,res,null,"2");
            return patientReservation;
        } else {
            //保存http日志
            logService.saveHttpLog(false,ORDER_INFO,content,method,null,msgBody,res,null,"2");
            return null;
        }
    }

+ 79 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/httplog/LogService.java

@ -0,0 +1,79 @@
package com.yihu.wlyy.service.third.httplog;
import com.yihu.wlyy.entity.httpLog.HttpLog;
import com.yihu.wlyy.repository.httplog.HttpLogDao;
import com.yihu.wlyy.service.system.SystemDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
 * Created by ysj on 2017/1/12.
 * 日志服务
 */
@Service
public class LogService {
    @Autowired
    private HttpLogDao httpLogDao;
    @Autowired
    private SystemDictService systemDictService;
    /**
     * 新增开放api调用日志
     * */
    public void saveOpenApiLog(Boolean isSuccess,String url,String content,String method,String params,String response,String error)
    {
        try {
            HttpLog log = new HttpLog();
            log.setType("0");  //开放接口
            log.setApi(url);
            log.setContent(content);
            log.setMethod(method);
            log.setParams(params);
            log.setCreateTime(new Date());
            log.setCreateTime(new Date());
            log.setResponse(response);
            log.setError(error);
            log.setStatus(isSuccess?"1":"0");
            httpLogDao.save(log);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    /**
     * 保存http调用日志
     */
    public void saveHttpLog(Boolean isSuccess,String url,String content,String method,String header,String params,String response,String error,String type)
    {
        try {
            //成功日志是否保存
            Boolean saveSuccessLog = systemDictService.getSaveSuccessLog();
            if(!isSuccess || saveSuccessLog) {
                //新增日志
                HttpLog log = new HttpLog();
                log.setType(type);
                log.setApi(url);
                log.setContent(content);
                log.setMethod(method);
                log.setHeader(header);
                log.setParams(params);
                log.setCreateTime(new Date());
                log.setResponse(response);
                log.setError(error);
                log.setStatus(isSuccess?"1":"0");
                httpLogDao.save(log);
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
}