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


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.dict.dao.DictHospitalDeptDao;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
import com.yihu.jw.doctor.dao.BaseDoctorRoleDao;
import com.yihu.jw.entity.base.area.BaseDrugStoreDO;
import com.yihu.jw.entity.base.dict.DictHospitalDeptDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.patient.PatientMedicareCardDO;
import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
import com.yihu.jw.entity.base.wx.WxWechatDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalWaitingRoomDO;
import com.yihu.jw.entity.hospital.dict.WlyyChargeDictDO;
import com.yihu.jw.entity.hospital.doctor.WlyyPatientRegisterTimeDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionExpressageDO;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.hospital.consult.dao.HospitalWaitingRoomDao;
import com.yihu.jw.hospital.dict.WlyyChargeDictDao;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.doctor.dao.PatientRegisterTimeDao;
import com.yihu.jw.hospital.drugstore.dao.BaseDrugStoreDao;
import com.yihu.jw.hospital.mapping.dao.DoctorMappingDao;
import com.yihu.jw.hospital.mapping.dao.PatientMappingDao;
import com.yihu.jw.hospital.mapping.service.PatientMappingService;
import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
import com.yihu.jw.hospital.prescription.dao.PrescriptionExpressageDao;
import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
import com.yihu.jw.hospital.ykyy.service.YkyyService;
import com.yihu.jw.order.BusinessOrderService;
import com.yihu.jw.order.dao.BusinessOrderDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.BasePatientMedicareCardDao;
import com.yihu.jw.restmodel.hospital.prescription.WlyyOutpatientVO;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionVO;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.utils.CheckSumBuilder;
import com.yihu.jw.utils.FileUtil;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.wechat.dao.BasePatientWechatDao;
import com.yihu.jw.wechat.dao.WechatDao;
import com.yihu.mysql.query.BaseJpaService;
import com.yihu.utils.network.HttpResponse;
import com.yihu.utils.network.HttpUtils;
import com.yihu.utils.security.MD5;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Trick on 2019/5/17.
 */
@Service
@Transactional
public class YkyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO, PrescriptionDao> {

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


    @Autowired
    private BasePatientDao basePatientDao;
    @Autowired
    private PrescriptionExpressageDao prescriptionExpressageDao;
    @Autowired
    private HospitalWaitingRoomDao hospitalWaitingRoomDao;
    @Autowired
    private PatientMappingService patientMappingService;
    @Autowired
    private OutpatientDao outpatientDao;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private PatientRegisterTimeDao patientRegisterTimeDao;
    @Autowired
    private YkyyEntranceService ykyyEntranceService;
    @Autowired
    private BusinessOrderDao businessOrderDao;
    @Autowired
    private WechatDao wechatDao;
    @Autowired
    private BasePatientWechatDao patientWechatDao;
    @Autowired
    private BusinessOrderService businessOrderService;
    @Autowired
    private BaseDrugStoreDao baseDrugStoreDao;
    @Autowired
    private BasePatientMedicareCardDao basePatientMedicareCardDao;
    @Autowired
    private PatientMappingDao patientMappingDao;
    @Autowired
    private DictHospitalDeptDao dictHospitalDeptDao;
    @Autowired
    private BaseDoctorHospitalDao doctorHospitalDao;
    @Autowired
    private BaseDoctorRoleDao doctorRoleDao;
    @Autowired
    private DoctorMappingDao doctorMappingDao;
    @Autowired
    private WlyyChargeDictDao wlyyChargeDictDao;
    @Autowired
    private WlyyHospitalSysDictDao hospitalSysDictDao;
    @Autowired
    private BaseDoctorDao doctorDao;

    @Autowired
    private HttpClientUtil httpClientUtil;



    @Value("${demo.flag}")
    private boolean demoFlag;

    @Value("${wechat.flag}")
    private boolean flag;

    @Value("${pay.flag}")
    private boolean payFlag;
    @Value("${wechat.id}")
    private String wechatId;
    @Autowired
    private YkyyService ykyyService;

    /**
     * 获取居民就诊记录接口
     * @param patient
     * @param startTime
     * @param endTime
     * @param demoFlag
     * @return
     * @throws Exception
     */
    public  List<WlyyOutpatientVO> findOutpatientList(String patient,String cardNo, String startTime, String endTime, boolean demoFlag,String ksdm)throws Exception{
        logger.info("findOutpatientList patient:"+patient);
        String patNo ="";
        PatientMappingDO patientMappingDO = patientMappingDao.findByPatient(patient);
        if(StringUtils.isNotBlank(cardNo)){
            BasePatientDO patientDO = basePatientDao.findByIdAndDel(patient,"1");
            JSONArray res = ykyyEntranceService.findPatientCodeByCardNo(cardNo,false,patientDO.getId());
            if(res !=null&&res.size()>0){
                JSONObject object = (JSONObject) res.get(0);
                if (object.get("brid")!=null){
                    patNo = object.get("brid").toString();
                }
            }
            if(!StringUtils.isBlank(patNo)){
                if (patientMappingDO!=null){
                    patientMappingDO.setMappingCode(patNo);
                }else {
                    patientMappingDO = new PatientMappingDO();
                    patientMappingDO.setMappingCode(patNo);
                    patientMappingDO.setCreateTime(new Date());
                    patientMappingDO.setSource("1");
                    patientMappingDO.setPatient(patient);
                    patientMappingDO.setIdcard(patientDO.getIdcard());
                    patientMappingDO.setPatientName(patientDO.getName());
                }
                patientMappingDao.save(patientMappingDO);
            }

        }else {
            if (patientMappingDO!=null){
                patNo = patientMappingDO.getMappingCode();
            }
        }
        if(StringUtils.isBlank(patNo)){
            return null;
        }
        logger.info("findOutpatientList patNo "+patNo);
        return ykyyEntranceService.BS30025(patNo,null,startTime,endTime,demoFlag,ksdm);
    }


