package com.huatek.busi.controller;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.dto.GisMechanicalPropertiesDto;
import com.huatek.busi.service.gis.GisMechanicalPropertiesService;
import com.huatek.busi.vo.GisMechanicalPropertiesVo;
import com.huatek.torch.frame.log.KerLog;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * gis机械特性 控制层
 *
 * @author anker_cheng
 * @date Jul 4, 2019 2:15:27 PM
 */
@Api(tags = { Tags.BUSI_OFFLINE_GIS_MECHANICAL_PROPS })
@RestController
@RequestMapping("/api/GisMechanicalProperties")
public class GisMechanicalPropertiesController {

    protected final Logger logger = LoggerFactory.getLogger(GisMechanicalPropertiesController.class);

    @Reference(check = false)
    private GisMechanicalPropertiesService gisMechanicalPropertiesService;

    /**
     * gis机械特性 分页列表
     *
     * @param gisMechanicalPropertiesDto gis机械特性Dto
     * @return map map
     */
    @ApiOperation(value = "列表分页查询", response = GisMechanicalPropertiesVo.class)
    @KerLog(projectName = "PROJECTNAME", modelName = "GISMECHANICALPROPERTIES.MODELNAME", methodName = "GISMECHANICALPROPERTIES.METHODNAME.QUERYLIST")
    @PostMapping(value = "/queryList", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> queryList(@RequestBody GisMechanicalPropertiesDto gisMechanicalPropertiesDto) {
        return gisMechanicalPropertiesService.findGisMechanicalPropertiesPage(gisMechanicalPropertiesDto);
    }

    /**
     * 添加 gis机械特性
     *
     * @param token                      the token
     * @param gisMechanicalPropertiesDto gis机械特性Dto
     * @return map map
     */
    @ApiOperation(value = "添加 GIS机械特性")
    @KerLog(projectName = "PROJECTNAME", modelName = "GISMECHANICALPROPERTIES.MODELNAME", methodName = "GISMECHANICALPROPERTIES.METHODNAME.ADDGISMECHANICALPROPERTIES")
    @PostMapping(value = "/addGisMechanicalProperties", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> addGisMechanicalProperties(String token,
            @RequestBody GisMechanicalPropertiesDto gisMechanicalPropertiesDto) {
        int count = gisMechanicalPropertiesService.addGisMechanicalProperties(token, gisMechanicalPropertiesDto);
        logger.debug("addGisMechanicalProperties: {}", count);
        Map<String, Object> map = ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
        return map;
    }

    /**
     * 通过id查找 gis机械特性
     *
     * @param id id
     * @return map map
     */
    @ApiOperation(value = "通过ID查找 GIS机械特性", response = GisMechanicalPropertiesVo.class)
    @KerLog(projectName = "PROJECTNAME", modelName = "GISMECHANICALPROPERTIES.MODELNAME", methodName = "GISMECHANICALPROPERTIES.METHODNAME.FINDGISMECHANICALPROPERTIES")
    @GetMapping(value = "/findGisMechanicalProperties/{id}", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> findGisMechanicalProperties(@PathVariable(value = "id") String id) {
        GisMechanicalPropertiesVo gisMechanicalPropertiesVo = gisMechanicalPropertiesService
                .findGisMechanicalPropertiesVo(id);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", gisMechanicalPropertiesVo);
    }

    @ApiOperation(value = "获取最新一条GIS机械特性数据记录", response = GisMechanicalPropertiesVo.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "siteId", value = "站点ID"),
        @ApiImplicitParam(name = "mainEquipmentId", value = "主设备ID", required = true)
    })
    @GetMapping(value = "/lastGisMechanicalProperties", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> lastGisMechanicalProperties(
        @RequestParam(value = "siteId", required = false) String siteId,
        @RequestParam("mainEquipmentId") String mainEquipmentId) {
        GisMechanicalPropertiesVo gisMechanicalPropertiesVo =
            gisMechanicalPropertiesService.lastGisMechanicalProperties(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", gisMechanicalPropertiesVo);
    }
}