package com.huatek.busi.controller;

import java.util.List;
import java.util.Map;

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.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.dto.BusiOfflineGisCheckDto;
import com.huatek.busi.service.gis.BusiOfflineGisCheckService;
import com.huatek.busi.vo.BusiOfflineGisCheckVo;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * GIS投运验收结论 控制层
 *
 * @author anker_cheng
 * @date Jul 4, 2019 2:15:27 PM
 */
@Api(tags = { Tags.BUSI_OFFLINE_GIS_CHECK })
@Slf4j
@RestController
@RequestMapping("/api/BusiOfflineGisCheck")
public class BusiOfflineGisCheckController {
    @Reference(check = false)
    private BusiOfflineGisCheckService busiOfflineGisCheckService;

    @ApiOperation(value = "列表分页查询", response = BusiOfflineGisCheckVo.class)
    @PostMapping(value = "/queryList", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> queryList(@RequestBody BusiOfflineGisCheckDto busiOfflineGisCheckDto) {
        PageInfo<BusiOfflineGisCheckVo> pageInfo =
            busiOfflineGisCheckService.findBusiOfflineGisCheckPage(busiOfflineGisCheckDto);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, pageInfo.getTotal(), "", pageInfo.getList());
    }

    @ApiOperation(value = "添加 GIS投运验收结论")
    @PostMapping(value = "/addBusiOfflineGisCheck", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> addBusiOfflineGisCheck(@RequestHeader("token")String token,
            @RequestBody BusiOfflineGisCheckDto busiOfflineGisCheckDto) {
        int count = busiOfflineGisCheckService.saveOrUpdate(token, busiOfflineGisCheckDto);
        log.debug("addBusiOfflineGisCheck: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    @ApiOperation(value = "通过id查找 GIS投运验收结论", response = BusiOfflineGisCheckVo.class)
    @GetMapping(value = "/findBusiOfflineGisCheck/{id}", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> findBusiOfflineGisCheck(@PathVariable(value = "id") String id) {
        BusiOfflineGisCheckVo busiOfflineGisCheckVo = busiOfflineGisCheckService.findBusiOfflineGisCheckVo(id);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiOfflineGisCheckVo);
    }

    @ApiOperation(value = "修改 GIS投运验收结论")
    @PostMapping(value = "/updateBusiOfflineGisCheck", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> updateBusiOfflineGisCheck(@RequestHeader("token")String token,
            @RequestBody BusiOfflineGisCheckDto busiOfflineGisCheckDto) {
        int count = busiOfflineGisCheckService.saveOrUpdate(token, busiOfflineGisCheckDto);
        log.debug("updateBusiOfflineGisCheck: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    @ApiOperation(value = "删除 GIS投运验收结论")
    @PostMapping(value = "/deleteBusiOfflineGisCheck", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> deleteBusiOfflineGisCheck(@RequestHeader("token")String token, @RequestBody List<String> ids) {
        int count = busiOfflineGisCheckService.deleteBusiOfflineGisCheck(token, ids);
        log.debug("deleteBusiOfflineGisCheck: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

}