    public void synDoctorInfo(String idcard) throws Exception {
        JSONArray jsonArray = ykyyEntranceService.findHisDoctor(idcard);
        if (jsonArray!=null&&jsonArray.size()!=0){
            for (int i=0;i<jsonArray.size();i++){
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                String idCard= jsonObject.getString("idcard");
                String code = jsonObject.getString("code");
                String name = jsonObject.getString("name");
                String expertise = jsonObject.getString("expertise");
                String introduce = jsonObject.getString("introduce");
                String mobile = jsonObject.getString("mobile");
                String jobTitleCode = jsonObject.getString("jobTitleCode");
                String jobTitleName = jsonObject.getString("jobTitleName");
                String dept = jsonObject.getString("dept");
                String deptName = jsonObject.getString("deptName");
                List<BaseDoctorDO> doctorDOS =doctorDao.findByIdcard(idcard);
                if (doctorDOS!=null&&doctorDOS.size()!=0){
                    BaseDoctorDO doctorDO = doctorDOS.get(0);
                    doctorDO.setIdcard(idcard);
                    doctorDO.setName(name);
                    doctorDO.setExpertise(expertise);
                    doctorDO.setIntroduce(introduce);
                    doctorDO.setMobile(mobile);
                    doctorDO.setJobTitleCode(jobTitleCode);
                    doctorDO.setJobTitleName(jobTitleName);
                    DictHospitalDeptDO dictHospitalDeptDO = dictHospitalDeptDao.findByCode(dept);
                    List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDeptCodeAndDoctorCode(dept,doctorDO.getId());
                    for (BaseDoctorHospitalDO doctorHospitalDO:doctorHospitalDOS){
                        doctorHospitalDO.setDeptCode(dept);
                        doctorHospitalDO.setDeptName(deptName);
                        doctorHospitalDao.save(doctorHospitalDO);
                    }
                    doctorDao.save(doctorDO);
                }else {
                    BaseDoctorDO doctorDO = new BaseDoctorDO();
                    doctorDO.setIdcard(idCard);
                    doctorDO.setName(name);
                    doctorDO.setExpertise(expertise);
                    doctorDO.setIntroduce(introduce);
                    doctorDO.setMobile(mobile);
                    doctorDO.setJobTitleCode(jobTitleCode);
                    doctorDO.setJobTitleName(jobTitleName);
                    doctorDO.setSex(Integer.parseInt(IdCardUtil.getSexForIdcard_new(idcard)));
                    doctorDO.setBirthday(IdCardUtil.getBirthdayForIdcard(idcard));
                    String salt = randomString(5);
                    String pw = idcard.substring(idcard.length() - 6);
                    doctorDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                    doctorDO.setSalt(salt);
                    doctorDO.setDel("1");
                    doctorDO.setEnabled(1);
                    doctorDO.setLocked(0);
                    doctorDO.setCreateTime(new Date());
                    doctorDO = doctorDao.save(doctorDO);
                    //机构信息部门信息
                    BaseDoctorHospitalDO hospitalDO = new BaseDoctorHospitalDO();
                    hospitalDO.setDoctorCode(doctorDO.getId());
                    hospitalDO.setOrgCode("350211A5004");
                    hospitalDO.setOrgName("厦门大学附属厦门眼科中心");
                    hospitalDO.setDeptCode(dept);
                    hospitalDO.setDeptName(deptName);
                    hospitalDO.setDel("1");
                    doctorHospitalDao.save(hospitalDO);
                    BaseDoctorRoleDO role = new BaseDoctorRoleDO();
                    role.setDoctorCode(doctorDO.getId());
                    role.setRoleCode("specialist");
                    doctorRoleDao.save(role);
                    DoctorMappingDO mappingDO = new DoctorMappingDO();
                    mappingDO.setIdcard(idcard);
                    mappingDO.setDoctor(doctorDO.getId());
                    mappingDO.setOrgCode("350211A5004");
                    mappingDO.setOrgName("厦门大学附属厦门眼科中心");
                    mappingDO.setMappingCode(code);
                    mappingDO.setMappingName(name);
                    mappingDO.setDoctorName(name);
                    mappingDO.setMappingDeptName(deptName);
                    mappingDO.setMappingDept(dept);
                    mappingDO.setMappingJob(jobTitleCode);
                    mappingDO.setMappingJobName(jobTitleName);
                    mappingDO.setCreateTime(new Date());
                    doctorMappingDao.save(mappingDO);
                }
            }

        }
    }


    /**
     *
     */
    public List<WlyyPrescriptionVO> findOriginPrescriptionList(String registerSn,String patient,String realOrder,String admNo,boolean demoFlag)throws Exception{
        String patNo =patientMappingService.findYkyyPatNoByPatient(patient,demoFlag);
        if(StringUtils.isBlank(patNo)){
            return null;
        }
        //BS16017(String REGISTER_SN,String realOrder,String PAT_NO,String ADM_NO,boolean demoFlag) throws Exception {
        logger.info("findOriginPrescriptionList： registerSn:"+registerSn+" patient"+patient+" patNo:"+patNo+" realOrder:"+realOrder+" admNo:"+admNo);
        return ykyyEntranceService.findV_MSDD01And02(admNo,demoFlag);
    }

    /**
     * 获取居民就诊记录接口
     * @param patient
     * @return
     * @throws Exception
     */
    public  WlyyOutpatientVO findOutpatientInfo(String patient,String conNo, boolean demoFlag,String ksdm)throws Exception{
        logger.info("findOutpatientList patient:"+patient);
        String patNo =patientMappingService.findYkyyPatNoByPatient(patient,demoFlag);
        if(StringUtils.isBlank(patNo)){
            return null;
        }
        logger.info("findOutpatientList patNo "+patNo);
        List<WlyyOutpatientVO> wlyyOutpatientVOS = ykyyEntranceService.BS30025(patNo,conNo,null,null,demoFlag,ksdm);
        if (wlyyOutpatientVOS!=null&&wlyyOutpatientVOS.size()!=0){
            WlyyOutpatientVO outpatientVO = wlyyOutpatientVOS.get(0);
            BasePatientDO patientDO = basePatientDao.findById(patient);
            outpatientVO.setSex(patientDO.getSex()+"");
            outpatientVO.setBirthday(patientDO.getBirthday());
            outpatientVO.setIdcard(patientDO.getIdcard());
            return outpatientVO;
        }
       return null;
    }



