package com.yihu.jw.hospital.prescription.service.entrance;

import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.hospital.dzqm.OauthDzqmConfigDO;
import com.yihu.jw.hospital.prescription.dao.OauthDzqmConfigDao;
import com.yihu.jw.hospital.prescription.service.entrance.util.WebserviceUtil;
import com.yihu.jw.utils.dzqm.SignPictureService;
import com.yihu.jw.utils.dzqm.SignPictureServiceImplServiceLocator;
import com.yihu.utils.network.HttpResponse;
import com.yihu.utils.network.HttpUtils;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.net.URL;
import java.util.Map;


/**
 * Created by Trick on 2019/10/14.
 */
@Service
@Transactional
public class DoctorPreSignService {

    private static final Logger logger = LoggerFactory.getLogger(DoctorPreSignService.class);

    @Autowired
    private OauthDzqmConfigDao oauthDzqmConfigDao;

    @Autowired
    private BaseDoctorDao doctorDao;

    /**
     * 获取医生签名
     * @param doctor
     * @return
     * @throws Exception
     */
    public JSONObject getDoctorSign(String doctor)throws Exception{

        logger.info("getDoctorSign doctor:"+doctor);
        BaseDoctorDO doc = doctorDao.findOne(doctor);

        //获取配置参数
        OauthDzqmConfigDO dzqmConfigDO = oauthDzqmConfigDao.findOne("base_dzqm");
        SignPictureServiceImplServiceLocator locator = new SignPictureServiceImplServiceLocator();
        URL portAddress = new  URL(dzqmConfigDO.getUrl());
        SignPictureService service = locator.getSignPictureServiceImplPort(portAddress);

        String rs = service.SOF_GetSignPicture(dzqmConfigDO.getSys(),doc.getIdcard(),"0","0");

        logger.info("getDoctorSign SOF_GetSignPicture:"+rs);

        JSONObject jsonObject = (JSONObject)JSONObject.parse(rs);

        return jsonObject;
    }

    /**
     * dome
     * @param args
     */
    public static void main(String[] args) {
        SignPictureServiceImplServiceLocator locator = new SignPictureServiceImplServiceLocator();
        String url = "http://101.132.67.155:8080/PKISignPicture/services/v1?wsdl";
        try {
            URL portAddress = new  URL(url);
            SignPictureService service = locator.getSignPictureServiceImplPort(portAddress);
            String sys = "EMR";
            String idNumber = "123456789123456789";
            String idType = "0";
            String picType = "0";
            String result = service.SOF_GetSignPicture(sys, idNumber, idType, picType);
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
