package com.huatek.busi.controller;

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.BusiOfflineTransformerCheckDto;
import com.huatek.busi.service.transformer.BusiOfflineTransformerCheckService;
import com.huatek.busi.vo.BusiOfflineTransformerCheckVo;
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;

/**
 * 变压器投运验收结论 控制层
 *
 * @author anker_cheng
 * @date Jul 4, 2019 2:15:27 PM
 */
@Api(tags = { Tags.BUSI_OFFLINE_TRANSFORMER_CHECK })
@Slf4j
@RestController
@RequestMapping("/api/BusiOfflineTransformerCheck")
public class BusiOfflineTransformerCheckController {
    @Reference(check = false)
    private BusiOfflineTransformerCheckService busiOfflineTransformerCheckService;

    /**
     * 变压器投运验收结论 分页列表
     *
     * @param busiOfflineTransformerCheckDto 变压器投运验收结论Dto
     * @return map map
     */
    @ApiOperation(value = "列表分页查询", response = BusiOfflineTransformerCheckVo.class)
    @PostMapping(value = "/queryList", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> queryList(@RequestBody BusiOfflineTransformerCheckDto busiOfflineTransformerCheckDto) {
        PageInfo<BusiOfflineTransformerCheckVo> pageInfo =
            busiOfflineTransformerCheckService.findBusiOfflineTransformerCheckPage(busiOfflineTransformerCheckDto);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, pageInfo.getTotal(), "", pageInfo.getList());
    }

    /**
     * 添加 变压器投运验收结论
     *
     * @param token                          the token
     * @param busiOfflineTransformerCheckDto 变压器投运验收结论Dto
     * @return map map
     */
    @ApiOperation(value = "添加 变压器投运验收结论")
    @PostMapping(value = "/addBusiOfflineTransformerCheck", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> addBusiOfflineTransformerCheck(@RequestHeader("token")String token,
            @RequestBody BusiOfflineTransformerCheckDto busiOfflineTransformerCheckDto) {
        int count = busiOfflineTransformerCheckService.saveOrUpdate(token, busiOfflineTransformerCheckDto);
        log.debug("addBusiOfflineTransformerCheck: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    /**
     * 通过id查找 变压器投运验收结论
     *
     * @param id id
     * @return map map
     */
    @ApiOperation(value = "通过id查找 变压器投运验收结论", response = BusiOfflineTransformerCheckVo.class)
    @GetMapping(value = "/findBusiOfflineTransformerCheck/{id}", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> findBusiOfflineTransformerCheck(@PathVariable(value = "id") String id) {
        BusiOfflineTransformerCheckVo busiOfflineTransformerCheckVo = busiOfflineTransformerCheckService
                .findBusiOfflineTransformerCheckVo(id);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiOfflineTransformerCheckVo);
    }

    /**
     * 修改 变压器投运验收结论
     *
     * @param token                          the token
     * @param busiOfflineTransformerCheckDto 变压器投运验收结论Dto
     * @return the map
     */
    @ApiOperation(value = "修改 变压器投运验收结论")
    @PostMapping(value = "/updateBusiOfflineTransformerCheck", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> updateBusiOfflineTransformerCheck(@RequestHeader("token")String token,
            @RequestBody BusiOfflineTransformerCheckDto busiOfflineTransformerCheckDto) {
        int count = busiOfflineTransformerCheckService.saveOrUpdate(token,
                busiOfflineTransformerCheckDto);
        log.debug("updateBusiOfflineTransformerCheck: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    /**
     * 删除 变压器投运验收结论
     *
     * @param token                          the token
     * @param busiOfflineTransformerCheckDto 变压器投运验收结论Dto
     * @return map map
     */
    @ApiOperation(value = "删除 变压器投运验收结论")
    @PostMapping(value = "/deleteBusiOfflineTransformerCheck", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> deleteBusiOfflineTransformerCheck(@RequestHeader("token")String token, @RequestBody String[] ids) {
        busiOfflineTransformerCheckService.deleteBusiOfflineTransformerCheck(ids);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }
}