package com.zcloud.fire.check.web;


import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.zcloud.fire.check.api.FirePointServiceI;
import com.zcloud.fire.check.dto.*;
import com.zcloud.fire.check.dto.clientobject.FirePointCO;
import com.zcloud.fire.check.dto.clientobject.FirePointDeviceCO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * web-adapter
 *
 * @Author zhaokai
 * @Date 2025-11-26 10:12:54
 */
@Api(tags = "消防点位维护表")
@RequestMapping("/${application.gateway}/firePoint")
@RestController
@AllArgsConstructor
public class FirePointController {
    private final FirePointServiceI firePointService;

    @ApiOperation("消防点位新增")
    @PostMapping("/save")
    public SingleResponse<FirePointCO> add(@Validated @RequestBody FirePointAddCmd cmd) {
        return firePointService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    @PreAuthorize("@pms.hasAnyPermission('xfdwwh')")
    public PageResponse<FirePointCO> page(@RequestBody FirePointPageQry qry) {
        return firePointService.listPage(qry);
    }

    @ApiOperation("股份端点位分页")
    @PostMapping("/mainList")
    public PageResponse<FirePointCO> mainList(@RequestBody FirePointPageQry qry) {
        return firePointService.listPage(qry);
    }



    @ApiOperation("根据消防区域获取消防点位所有")
    @GetMapping("/listByFireRegionId/{fireRegionId}")
    public MultiResponse<FirePointCO> listByFireRegionId(@PathVariable("fireRegionId") String fireRegionId) {
        return firePointService.listByFireRegionId(fireRegionId);
    }

    @ApiOperation("消防点位详情")
    @GetMapping("/getInfoById/{id}")
    public SingleResponse<FirePointCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(firePointService.getInfoById(id));
    }

    @ApiOperation("删除")
    @GetMapping("/remove/{id}")
    public Response remove(@PathVariable("id") Long id) {
        firePointService.remove(id);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("删除多个")
    @PostMapping("/remove/ids")
    public Response removeBatch(@RequestBody FirePointRemoveCmd cmd) {
        firePointService.removeBatch(cmd.getIds());
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("修改")
    @PostMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody FirePointUpdateCmd firePointUpdateCmd) {
        firePointService.edit(firePointUpdateCmd);
        return SingleResponse.buildSuccess();
    }
    @ApiOperation("批量修改负责部门")
    @PostMapping("/editAllDepartment")
    public SingleResponse editAllDepartment(@Validated @RequestBody FirePointUpdateDepartmentCmd firePointUpdateDepartmentCmd) {
        firePointService.editAllDepartment(firePointUpdateDepartmentCmd);
        return SingleResponse.buildSuccess();
    }
    @ApiOperation("消防点位-导出")
    @GetMapping("/exportFirePointPage")
    public void exportFirePointPage(@RequestParam("ids") Long[] ids, HttpServletResponse httpServletResponse) {
        firePointService.exportFirePointPage(ids,httpServletResponse);
    }

    @ApiOperation("可视化大屏-消防点位设备列表")
    @PostMapping("/deviceList")
    public PageResponse<FirePointDeviceCO> deviceList(@RequestBody FirePointDeviceQry qry) {
        return firePointService.listDevice(qry);
    }
}

