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.controller.helper.BusiGisRepairParamDto;
import com.huatek.busi.dto.BusiOfflineOtherRepairDto;
import com.huatek.busi.service.BusiOtherSensorService;
import com.huatek.busi.service.Other.BusiOfflineOtherRepairService;
import com.huatek.busi.vo.BusiOfflineOtherRepairVo;
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 anker_cheng
 * @date Jul 4, 2019 2:15:27 PM
 */
@Api(tags = {Tags.BUSI_OFFLINE_GIS_REPAIR})
@Slf4j
@RestController
@RequestMapping("/api/BusiOfflineOtherRepair")
public class BusiOfflineOtherRepairController {
    @Reference(check = false)
    private BusiOfflineOtherRepairService busiOfflineOtherRepairService;
    @Reference(check = false)
    private BusiOtherSensorService busiOtherSensorService;

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

    /**
     * 通过id查找其它检修记录
     *
     * @param id
     *            id
     * @return map map
     */
    @ApiOperation(value = "通过id查找其它检修记录", response = BusiOfflineOtherRepairVo.class)
    @GetMapping(value = "/findOtherRepair/{id}", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> findBusiOfflineOtherRepair(@PathVariable(value = "id") String id) {
        BusiOfflineOtherRepairVo busiOfflineOtherRepairVo = busiOfflineOtherRepairService.findBusiOfflineOtherRepairVo(id);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiOfflineOtherRepairVo);
    }

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

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

    /**
     * 处理其它检修记录
     *
     * @param token
     *            the token
     * @param busiOfflineGisRepairDto
     *            其它检修记录Dto
     * @return map map
     */
    @ApiOperation(value = "处理其它检修记录")
    @PostMapping(value = "/dealOtherRepair", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> dealOtherRepair(@RequestHeader("token") String token,
        @RequestBody BusiGisRepairParamDto param) {
        busiOfflineOtherRepairService.dealOtherRepair(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 = busiOtherSensorService.findSensorList(null);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
    }
}