    /**
     * 发起图文和视频复诊
     *
     * @param outpatientJson
     * @param expressageJson
     * @return
     * @throws Exception
     */
    public WlyyOutpatientDO appointmentRevisit(String outpatientJson, String expressageJson, String registerJson, String chargeType) throws Exception {

        System.out.print("outpatientJson::"+outpatientJson);
        //1.保存就诊实体
        WlyyOutpatientDO outpatientDO = objectMapper.readValue(outpatientJson, WlyyOutpatientDO.class);
        System.out.print("getDescription::"+outpatientDO.getDescription());
        BasePatientDO patientDO = basePatientDao.findById(outpatientDO.getPatient());
        BaseDoctorDO doctorDO = doctorDao.findById(outpatientDO.getDoctor());
        outpatientDO.setMjz("mz");
        outpatientDO.setStatus("0");
        outpatientDO.setCreateTime(new Date());
        outpatientDO.setIdcard(patientDO.getIdcard());
        outpatientDO.setCreateTime(new Date());
        if (!payFlag){
            outpatientDO.setPayStatus(1);
        }else {
            outpatientDO.setPayStatus(0);
        }
        if (outpatientDO.getRegisterDate() == null) {
            outpatientDO.setRegisterDate(new Date());
        }

        WlyyOutpatientDO outpatient = outpatientDao.save(outpatientDO);
        BusinessOrderDO businessOrderDO = new BusinessOrderDO();
        if("3".equalsIgnoreCase(outpatient.getOutpatientType())){
            businessOrderDO.setRelationCode(outpatient.getId());
            businessOrderDO.setRelationName("专家咨询费");
            businessOrderDO.setDescription("专家咨询费");
            businessOrderDO.setRematk(outpatient.getDescription());
            businessOrderDO.setPatient(outpatient.getConsumer());
            businessOrderDO.setPatientName(outpatient.getConsumerName());
            businessOrderDO.setDoctor(outpatient.getDoctor());
            if (outpatientDO.getType().equalsIgnoreCase("1")) {
                businessOrderDO.setOrderType(1);
                businessOrderDO.setOrderCategory("1");
            } else if (outpatientDO.getType().equalsIgnoreCase("2")) {
                businessOrderDO.setOrderType(3);
                businessOrderDO.setOrderCategory("1");
            }
        }else {
            businessOrderDO.setRelationCode(outpatient.getId());
            businessOrderDO.setRelationName("复诊-诊查费");
            businessOrderDO.setDescription("复诊-诊查费");
            businessOrderDO.setRematk(outpatient.getDescription());
            businessOrderDO.setPatient(outpatient.getConsumer());
            businessOrderDO.setPatientName(outpatient.getConsumerName());
            businessOrderDO.setDoctor(outpatient.getDoctor());
            if (outpatientDO.getType().equalsIgnoreCase("1")) {
                businessOrderDO.setOrderType(1);
                businessOrderDO.setOrderCategory("2");
            } else if (outpatientDO.getType().equalsIgnoreCase("2")) {
                businessOrderDO.setOrderType(3);
                businessOrderDO.setOrderCategory("3");
            }
        }
        WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("WX_MONEY");
        Double price = 0.0;
        String chargeType1 = null;
        if (doctorDO!=null){
            if (outpatient.getOutpatientType().equalsIgnoreCase("1")){
                if(outpatientDO.getType().equalsIgnoreCase("1")){
                    chargeType1 = doctorDO.getTwfzChargeType();
                }else if(outpatientDO.getType().equalsIgnoreCase("2")){
                    chargeType1 = doctorDO.getSpfzChargeType();
                }
            }else if (outpatient.getOutpatientType().equalsIgnoreCase("3")){
                if(outpatientDO.getType().equalsIgnoreCase("1")){
                    chargeType1 = doctorDO.getTwzxChargeType();
                }else if(outpatientDO.getType().equalsIgnoreCase("2")){
                    chargeType1 = doctorDO.getSpzxChargeType();
                }
            }else if (outpatient.getOutpatientType().equalsIgnoreCase("2")){
                chargeType1 = doctorDO.getXtfzChargeType();
            }
            if(doctorDO!=null){
                if (StringUtils.isNoneBlank(chargeType1)){
                    WlyyChargeDictDO chargeDictDO = wlyyChargeDictDao.findByChargeType(chargeType1);
                    if (chargeDictDO!=null){
                        price = chargeDictDO.getReqFee();
                    }else {
                        price = Double.parseDouble(hospitalSysDictDO.getDictValue());
                    }
                }
            }else {
                price = Double.parseDouble(hospitalSysDictDO.getDictValue());
            }
        }else {
            if (StringUtils.isNoneBlank(chargeType)){
                WlyyChargeDictDO chargeDictDO = wlyyChargeDictDao.findByChargeType(chargeType);
                if (chargeDictDO!=null){
                    price = chargeDictDO.getReqFee();
                }else {
                    price = Double.parseDouble(hospitalSysDictDO.getDictValue());
                }
            }
        }

        /*if (doctorDO != null && StringUtils.isNoneBlank(doctorDO.getFee())) {
            price = Double.parseDouble(doctorDO.getFee());
        }else {
            price = Double.parseDouble(hospitalSysDictDO.getDictValue());
        }*/
        if (price == 0.0) {
            outpatientDO.setPayStatus(1);
        } else {
            outpatientDO.setPayStatus(0);
        }

        businessOrderDO.setPayPrice(price*100);


        if (!flag){
            businessOrderDO = businessOrderService.saveOrder(businessOrderDO);
        }

        WlyyPatientRegisterTimeDO registerTimeDO = null;

        try {
            //如果是视频预约咨询
            if (StringUtils.isNotBlank(registerJson)) {
                registerTimeDO = objectMapper.readValue(registerJson, WlyyPatientRegisterTimeDO.class);
                registerTimeDO.setOutpatientId(outpatient.getId());
                registerTimeDO.setCreateTime(new Date());
                patientRegisterTimeDao.save(registerTimeDO);
            }
        } catch (Exception e) {
            throw new RuntimeException("号源已经被预约，请选择其他号源");
        }
        if ("3".equalsIgnoreCase(outpatient.getOutpatientType())){

        }else {
            //2.物流信息
            WlyyPrescriptionExpressageDO expressageDO = objectMapper.readValue(expressageJson, WlyyPrescriptionExpressageDO.class);
            expressageDO.setDel(1);
            expressageDO.setCreateTime(new Date());
            expressageDO.setOutpatientId(outpatient.getId());
            prescriptionExpressageDao.save(expressageDO);

            if (1==expressageDO.getOneselfPickupFlg()){
                if("xm_ykyy_wx".equalsIgnoreCase(wechatId)){
                    String drugCode= expressageDO.getHospitalCode()==null?"5550":expressageDO.getHospitalCode();
                    expressageDO.setHospitalCode(drugCode);
                }
                System.out.println("进入物流信息");
                expressageDO.setDel(1);
                expressageDO.setCreateTime(new Date());
                expressageDO.setOutpatientId(outpatient.getId());
                prescriptionExpressageDao.save(expressageDO);
            }else {
                System.out.println("写入自取信息");
                String drugStoreCode = expressageDO.getHospitalCode();
                BaseDrugStoreDO baseDrugStoreDO = baseDrugStoreDao.findDrugByid(drugStoreCode);
                if (null!=baseDrugStoreDO){
                    expressageDO.setCityCode(baseDrugStoreDO.getCityCode());
                    expressageDO.setCityName(baseDrugStoreDO.getCityName());
                    expressageDO.setProvinceCode(baseDrugStoreDO.getProvinceCode());
                    expressageDO.setProvinceName(baseDrugStoreDO.getProvinceName());
                    expressageDO.setTownCode(baseDrugStoreDO.getTownCode());
                    expressageDO.setTownName(baseDrugStoreDO.getTownName());
                    expressageDO.setHospitalCode(baseDrugStoreDO.getDrugStoreCode());
                    expressageDO.setHospitalName(baseDrugStoreDO.getHospitalName());
                    expressageDO.setHospitalAddress(baseDrugStoreDO.getAddress());
                }
                expressageDO.setDel(1);
                expressageDO.setCreateTime(new Date());
                expressageDO.setOutpatientId(outpatient.getId());
                prescriptionExpressageDao.save(expressageDO);
            }
        }
        //3.创建候诊室
        createRoom(outpatient, chargeType);
        return outpatient;
    }


