package com.securitycontrol.background.controller;

import com.securitycontrol.background.service.DeviceService;
import com.securitycontrol.background.service.EmergencyService;
import com.securitycontrol.background.service.TbAreaService;
import com.securitycontrol.common.core.domain.Result;
import com.securitycontrol.common.core.utils.WordUtils;
import com.securitycontrol.common.core.web.controller.BaseController;
import com.securitycontrol.common.core.web.page.TableDataInfo;
import com.securitycontrol.common.log.annotation.Log;
import com.securitycontrol.common.log.enums.OperationType;
import com.securitycontrol.entity.background.dto.AreaDto;
import com.securitycontrol.entity.background.dto.DeviceDto;
import com.securitycontrol.entity.background.vo.AreaVo;
import com.securitycontrol.entity.background.vo.DeviceVo;
import com.securitycontrol.entity.background.vo.EmergencyPlanVo;
import com.securitycontrol.entity.background.vo.GtVo;
import com.securitycontrol.entity.file.FileExportVo;
import com.securitycontrol.entity.screen.vo.ProCostVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * 区域管理接口
 * 杆塔 管理接口
 * @author 黑子
 */
@RestController
@RequestMapping("/back/area/")
@Slf4j
public class TbAreaController  extends BaseController {

    @Autowired
    private TbAreaService service;


    @ApiOperation(value = "查询工程成本")
    @GetMapping("getProCostList")
    @Log(title = "工程管理", menu = "基础管理->工程管理", grade = OperationType.QUERY_BUSINESS, details = "查询工程成本", type = "业务日志")
    public TableDataInfo getProCostList(AreaDto dto) {
        try{
            startPage();
            List<ProCostVo> list = service.getProCostList(dto);
            return getDataTable(list);
        }catch (Exception e){
            log.error(e.toString(),e);
            return getDataTableBad(new ArrayList<>(),"请求出错了");
        }
    }

    /**
     * 新增成本
     *
     * @param dto
     * @return
     */
    @PostMapping("addCost")
    @Log(title = "工程管理", menu = "基础管理->工程管理", grade = OperationType.ADD_BUSINESS, details = "新增成本", type = "业务日志")
    public Result<String> addCost(@RequestBody ProCostVo dto) {
        return service.addCost(dto);
    }

    /**
     * 修改成本
     *
     * @param dto
     * @return
     */
    @PostMapping("updateCost")
    @Log(title = "工程管理", menu = "基础管理->工程管理", grade = OperationType.ADD_BUSINESS, details = "修改成本", type = "业务日志")
    public Result<String> updateCost(@RequestBody ProCostVo dto) {
        return service.updateCost(dto);
    }

    /**
     * 删除维护成本
     * @param dto
     * @return
     */
    @PostMapping("deleteCost")
    @Log(title = "工程管理", menu = "基础管理->工程管理", grade = OperationType.ADD_BUSINESS, details = "删除成本", type = "业务日志")
    public Result<String> deleteCost(@RequestBody ProCostVo dto) {
        return service.deleteCost(dto);
    }

    @ApiOperation(value = "获取设备列表")
    @GetMapping("getAreaList")
    @Log(title = "区域管理", menu = "基础管理->区域管理", grade = OperationType.QUERY_BUSINESS, details = "查询区域列表", type = "业务日志")
    public TableDataInfo getAreaList(AreaDto dto) {
        try{
            startPage();
            List<AreaVo> list = service.getAreaList(dto);
            return getDataTable(list);
        }catch (Exception e){
            log.error(e.toString(),e);
            return getDataTableBad(new ArrayList<>(),"请求出错了");
        }
    }

    @ApiOperation(value = "查询杆塔列表")
    @GetMapping("getGtList")
    @Log(title = "杆塔管理", menu = "基础管理->区域管理", grade = OperationType.QUERY_BUSINESS, details = "查询杆塔信息", type = "业务日志")
    public TableDataInfo getGtList(AreaDto dto) {
        try{
            startPage();
            List<GtVo> list = service.getGtList(dto);
            return getDataTable(list);
        }catch (Exception e){
            log.error(e.toString(),e);
            return getDataTableBad(new ArrayList<>(),"请求出错了");
        }
    }

