package com.yihu.jw.base.endpoint.equipment;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.service.equipment.BaseHospitalEquipmentService;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.entity.equipment.BaseHospitalEquipmentDO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;

/**
 * Created by wangzhinan on 2021/09/16.
 * 设备管理
 */
@RestController
@RequestMapping(value = BaseRequestMapping.Equipment.PREFIX)
@Api(value = "设备管理", description = "设备管理接口", tags = {"设备管理接口"})
public class EquipmentEndpoint extends EnvelopRestEndpoint {

    @Autowired
    public BaseHospitalEquipmentService hospitalEquipmentService;

    @PostMapping(value = BaseRequestMapping.Equipment.selectByHospitalOrTown)
    @ApiOperation(value = "根据医院code/区域code查找设备")
    public ListEnvelop selectByHospitalOrTown (
            @ApiParam(name = "town", value = "区code", required = false)
            @RequestParam(value = "town", required = false) String town,
            @ApiParam(name = "hospital", value = "医院code或者区域code", required = false)
            @RequestParam(value = "hospital", required = false) String hospital,
            @ApiParam(name = "name", value = "设备名称", required = false)
            @RequestParam(value = "name", required = false) String name) throws Exception {
        List<Map<String,Object>> mapList =  hospitalEquipmentService.selectByHospitalOrTown(town,hospital,name);
        ListEnvelop listEnvelop = new ListEnvelop();
        listEnvelop.setDetailModelList(mapList);
        return listEnvelop;
    }

    @PostMapping(value = BaseRequestMapping.Equipment.selectEquipment)
    @ApiOperation(value = "查询机器（分配投放地址）")
    public ListEnvelop selectEquipment(@ApiParam(name = "code", value = "设备编码", required = false)
                                   @RequestParam(value = "code", required = false) String code,
                                       @ApiParam(name = "typeName", value = "设备分类名称", required = false)
                                   @RequestParam(value = "typeName", required = false) String typeName,
                                       @ApiParam(name = "adress", value = "投放地址", required = false)
                                   @RequestParam(value = "adress", required = false) String address,
                                       @ApiParam(name = "hospitalName", value = "所属社区", required = false)
                                   @RequestParam(value = "hospitalName", required = false) String hospitalName){

        List<Map<String,Object>> map = hospitalEquipmentService.selectEquipment(code,typeName,address,hospitalName);
        ListEnvelop listEnvelop = new ListEnvelop();
        listEnvelop.setMessage("success");
        listEnvelop.setDetailModelList(map);
        return listEnvelop;
    }


}
