package com.huatek.busi.controller;

import java.util.Map;

import com.huatek.busi.service.IBusiOfflineCableBrandService;
import com.huatek.busi.service.generatro.BusiOfflineGeneratorBrandService;
import com.huatek.busi.service.temperature.BusiOfflineSwitchgearBrandService;
import com.huatek.busi.vo.BusiOfflineCableBrandVo;
import org.springframework.web.bind.annotation.*;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.dto.*;
import com.huatek.busi.service.arrester.BusiOfflineArresterBrandService;
import com.huatek.busi.service.gis.BusiOfflineGisBrandService;
import com.huatek.busi.service.transformer.BusiOfflineTransformerBrandService;
import com.huatek.busi.vo.*;
import com.huatek.torch.frame.tools.*;

import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;

/**
 * 主设备标牌控制器
 *
 * <p>
 * 变压器标牌
 *
 * <p>
 * GIS标牌
 *
 * <p>
 * 避雷器标牌
 *
 * <p>
 * 电缆标牌
 *
 * @author anker_cheng
 * @date 2019/07/17
 */
@Api(tags = {Tags.BUSI_MAIN_EQUIP_BRAND})
@Slf4j
@RestController
@RequestMapping("/api/mainEquipmentBrand")
public class MainEquipmentBrandController {

    @Reference(check = false)
    private BusiOfflineTransformerBrandService busiOfflineTransformerBrandService;
    @Reference(check = false)
    private BusiOfflineGisBrandService busiOffllineGisBrandService;
    @Reference(check = false)
    private BusiOfflineArresterBrandService busiOfflineArresterBrandService;
    @Reference(check = false)
    IBusiOfflineCableBrandService busiOfflineCableBrandService;
    @Reference(check = false)
    private BusiOfflineGeneratorBrandService busiOfflineGeneratorBrandService;
    @Reference(check = false)
    private BusiOfflineSwitchgearBrandService busiOfflineSwitchgearBrandService;


