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.jjb.saas.framework.auth.model.SSOUser;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.fire.check.api.FireCheckListServiceI;
import com.zcloud.fire.check.api.FireDeviceServiceI;
import com.zcloud.fire.check.dto.*;
import com.zcloud.fire.check.dto.clientobject.CorpStatisticsCO;
import com.zcloud.fire.check.dto.clientobject.FireDeviceCO;
import com.zcloud.fire.check.dto.clientobject.RiskDistributionStasticCO;
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 org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;

/**
 * web-adapter
 *
 * @Author zhaokai
 * @Date 2025-11-26 10:12:34
 */
@Api(tags = "消防器材维护表")
@RequestMapping("/${application.gateway}/fireDevice")
@RestController
@AllArgsConstructor
public class FireDeviceController {
    private final FireDeviceServiceI fireDeviceService;
    private final FireCheckListServiceI fireCheckListService;

    @ApiOperation("消防器材新增")
    @PostMapping("/save")
    public SingleResponse<FireDeviceCO> add(@Validated @RequestBody FireDeviceAddCmd cmd) {
        return fireDeviceService.add(cmd);
    }

    @ApiOperation("消防器材分页")
    @PostMapping("/list")
    @PreAuthorize("@pms.hasAnyPermission('xfqcgl')")
    public PageResponse<FireDeviceCO> page(@RequestBody FireDevicePageQry qry) {
        return fireDeviceService.listPage(qry);
    }
    @ApiOperation("股份端-消防器材分页")
    @PostMapping("/mainList")
    public PageResponse<FireDeviceCO> mianList(@RequestBody FireDevicePageQry qry) {
        return fireDeviceService.listPage(qry);
    }

    @ApiOperation("消防器材详情")
    @GetMapping("/getInfoById/{id}")
    public SingleResponse<FireDeviceCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(fireDeviceService.getInfoById(id));
    }

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

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

    @ApiOperation("修改")
    @PostMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody FireDeviceUpdateCmd fireDeviceUpdateCmd) {
        fireDeviceService.edit(fireDeviceUpdateCmd);
        return SingleResponse.buildSuccess();
    }
    @ApiOperation("消防器材-导出")
    @GetMapping("/exportFireDevicePage")
    public void exportFireDevicePage(@RequestParam(value = "ids") Long[] ids, HttpServletResponse httpServletResponse) {
        fireDeviceService.exportFireDevicePage(ids, httpServletResponse);
    }
    @ApiOperation("消防器材-导入")
    @PostMapping("/importFireDevicePage")
    public Response importFireDevicePage(@RequestPart(value = "file") MultipartFile file) {
        fireDeviceService.importFireDevicePage(file);
        return SingleResponse.buildSuccess();
    }
    @ApiOperation("根据条件获取所有消防器材")
    @PostMapping("/getAllList")
    public MultiResponse<FireDeviceCO> getAllList(@RequestBody FireDeviceListQry qry) {
        return MultiResponse.of(fireDeviceService.getAllList(qry));
    }

    @ApiOperation("股份端-消防器材统计汇总首页分页")
    @PostMapping("/corpStatisticslist")
    @PreAuthorize("@pms.hasAnyPermission('xfqctjhz')")
    public PageResponse<CorpStatisticsCO> corpStatisticslist(@RequestBody CorpStatisticsPageQry qry) {
        return fireDeviceService.corpStatisticslist(qry);
    }
    @ApiOperation("股份端-消防器材统计汇总首页总数")
    @GetMapping("/corpStatisticsTotal")
    @PreAuthorize("@pms.hasAnyPermission('xfqctjhz')")
    public SingleResponse<RiskDistributionStasticCO> corpStatisticsTotal() {
        return SingleResponse.of(fireCheckListService.riskDistributionStatistic());
    }

    @ApiOperation("H5s扫码-点位分布-消防器材分页查询，(H5扫码点位分布可使用)")
    @PostMapping("/pageByPointId")
    public PageResponse<FireDeviceCO> pageByPointId(@RequestBody FireDevicePageQry qry) {
        return fireDeviceService.pageByPointId(qry);
    }
}