    /**
     * 创建候诊室
     *
     * @param outpatientDO
     * @return
     */
    public Boolean createRoom(WlyyOutpatientDO outpatientDO, String chargeType) {

        WlyyHospitalWaitingRoomDO waitingRoom = new WlyyHospitalWaitingRoomDO();

        waitingRoom.setDept(outpatientDO.getDept());
        waitingRoom.setDeptName(outpatientDO.getDeptName());
        waitingRoom.setHospital(outpatientDO.getHospital());
        waitingRoom.setHospitalName(outpatientDO.getHospitalName());

        //是否是有协同门诊医生
        if (StringUtils.isNotBlank(outpatientDO.getGeneralDoctor())) {
            waitingRoom.setGeneralDoctor(outpatientDO.getGeneralDoctor());
            waitingRoom.setGeneralDoctorName(outpatientDO.getGeneralDoctorName());
        }

        waitingRoom.setPatientId(outpatientDO.getConsumer());
        waitingRoom.setPatientName(outpatientDO.getConsumerName());
        waitingRoom.setReservationTime(outpatientDO.getRegisterDate());
        waitingRoom.setVisitStatus(0);
        //设置复诊类型
        waitingRoom.setReservationType(StringUtils.isNotBlank(outpatientDO.getOutpatientType()) ? Integer.parseInt(outpatientDO.getOutpatientType()) : 1);

        waitingRoom.setSort(0);
        waitingRoom.setConsultType(Integer.parseInt(outpatientDO.getType()));
        if (StringUtils.isNotBlank(outpatientDO.getDoctor())) {
            waitingRoom.setDoctor(outpatientDO.getDoctor());
            waitingRoom.setDoctorName(outpatientDO.getDoctorName());
        }
        waitingRoom.setOutpatientId(outpatientDO.getId());
        waitingRoom.setCreateTime(new Date());

        if (StringUtils.isNotBlank(chargeType)) {
            waitingRoom.setChargeType(chargeType);
        }

        hospitalWaitingRoomDao.save(waitingRoom);

        return true;
    }