    // *********************************变压器********************************\\
    /**
     * 获取变压器标牌信息
     *
     * @param siteId
     *            站点ID
     * @param mainEquipmentId
     *            主设备ID
     * @return
     */
    @ApiOperation(value = "获取变压器标牌信息", response = BusiOfflineTransformerBrandVo.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "siteId", value = "站点ID"),
        @ApiImplicitParam(name = "mainEquipmentId", value = "主设备ID", required = true)
    })
    @GetMapping(value = "/transformer/info", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> transformerBrandInfo(@RequestParam(value = "siteId", required = false) String siteId,
        @RequestParam("mainEquipmentId") String mainEquipmentId) {
        BusiOfflineTransformerBrandVo busiOfflineTransformerBrandVo =
            busiOfflineTransformerBrandService.getBusiOfflineTransformerBrandVo(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiOfflineTransformerBrandVo);
    }

    /**
     * 保存变压器标牌信息
     *
     * @param token
     *            token
     * @param busiOfflineTransformerBrandDto
     *            busiOfflineTransformerBrandDto
     * @return
     */
    @ApiOperation(value = "保存变压器标牌信息")
    @PostMapping(value = "/transformer/save", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> saveTransformerBrandInfo(String token,
        @RequestBody BusiOfflineTransformerBrandDto busiOfflineTransformerBrandDto) {
        int count = busiOfflineTransformerBrandService.saveBusiOfflineTransformerBrand(token, busiOfflineTransformerBrandDto);
        log.debug("saveTransformerBrandInfo: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }



//    /**
//     * 保存变压器标牌信息
//     *
//     * @return
//     */
//    @ApiOperation(value = "保存变压器排序信息")
//    @PostMapping(value = "/saveSort", produces = {"application/json;charset=utf-8"})
//    public Map<String, Object> saveSort(String token, @RequestBody BusiOfflineTransformerBrandDto busiOfflineTransformerBrandDto) {
//        int count = busiOfflineTransformerBrandService.saveBusiOfflineTransformerBrandSort(token, busiOfflineTransformerBrandDto);
//        log.debug("saveTransformerBrandInfo: {}", count);
//        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
//    }

    // *********************************GIS********************************\\
    /**
     * 获取GIS标牌信息
     *
     * @param siteId
     *            站点ID
     * @param mainEquipmentId
     *            主设备ID
     * @return
     */
    @ApiOperation(value = "获取GIS标牌信息", response = BusiOfflineGisBrandVo.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "siteId", value = "站点ID"),
        @ApiImplicitParam(name = "mainEquipmentId", value = "主设备ID", required = true)
    })
    @GetMapping(value = "/gis/info", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> gisBrandInfo(@RequestParam(value = "siteId", required = false) String siteId,
        @RequestParam("mainEquipmentId") String mainEquipmentId) {
        BusiOfflineGisBrandVo busiOffllineGisBrandVo =
            busiOffllineGisBrandService.findBusiOfflineGISBrand(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiOffllineGisBrandVo);
    }

    /**
     * 保存GIS标牌信息
     *
     * @param token
     *            token
     * @param busiOffllineGisBrandDto
     *            busiOffllineGisBrandDto
     * @return
     */
    @ApiOperation(value = "保存GIS标牌信息")
    @PostMapping(value = "/gis/save", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> saveGisBrandInfo(String token,
        @RequestBody BusiOffllineGisBrandDto busiOffllineGisBrandDto) {
        int count = busiOffllineGisBrandService.updateBusiOffllineGisBrand(token, busiOffllineGisBrandDto);
        log.debug("saveGisBrandInfo: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    // *********************************开关柜********************************\\
    /**
     * 获取开关柜标牌信息
     *
     * @param siteId
     *            站点ID
     * @param mainEquipmentId
     *            主设备ID
     * @return
     */
    @ApiOperation(value = "获取开关柜标牌信息", response = BusiOfflineGisBrandVo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "siteId", value = "站点ID"),
            @ApiImplicitParam(name = "mainEquipmentId", value = "主设备ID", required = true)
    })
    @GetMapping(value = "/switchgear/info", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> switchgearBrandInfo(@RequestParam(value = "siteId", required = false) String siteId,
                                            @RequestParam("mainEquipmentId") String mainEquipmentId) {
        BusiOfflineSwitchgearBrandVo busiOffllineSwitchgearBrandVo =
                busiOfflineSwitchgearBrandService.findBusiOfflineSwitchgearBrand(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiOffllineSwitchgearBrandVo);
    }

    /**
     * 保存开关柜标牌信息
     *
     * @param token
     *            token
     *            BusiOfflineSwitchgearBrandDto
     * @return
     */
    @ApiOperation(value = "保存开关柜标牌信息")
    @PostMapping(value = "/switchgear/save", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> saveSwitchgearBrandInfo(@RequestHeader("") String token,
                                                      @RequestBody BusiOfflineSwitchgearBrandDto busiOffllineSwitchgearBrandDto) {

        return busiOfflineSwitchgearBrandService.updateBusiOfflineSwitchgearBrand(token, busiOffllineSwitchgearBrandDto);

    }

    // *********************************发电机********************************\\
    /**
     * 获取发电机标牌信息
     *
     * @param siteId
     *            站点ID
     * @param mainEquipmentId
     *            主设备ID
     * @return
     */
    @ApiOperation(value = "获取发电机标牌信息", response = BusiOfflineGisBrandVo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "siteId", value = "站点ID"),
            @ApiImplicitParam(name = "mainEquipmentId", value = "主设备ID", required = true)
    })
    @GetMapping(value = "/generator/info", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> generatorBrandInfo(@RequestParam(value = "siteId", required = false) String siteId,
                                            @RequestParam("mainEquipmentId") String mainEquipmentId) {
        BusiOfflineGeneratorBrandVo busiOfflineGeneratorBrandVo =
                busiOfflineGeneratorBrandService.findBusiOfflineGeneratorBrand(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiOfflineGeneratorBrandVo);
    }

    /**
     * 保存发电机标牌信息
     *
     * @param token
     *            token
     * @param busiOfflineGeneratorBrandDto
     *            busiOfflineGeneratorBrandDto
     * @return
     */
    @ApiOperation(value = "保存发电机标牌信息")
    @PostMapping(value = "/generator/save", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> saveGeneratorBrandInfo(@RequestHeader("") String token,
                                                      @RequestBody BusiOfflineGeneratorBrandDto busiOfflineGeneratorBrandDto) {

        return busiOfflineGeneratorBrandService.saveBusiOfflineGeneratorBrand(token, busiOfflineGeneratorBrandDto);

    }


    // *********************************避雷器********************************\\
    /**
     * 获取避雷器标牌信息
     *
     * @param siteId
     *            站点ID
     * @param mainEquipmentId
     *            主设备ID
     * @return
     */
    @ApiOperation(value = "获取避雷器标牌信息", response = BusiOfflineArresterBrandVo.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "siteId", value = "站点ID"),
        @ApiImplicitParam(name = "mainEquipmentId", value = "主设备ID", required = true)
    })
    @GetMapping(value = "/arrester/info", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> arresterBrandInfo(@RequestParam(value = "siteId", required = false) String siteId,
        @RequestParam("mainEquipmentId") String mainEquipmentId) {
        BusiOfflineArresterBrandVo busiOfflineArresterBrandVo =
            busiOfflineArresterBrandService.getBusiOfflineArresterBrandInfo(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiOfflineArresterBrandVo);
    }

    /**
     * 保存避雷器标牌信息
     *
     * @param token
     *            token
     * @param busiOfflineArresterBrandDto
     *            busiOfflineArresterBrandDto
     * @return
     */
    @ApiOperation(value = "保存避雷器标牌信息")
    @PostMapping(value = "/arrester/save", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> saveArresterBrandInfo(String token,
        @RequestBody BusiOfflineArresterBrandDto busiOfflineArresterBrandDto) {
        int count = busiOfflineArresterBrandService.saveBusiOfflineArresterBrand(token, busiOfflineArresterBrandDto);
        log.debug("saveArresterBrandInfo: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    @ApiOperation(value = "获取电缆标牌信息")
    @GetMapping(value = "/cable/info", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> cableBrandInfo(@RequestParam(value = "siteId", required = false) String siteId,
                                                 @RequestParam("mainEquipmentId") String mainEquipmentId) {
        BusiOfflineCableBrandVo busiOfflineCableBrandVo =
                busiOfflineCableBrandService.getBusiOfflineCableBrandInfo(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiOfflineCableBrandVo);
    }

    @ApiOperation(value = "保存电缆标牌信息")
    @PostMapping(value = "/cable/save", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> saveCableBrandInfo(@RequestHeader("token") String token,
                                                  @RequestBody BusiOfflineCableBrandVo busiOfflineCableBrandVo) {
        return busiOfflineCableBrandService.saveBusiOfflineCableBrand(token, busiOfflineCableBrandVo);
    }
}