    /**
     * 新增区域
     *
     * @param dto
     * @return
     */
    @PostMapping("addGtData")
    @Log(title = "杆塔管理", menu = "基础管理->区域管理", grade = OperationType.ADD_BUSINESS, details = "新增杆塔", type = "业务日志")
    public Result<String> addGtData(@RequestBody @Valid GtVo dto) {
        return service.addGtData(dto);
    }

    /**
     * 新增杆塔
     * @param dto
     * @return
     */
    @PostMapping("updateGtData")
    @Log(title = "杆塔管理", menu = "基础管理->区域管理", grade = OperationType.UPDATE_BUSINESS, details = "修改杆塔", type = "业务日志")
    public Result<String> updateGtData(@RequestBody @Valid GtVo dto) {
        return service.updateGtData(dto);
    }

    /**
     *删除杆塔
     * @param dto
     * @return
     */
    @PostMapping("deleteGt")
    @Log(title = "杆塔管理", menu = "基础管理->区域管理", grade = OperationType.DELETE_BUSINESS, details = "删除杆塔", type = "业务日志")
    public Result<String> deleteGt(@RequestBody @Valid GtVo dto) {
        return service.deleteGt(dto);
    }




    /**
     * 新增区域
     *
     * @param dto
     * @return
     */
    @PostMapping("addArea")
    @Log(title = "新增区域", menu = "基础管理->区域管理", grade = OperationType.ADD_BUSINESS, details = "新增区域", type = "业务日志")
    public Result<String> addArea(@RequestBody @Valid AreaVo dto) {
        return service.addArea(dto);
    }

    /**
     * 修改区域
     * @param dto
     * @return
     */
    @PostMapping("updateArea")
    @Log(title = "修改区域", menu = "基础管理->区域管理", grade = OperationType.UPDATE_BUSINESS, details = "修改区域", type = "业务日志")
    public Result<String> updateArea(@RequestBody @Valid AreaVo dto) {
        return service.updateArea(dto);
    }
    /**
     * 删除区域
     * 批量删除
     * @param dto
     * @return
     */
    @PostMapping("deleteArea")
    @Log(title = "修改区域", menu = "基础管理->区域管理", grade = OperationType.QUERY_BUSINESS, details = "删除区域", type = "业务日志")
    public Result<String> deleteArea(@RequestBody @Valid AreaDto dto) {
        return service.deleteArea(dto);
    }


    /**
     *
     *查询区域 依据id
     * @param dto
     * @return
     */
    @PostMapping("getAreaById")
    public Result<AreaVo> getAreaById(@RequestBody @Valid AreaDto dto) {
        return service.getAreaById(dto);
    }

    /**
     * 查询杆塔 依据id
     * @param dto
     * @return
     */
    @PostMapping("getGtById")
    public Result<GtVo> getGtById(@RequestBody @Valid AreaDto dto) {
        return service.getGtById(dto);
    }


    @ApiOperation(value = "获取三维文件列表")
    @GetMapping("getSwList")
    @Log(title = "三维文件管理", menu = "基础管理->三维文件管理", grade = OperationType.QUERY_BUSINESS, details = "查询三维文件列表", type = "业务日志")
    public TableDataInfo getSwList(AreaDto dto) {
        try{
            startPage();
            List<AreaVo> list = service.getSwList(dto);
            return getDataTable(list);
        }catch (Exception e){
            log.error(e.toString(),e);
            return getDataTableBad(new ArrayList<>(),"请求出错了");
        }
    }

    @ApiOperation(value = "新增三维文件")
    @PostMapping("addSwFile")
    @Log(title = "三维管理", menu = "应急响应->三维管理", grade = OperationType.ADD_BUSINESS, details = "新增三维文件", type = "业务日志")
    public  Result<String> addYaFile(@RequestParam(value = "file[]", required = false) MultipartFile[] files, AreaVo dto ) {
        return service.addSwFile(files, dto);
    }

    @ApiOperation(value = "删除信息")
    @PostMapping("deleteSwFile")
    @Log(title = "三维管理", menu = "应急响应->三维管理", grade = OperationType.DELETE_BUSINESS, details = "删除三维文件", type = "业务日志")
    public  Result<String> deleteSwFile(@RequestBody AreaVo dto ) {
        return service.deleteSwFile(dto);
    }





}
