package com.huatek.busi.controller;

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

import com.huatek.busi.service.IBusiCableSensorService;
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.controller.helper.BusiGisRepairParamDto;
import com.huatek.busi.dto.BusiOfflineCableRepairDto;
import com.huatek.busi.service.cable.BusiOfflineCableRepairService;
import com.huatek.busi.vo.BusiOfflineGisRepairVo;
import com.huatek.busi.vo.BusiOfflineCableRepairVo;
import com.huatek.busi.vo.BusiSensorVo;
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 plus_wang
 * @date 2021.8.27 11:02:28
 */
@Api(tags = {Tags.BUSI_OFFLINE_GIS_REPAIR})
@Slf4j
@RestController
@RequestMapping("/api/BusiOfflineCableRepair")
public class BusiOfflineCableRepairController {
    @Reference(check = false)
    private BusiOfflineCableRepairService busiOfflineCableRepairService;
    @Reference(check = false)
    private IBusiCableSensorService busiCableSensorService;

    /**
     * 电缆检修记录 分页列表
     *
     * @param busiOfflineCableRepairDto
     *            其它检修记录Dto
     * @return map map
     */
    @ApiOperation(value = "列表分页查询", response = BusiOfflineGisRepairVo.class)
    @PostMapping(value = "/queryList", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> queryList(@RequestBody BusiOfflineCableRepairDto busiOfflineCableRepairDto) {
        PageInfo<BusiOfflineCableRepairVo> pageInfo =
                busiOfflineCableRepairService.findBusiOfflineCableRepairPage(busiOfflineCableRepairDto);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, pageInfo.getTotal(), "", pageInfo.getList());
    }

    /**
     * 通过id查找电缆检修记录
     *
     * @param id
     *            id
     * @return map map
     */
    @ApiOperation(value = "通过id查找其它检修记录", response = BusiOfflineGisRepairVo.class)
    @GetMapping(value = "/findCableRepair/{id}", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> findBusiOfflineCableRepair(@PathVariable(value = "id") String id) {
        BusiOfflineCableRepairVo busiOfflineCableRepairVo = busiOfflineCableRepairService.findBusiOfflineCableRepairVo(id);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiOfflineCableRepairVo);
    }

    /**
     * 修改电缆检修记录
     *
     * @param token
     *            the token
     * @param busiOfflineCableRepairDto
     *            其他检修记录Dto
     * @return the map
     */
    @ApiOperation(value = "修改其它检修记录")
    @PostMapping(value = "/saveOrUpdateCableRepair", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> saveOrUpdateCableRepair(@RequestHeader("token") String token,
                                                       @RequestBody BusiOfflineCableRepairDto busiOfflineCableRepairDto) {
        int count = busiOfflineCableRepairService.saveOrUpdateCableRepair(token, busiOfflineCableRepairDto);
        log.debug("updateBusiOfflineGisRepair: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    /**
     * 删除 电缆检修记录
     *
     * @param token
     *            the token
     * @return map map
     */
    @ApiOperation(value = "删除其它检修记录")
    @PostMapping(value = "/deleteCableRepair", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> deleteBusiOfflineCableRepair(@RequestHeader("token") String token,
                                                            @RequestBody List<String> ids) {
        int count = busiOfflineCableRepairService.deleteBusiOfflineCableRepair(token, ids);
        log.debug("deleteBusiOfflineGisRepair: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    /**
     * 处理电缆检修记录
     *
     * @param token
     *            the token
     * @param param
     *            其它检修记录Dto
     * @return map map
     */
    @ApiOperation(value = "处理其它检修记录")
    @PostMapping(value = "/dealCableRepair", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> dealCableRepair(@RequestHeader("token") String token,
                                               @RequestBody BusiGisRepairParamDto param) {
        busiOfflineCableRepairService.dealCableRepair(token, param.getIds(), param.getDealResult());
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    @ApiOperation(value = "传感器列表", response = BusiSensorVo.class)
    @GetMapping(value = "/sensorList", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> sensorList(Map<String, Object> params) {
        List<BusiSensorVo> list = busiCableSensorService.findSensorList(null);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }
}