    /**
     * 获取药品
     *
     `prescription_id` varchar(50) DEFAULT NULL COMMENT '处方code 关联表wlyy_prescription code',
     `drug_no` varchar(50) DEFAULT NULL COMMENT '药品编号',
     `drug_name` varchar(50) DEFAULT NULL COMMENT '药品名称',
     `disp_deposite` varchar(50) DEFAULT NULL COMMENT '库房号',
     `dosage` varchar(50) DEFAULT NULL COMMENT '药量',
     `quantity` varchar(50) DEFAULT NULL COMMENT '数量',
     `unit` varchar(50) DEFAULT NULL COMMENT '用量单位',
     `unit_name` varchar(50) DEFAULT NULL COMMENT '用量单位中文',
     `pack_unit` varchar(50) DEFAULT NULL COMMENT '包装单位',
     `pack_unit_name` varchar(50) DEFAULT NULL COMMENT '包装单位名称',
     `usage_code` varchar(50) DEFAULT NULL COMMENT '频率code',
     `usage_name` varchar(50) DEFAULT NULL COMMENT '频次名称',
     `supply_code` varchar(50) DEFAULT NULL COMMENT '用法',
     `supply_name` varchar(50) DEFAULT NULL COMMENT '用法名称',
     `days` varchar(50) DEFAULT NULL COMMENT '天数',
     `frequency` varchar(50) DEFAULT NULL COMMENT '组号',
     `serial` varchar(50) DEFAULT NULL COMMENT '药品序列号',
     `group_no` varchar(50) DEFAULT NULL COMMENT '库房号',
     `specification` varchar(50) DEFAULT NULL COMMENT '规格（10mgx10片/盒）',
     `pack_retprice` double(10,4) DEFAULT NULL COMMENT '包装价格',
     `herbal_count` varchar(10) DEFAULT NULL COMMENT '草药数量',
     `post_count` varchar(10) DEFAULT NULL COMMENT '贴数',
     `comm` varchar(50) DEFAULT NULL COMMENT '中药用法',
     `del` int(2) DEFAULT '1' COMMENT '1可用 0删除',
     `drug_place` varchar(100) DEFAULT NULL COMMENT '药品产地',
     `pack_quantity` int(11) DEFAULT NULL COMMENT '包装数量',
     PRIMARY KEY (`id`),
     */
    public JSONArray getDrugDictionary(String chargeCode, String pyKey, String winNo, String groupNo,String oupatientId) throws Exception {
        String hisCode = "";
        if (StringUtils.isNotEmpty(oupatientId)){
            List<WlyyPrescriptionExpressageDO> wlyyPrescriptionExpressageDOS = prescriptionExpressageDao.findByOutpatientIdAndOneSelfPick(oupatientId);
            if (wlyyPrescriptionExpressageDOS.size()>0){
                hisCode = wlyyPrescriptionExpressageDOS.get(0).getHospitalCode();
            }
        }
        JSONArray mapList = new JSONArray();
        if (demoFlag){
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("ypcd","400");
            jsonObject.put("ypjl",0.5);
            jsonObject.put("yfzf",0);
            jsonObject.put("kcsl",0);
            jsonObject.put("jldw","mg");
            jsonObject.put("lsjg",0.1);
            jsonObject.put("ypdm","0601");
            jsonObject.put("zfpb",0);
            jsonObject.put("yfgg","1ml:0.5mg");
            jsonObject.put("ypmc","维生素B12注射液");
            jsonObject.put("yfsx",null);
            jsonObject.put("fyfs",2);
            jsonObject.put("gyffmc","注射");
            jsonObject.put("jbywbz",1);
            jsonObject.put("yfbz",1);
            jsonObject.put("ybfl",null);
            jsonObject.put("yfdw","支");
            jsonObject.put("gyff",13);
            jsonObject.put("ypmc2","维生素B12注射液");
            jsonObject.put("ydyp",0);
            jsonObject.put("py_code","WSSB12ZS");
            mapList.add(jsonObject);
        }else {
            mapList = ykyyEntranceService.findYkYpxx(chargeCode, null, null, pyKey,hisCode);
        }
        JSONArray array = new JSONArray();
        for (int i=0;i<mapList.size();i++){
            JSONObject map = mapList.getJSONObject(i);
            JSONObject object = new JSONObject();
            object.put("charge_code",map.get("ypxh"));
            object.put("drugname",map.get("ypmc"));
            object.put("specification",map.get("yfgg"));
            object.put("pack_unit",map.get("yfdw"));
            object.put("pack_unit_name",map.get("yfdw"));
            object.put("yfdw",map.get("yfdw"));
            if (map.get("yfsb")!=null){
                String yfsb = map.get("yfsb").toString();
                if (yfsb.equalsIgnoreCase("9")){
                    object.put("yfsb",3);//药房识别 3思明6五缘
                }else if (yfsb.equalsIgnoreCase("10")){
                    object.put("yfsb",6);//药房识别 3思明6五缘
                }
            }
            object.put("pack_size",map.get("yfbz"));
            object.put("yfsx",map.get("yfsx"));//药房属性
            object.put("ypjl",map.get("ypjl"));//药剂量
            object.put("mini_unit",map.get("jldw"));//最小单位
            object.put("mini_unit_name",map.get("jldw"));//最小单位名称
            object.put("jldw",map.get("jldw"));//剂量单位
            object.put("py_code",map.get("pydm"));//拼音代码
            object.put("fyfs",map.get("fyfs"));//发药方式
            object.put("supply_code",map.get("gyff"));//给药方式
            object.put("yfzf",map.get("yfzf"));//药房作废
            object.put("supply_name",map.get("gyffmc"));//给药方式名称
            object.put("ybfl",map.get("ybfl"));//医保分类
            object.put("retprice",map.get("lsjg"));//零售价格
            object.put("kcsl",map.get("kcsl"));//库存
            object.put("ypcd",map.get("ypcd"));//产地
            object.put("zfpb",map.get("zfpb"));//作废判别
            object.put("jbywbz",map.get("jbywbz"));//基本药物标志
            object.put("ydyp",map.get("ydyp"));//药店药品
            object.put("ypmc2",map.get("ypmc2"));//药品名称2
            object.put("t",map.get("pzwh"));//药品批文
            object.put("stock_amount",map.get("kcsl"));//库存
            array.add(object);
        }
        return array;
    }


    /**
     * 获取药品用法
     */
    public JSONArray getDrugUse(String drugNo, String pyKey,boolean demoFlag) throws Exception {

        JSONArray mapList = new JSONArray();
        if (demoFlag){
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("xmmc","含服");
            jsonObject.put("pydm","HF");
            jsonObject.put("ypyf",64);
            mapList.add(jsonObject);
        }else {
            mapList = ykyyEntranceService.findYpyf(pyKey,"");
        }
        JSONArray array = new JSONArray();
        for (int i=0;i<mapList.size();i++){
            JSONObject map = mapList.getJSONObject(i);
            JSONObject object = new JSONObject();
            object.put("supply_code",map.get("pydm"));
            object.put("supply_name",map.get("xmmc"));
            object.put("ypyf",map.get("ypyf"));
            array.add(object);
        }
        return array;
    }

    /**
     * 医院频次
     *
     * @return
     */
    public JSONArray getDrugFrequency(boolean demoFlag) throws Exception {
        JSONArray mapList = new JSONArray();
        if (demoFlag){
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("pcmc","qd");
            jsonObject.put("pcmc1","每日一次");
            jsonObject.put("mrcs",1);
            mapList.add(jsonObject);
        }else {
            mapList= ykyyEntranceService.findSypc(null);
        }
        JSONArray array = new JSONArray();
        for (int i=0;i<mapList.size();i++){
            JSONObject map = mapList.getJSONObject(i);
            JSONObject object = new JSONObject();
            object.put("FREQ_CODE",map.get("pcmc"));
            object.put("FREQ_NAME",map.get("pcmc1"));
            object.put("MRSC",map.get("mrcs"));
            array.add(object);
        }
        return array;
    }

    /**
     * 获取检查检验
     *  "action": "select",
     "name": "丙型肝炎RNA测定(全自动荧光定量分析)",
     "charge_unit": "项",
     "charge_amount": "150",
     "py_code": "BXGYRNAC",
     "d_code": "GGEORNAI",
     "code": "393333",
     "exec_unit": "2160000",
     "win_no": "0",
     "exec_unit_name": "检验科"
     *
     * @return
     */
    public JSONArray getInspectionDictionary(String pyKey, String codes, String winNo) throws Exception {
        JSONArray mapList = ykyyEntranceService.findYkJcxm(pyKey);
        JSONArray array = new JSONArray();
        for (int i=0;i<mapList.size();i++){
            JSONObject map = mapList.getJSONObject(i);
            JSONObject object = new JSONObject();
            object.put("name",map.get("xmmc"));
            object.put("code",map.get("zlxmid"));
            object.put("py_code",map.get("pydm"));
            object.put("wbdm",map.get("wbdm"));
            object.put("jxdm",map.get("jxdm"));
            object.put("qtdm",map.get("qtdm"));
            object.put("ydyzlb",map.get("ydyzlb"));
            object.put("mlbh",map.get("mlbh"));
            object.put("zxpc",map.get("zxpc"));
            object.put("jfpc",map.get("jfpc"));
            object.put("jsfs",map.get("jsfs"));
            object.put("jszq",map.get("jszq"));
            object.put("charge_unit",map.get("jsdw"));
            object.put("syxb",map.get("syxb"));
            object.put("mxsy",map.get("mxsy"));
            object.put("zysy",map.get("zysy"));//住院使用
            object.put("tjsy",map.get("tjsy"));
            object.put("zxlb",map.get("zxlb"));//执行类别
            object.put("exec_unit",map.get("zxks"));//执行科室
            object.put("zxgzid",map.get("zxgzid"));//执行规则
            object.put("ywzx",map.get("ywzx"));
            object.put("zxap",map.get("zxap"));
            object.put("cpzx",map.get("cpzx"));
            object.put("szzx",map.get("szzx"));
            object.put("jjlx",map.get("jjlx"));
            object.put("ycxzsl",map.get("ycxzsl"));
            object.put("yblx",map.get("yblx"));
            object.put("zxbz",map.get("zxbz"));
            object.put("txid",map.get("txid"));
            object.put("bgbh",map.get("bgbh"));
            object.put("czsy",map.get("czsy"));
            object.put("lzsy",map.get("lzsy"));
            object.put("lccs",map.get("lccs"));
            object.put("bwbz",map.get("bwbz"));
            object.put("yblb",map.get("yblb"));
            array.add(object);
        }
        return array;
    }


    /**
     * 获取卡记录
     *  "PAT_NO": "P5616242-0  ",
     "CARD_NO": "D40136791",
     "CARD_STAT": "旧卡停用",
     "OP_DATE": "2011-09-27 15:35:57",
     "CARD_TYPE": "2",
     "CARD_TYPE_NAME": "社保卡",
     "social_no": "350211198411053024"
     * @param patient
     * @return
     * @throws Exception
     */
    public JSONArray findPatientCard(String patient)throws Exception{
        BasePatientDO patientDO = basePatientDao.findById(patient);
        if (patientDO!=null){
            //JSONArray res = ykyyEntranceService.findHisCard(patientDO.getIdcard(),demoFlag);
            JSONArray rs = new JSONArray();
            /*if(res !=null){
                for (int i =0;i<res.size();i++){
                    JSONObject object = (JSONObject) res.get(i);
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("PAT_NO",object.get("pat_no"));
                    jsonObject.put("CARD_NO",object.get("card_no"));
                    jsonObject.put("OP_DATE",object.get("op_date"));
                    jsonObject.put("CARD_STAT",object.get("card_stat"));
                    jsonObject.put("CARD_TYPE",object.get("card_type"));
                    jsonObject.put("CARD_TYPE_NAME",object.get("card_type_name"));
                    rs.add(jsonObject);
                }
            }*/
            List<PatientMedicareCardDO> list  = basePatientMedicareCardDao.findByPatientCode(patientDO.getId());
            PatientMappingDO patientMappingDO = patientMappingDao.findByPatient(patientDO.getId());
            if (list!=null&&list.size()>0){
                for (PatientMedicareCardDO patientMedicareCardDO :list){
                    JSONObject jsonObject = new JSONObject();
                    if (null!=patientMappingDO){
                        jsonObject.put("PAT_NO",patientMappingDO.getMappingCode());
                    }else {
                        JSONArray res = ykyyEntranceService.findPatientCodeByCardNo(patientMedicareCardDO.getCode(),false,patient);
                        patientMappingDO = new PatientMappingDO();
                        if(res !=null&&res.size()>0){
                            JSONObject object = (JSONObject) res.get(0);
                            if (object.get("pat_no")!=null){
                                jsonObject.put("PAT_NO",object.get("pat_no").toString());
                            }
                            if (object.get("brid")!=null){
                                jsonObject.put("BRID",object.get("brid").toString());
                                patientMappingDO.setMappingCode(object.get("brid").toString());
                                patientMappingDO.setPatient(patient);
                                patientMappingDO.setPatientName(patientDO.getName());
                                patientMappingDO.setIdcard(patientDO.getIdcard());
                                patientMappingDO.setSource("1");
                                patientMappingDO.setCreateTime(new Date());
                                patientMappingDao.save(patientMappingDO);
                            }
                        }
                    }
                    jsonObject.put("CARD_NO",patientMedicareCardDO.getCode());
                    jsonObject.put("OP_DATE","");
                    jsonObject.put("CARD_STAT","正常");
                    jsonObject.put("CARD_TYPE",patientMedicareCardDO.getType());
                    if (patientMedicareCardDO.getType().equalsIgnoreCase("A_02")){
                        jsonObject.put("CARD_TYPE_NAME","门诊号");
                    }else {
                        jsonObject.put("CARD_TYPE_NAME","社保卡");
                    }
                    rs.add(jsonObject);
                }
                return rs;
            }
        }
        return null;

    }


    public JSONArray synYkICD10() throws Exception {
        JSONArray jsonArray = ykyyEntranceService.synYkICD10();
        return jsonArray;
    }



    /**
     *
     * 处方下单
     *
     * @return
     * @throws Exception
     */
    public Map<String,Object> savePrescriptionOrder(String code,Double price,String tradeType,String wechatId,String appletCode) throws Exception {
        WxWechatDO wxWechatDO = wechatDao.findById(wechatId);
        Map<String,Object> map = new HashedMap();
        if(wxWechatDO==null){
            throw new Exception("can't find wechat:the wxId is "+wechatId);
        }
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(code);
        if (businessOrderDO!=null){
            if (businessOrderDO.getStatus()==1){
                throw new Exception("该处方已支付过");
            }
            List<BasePatientWechatDo> patientWechatDos = patientWechatDao.findByWechatIdAndPatientId(wechatId,businessOrderDO.getPatient());
            String openId = "";
            if (StringUtils.isNotBlank(appletCode)){
                logger.info("appletCode不为空"+appletCode);
                Map<String,Object> objectMap = checkApplets(appletCode,wxWechatDO.getApplets(),wxWechatDO.getAppletsSecret());
                if (objectMap!=null){
                    openId = objectMap.get("openid").toString();
                    logger.info("appletCode"+appletCode);
                    logger.info("openid"+openId);
                }
            }else {
                logger.info("appletCode为空"+appletCode);
                List<BasePatientWechatDo> patientWechatDo = patientWechatDao.findByWechatIdAndPatientId(wechatId,businessOrderDO.getPatient());
                if (patientWechatDo!=null&&patientWechatDo.size()!=0){
                    openId = patientWechatDo.get(0).getOpenid();
                }
            }
            if (businessOrderDO.getOrderNo()!=null&&businessOrderDO.getOrderNo().contains("HLWYYQD")){
                businessOrderDO.setOrderNo("HLWYYQD"+businessOrderDO.getOrderType()+System.currentTimeMillis()+(int)(Math.random()*900)+100);
            }else {
                businessOrderDO.setOrderNo("HLWYY"+businessOrderDO.getOrderType()+System.currentTimeMillis()+(int)(Math.random()*900)+100);
            }
            businessOrderDO= businessOrderDao.save(businessOrderDO);
            String url = wxWechatDO.getBaseUrl();
            String notifyUrl =url;
            String totalFee =businessOrderDO.getPayPrice().intValue()+"";
            map = businessOrderService.unifiedorder(wechatId,businessOrderDO.getDescription(),totalFee, tradeType,openId,businessOrderDO.getOrderNo(),notifyUrl,businessOrderDO.getPatient());
        }
        return map;
    }

    public Map<String, Object> checkApplets(String code,String appid,String appSecret) throws Exception {
        HttpUtils httpUtils = new HttpUtils();
        Map<String, Object> param = new HashedMap();
        param.put("appid", appid);
        param.put("secret", appSecret);
        param.put("js_code", code);
        param.put("grant_type", "authorization_code");

        HttpResponse response = httpUtils.doGet("https://api.weixin.qq.com/sns/jscode2session", param);
        org.json.JSONObject rs = new org.json.JSONObject(response.getContent());
        Map<String, Object> res = new HashedMap();
        logger.info("checkApplets:"+response.getContent());
        if (rs.has("openid")){
            res.put("openid", rs.getString("openid"));
            res.put("sessionKey", rs.getString("session_key"));
        }
        return res;
    }


    /**
     * 获取诊断
     *
     * @param pyKey
     * @return
     * @throws Exception
     */
    public JSONArray getICD10(String pyKey,boolean demoFlag) throws Exception {
        JSONArray array = ykyyEntranceService.findIcd10(pyKey,demoFlag);
        return array;
    }

    public String findYxVideoList(){
        WlyyHospitalSysDictDO sysDictDO = hospitalSysDictDao.findById("YXAPPKEY");
        WlyyHospitalSysDictDO hospitalSysDictDO =  hospitalSysDictDao.findById("YXAPPSECRET");
        if (sysDictDO==null){
            return  "找不到对应的key";
        }
        Long endTime = new Date().getTime();
        WlyyHospitalSysDictDO yxDownLoadVideoTime =  hospitalSysDictDao.findById("yxDownLoadVideoTime");
        /*long downVideoTime = 10;
        if (yxDownLoadVideoTime!=null&& StringUtils.isNotBlank(yxDownLoadVideoTime.getDictValue())){
            downVideoTime = Long.parseLong(yxDownLoadVideoTime.getDictValue());
        }*/
        Long startTime = new Date().getTime()-24*60*60*1000;
        String appKey = sysDictDO.getDictValue();
        String appSecret = hospitalSysDictDO.getDictValue();
        String nonce =  randomInt(10);
        String curTime = String.valueOf((new Date()).getTime() / 1000L);
        String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码
        String url = "https://vcloud.163.com/app/vod/video/list";
        Map<String,Object> httpPost = new HashedMap();
        // 设置请求的header
        httpPost.put("AppKey", appKey);
        httpPost.put("Nonce", nonce);
        httpPost.put("CurTime", curTime);
        httpPost.put("CheckSum", checkSum);
        httpPost.put("Content-Type", "application/json");
        JSONObject object = new JSONObject();
        object.put("currentPage",1);
        object.put("pageSize",500);
        object.put("status",40);
        object.put("type",0);
        object.put("beginTime",startTime);
        object.put("endTime",endTime);
        logger.info("入参"+object.toJSONString());
        String response = httpClientUtil.postBodyHead(url,object,httpPost);
        logger.info("返回日志"+response);
        if(StringUtils.isNoneBlank(response)){
            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
            if (jsonObject.getString("code").equalsIgnoreCase("200")){
                JSONObject object1 = jsonObject.getJSONObject("ret");
                if (object1!=null){
                    JSONArray jsonArray = object1.getJSONArray("list");
                    if (jsonArray!=null&&jsonArray.size()>0){
                        for (int i=0;i<jsonArray.size();i++){
                            JSONObject object2 = jsonArray.getJSONObject(i);
                            if (object2!=null){
                                String vedioUrl =object2.getString("origUrl");
                                String vedioName = object2.getString("videoName");
                                String filePath = "/Projects/Video/"+DateUtil.getStringDatePre("yyyyMMdd","1");
                                logger.info("filePath:"+filePath);
                                logger.info("vedioUrl"+vedioUrl);
                                FileUtil.saveUrlAs(vedioUrl,filePath,"GET",vedioName);
                            }
                        }

                    }
                }
            }
        }
        return null;
    }

    public String saveVideoFile(String vip){
        WlyyHospitalSysDictDO sysDictDO = hospitalSysDictDao.findById("YXAPPKEY");
        WlyyHospitalSysDictDO hospitalSysDictDO =  hospitalSysDictDao.findById("YXAPPSECRET");
        if (sysDictDO==null){
            return  "找不到对应的key";
        }
        String appKey = sysDictDO.getDictValue();
        String appSecret = hospitalSysDictDO.getDictValue();
        String nonce =  randomInt(10);
        String curTime = String.valueOf((new Date()).getTime() / 1000L);
        String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码
        String url = "https://vcloud.163.com/app/vod/video/get";
        Map<String,Object> httpPost = new HashedMap();
        // 设置请求的header
        httpPost.put("AppKey", appKey);
        httpPost.put("Nonce", nonce);
        httpPost.put("CurTime", curTime);
        httpPost.put("CheckSum", checkSum);
        httpPost.put("Content-Type", "application/json");
        JSONObject object = new JSONObject();
        object.put("vid",vip);
        logger.info("入参"+object.toJSONString());
        String response = httpClientUtil.postBodyHead(url,object,httpPost);
        logger.info("返回日志"+response);
        if(StringUtils.isNoneBlank(response)){
            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
            if (jsonObject.getString("code").equalsIgnoreCase("200")){
                JSONObject object1 = jsonObject.getJSONObject("ret");
                String vedioUrl =object1.getString("origUrl");
                String vedioName = object1.getString("videoName");
                String filePath = "/Projects/Video/"+DateUtil.getStringDate("yyyyMMdd");
                logger.info("filePath:"+filePath);
                logger.info("vedioUrl"+vedioUrl);
                FileUtil.saveUrlAs(vedioUrl,filePath,"GET",vedioName);
            }
        }
        return null;
    }
    public String saveVideoFileList(String startTime,String endTime,Integer status,Integer page ,Integer pageSize){
        WlyyHospitalSysDictDO sysDictDO = hospitalSysDictDao.findById("YXAPPKEY");

        WlyyHospitalSysDictDO hospitalSysDictDO =  hospitalSysDictDao.findById("YXAPPSECRET");
        if (sysDictDO==null){
            return  "找不到对应的key";
        }
        JSONObject object = new JSONObject();
        if (StringUtils.isNoneBlank(startTime)){
            Long start = DateUtil.strToDate(startTime).getTime();
            object.put("beginTime",start);
        }
        if (StringUtils.isNoneBlank(endTime)){
            Long end = DateUtil.strToDate(endTime).getTime();
            object.put("endTime",end);
        }
        if (status!=null){
            object.put("status",40);
        }
        object.put("type",0);
        String appKey = sysDictDO.getDictValue();
        String appSecret = hospitalSysDictDO.getDictValue();
        String nonce =  randomInt(10);
        String curTime = String.valueOf((new Date()).getTime() / 1000L);
        String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码
        String url = "https://vcloud.163.com/app/vod/video/list";
        Map<String,Object> httpPost = new HashedMap();
        // 设置请求的header
        httpPost.put("AppKey", appKey);
        httpPost.put("Nonce", nonce);
        httpPost.put("CurTime", curTime);
        httpPost.put("CheckSum", checkSum);
        httpPost.put("Content-Type", "application/json");
        object.put("currentPage",page);
        object.put("pageSize",pageSize);
        logger.info("入参"+object.toJSONString());
        String response = httpClientUtil.postBodyHead(url,object,httpPost);
        logger.info("返回日志"+response);
        if(StringUtils.isNoneBlank(response)){
            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
            if (jsonObject.getString("code").equalsIgnoreCase("200")){
                JSONObject object1 = jsonObject.getJSONObject("ret");
                if (object1!=null){
                    JSONArray jsonArray = object1.getJSONArray("list");
                    if (jsonArray!=null&&jsonArray.size()>0){
                        for (int i=0;i<jsonArray.size();i++){
                            JSONObject object2 = jsonArray.getJSONObject(i);
                            if (object2!=null){
                                String vedioUrl =object2.getString("origUrl");
                                String vedioName = object2.getString("videoName");
                                String filePath = "/Projects/Video/"+DateUtil.getStringDate("yyyyMMdd");
                                //String filePath = "D:\\Backup\\桌面\\配置及相关文档\\"+DateUtil.getStringDate("yyyyMMdd");
                                logger.info("filePath:"+filePath);
                                logger.info("vedioUrl"+vedioUrl);
                                FileUtil.saveUrlAs(vedioUrl,filePath,"GET",vedioName);
                            }
                        }

                    }
                }
            }
        }
        return null;
    }


}
