package com.srs.web.controller.staff;

import com.srs.common.annotation.Log;
import com.srs.common.annotation.RepeatSubmit;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.core.page.TableDataInfo;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.staff.domain.SrsStaffOneStopCommunityConstruction;
import com.srs.staff.service.ISrsStaffOneStopCommunityConstructionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 一站式社区模块：社区建设Controller
 *
 * @author chc
 * @date 2024-07-17
 */
@RestController
@RequestMapping("/staff/oneStopCommunityConstruction")
@Api(value = "一站式社区模块-社区建设管理", tags = "一站式社区模块-社区建设管理")
public class SrsStaffOneStopCommunityConstructionController extends BaseController {
    @Autowired
    private ISrsStaffOneStopCommunityConstructionService srsStaffOneStopCommunityConstructionService;

    /**
     * 查询一站式社区模块：社区建设列表
     */
    @PreAuthorize("@ss.hasPermi('staff:oneStopCommunityConstruction:list')")
    @GetMapping("/list")
    @ApiOperation("查询一站式社区模块：社区建设列表")
    public TableDataInfo list(SrsStaffOneStopCommunityConstruction srsStaffOneStopCommunityConstruction) {
        startPage();
        List<SrsStaffOneStopCommunityConstruction> list = srsStaffOneStopCommunityConstructionService.selectSrsStaffOneStopCommunityConstructionList(srsStaffOneStopCommunityConstruction);
        return getDataTable(list);
    }

    /**
     * 导出一站式社区模块：社区建设列表
     */
    @PreAuthorize("@ss.hasPermi('staff:oneStopCommunityConstruction:export')")
    @Log(title = "一站式社区模块：社区建设", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出一站式社区模块：社区建设列表")
    public void export(HttpServletResponse response, SrsStaffOneStopCommunityConstruction srsStaffOneStopCommunityConstruction) {
        // 从请求中获取ID列表
        List<Long> ids = srsStaffOneStopCommunityConstruction.getIds();

        // 根据ID列表是否为空，选择不同的查询策略
        if (ids == null || ids.isEmpty()) {
            // 如果ID列表为空，则查询全部数据
            List<SrsStaffOneStopCommunityConstruction> list = srsStaffOneStopCommunityConstructionService.selectSrsStaffOneStopCommunityConstructionList(srsStaffOneStopCommunityConstruction);
            // 使用ExcelUtil导出全部数据
            ExcelUtil<SrsStaffOneStopCommunityConstruction> util = new ExcelUtil<SrsStaffOneStopCommunityConstruction>(SrsStaffOneStopCommunityConstruction.class);
            util.exportExcel(response, list, "一站式社区模块：社区建设数据");
        } else {
            // 如果ID列表不为空，则根据ID列表查询数据
            List<SrsStaffOneStopCommunityConstruction> list = new ArrayList<>();
            for (Long id : ids) {
                // 根据每个ID查询对应的SrsStaffOneStopCommunityConstruction对象
                SrsStaffOneStopCommunityConstruction item = srsStaffOneStopCommunityConstructionService.selectSrsStaffOneStopCommunityConstructionByConstructId(id);
                // 如果查询到的对象不为null，则添加到列表中
                if (item != null) {
                    list.add(item);
                }
            }
            // 使用ExcelUtil导出选中的数据
            ExcelUtil<SrsStaffOneStopCommunityConstruction> util = new ExcelUtil<SrsStaffOneStopCommunityConstruction>(SrsStaffOneStopCommunityConstruction.class);
            util.exportExcel(response, list, "一站式社区模块：社区建设数据");
        }
    }

    /**
     * 获取一站式社区模块：社区建设详细信息
     */
    @PreAuthorize("@ss.hasPermi('staff:oneStopCommunityConstruction:query')")
    @GetMapping(value = "/{constructId}")
    @ApiOperation("获取一站式社区模块：社区建设详细信息")
    public AjaxResult getInfo(@PathVariable("constructId") Long constructId) {
        return success(srsStaffOneStopCommunityConstructionService.selectSrsStaffOneStopCommunityConstructionByConstructId(constructId));
    }

    /**
     * 新增一站式社区模块：社区建设
     */
    @PreAuthorize("@ss.hasPermi('staff:oneStopCommunityConstruction:add')")
    @Log(title = "一站式社区模块：社区建设", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增一站式社区模块：社区建设")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    public AjaxResult add(@RequestBody SrsStaffOneStopCommunityConstruction srsStaffOneStopCommunityConstruction) {
        return toAjax(srsStaffOneStopCommunityConstructionService.insertSrsStaffOneStopCommunityConstruction(srsStaffOneStopCommunityConstruction));
    }

    /**
     * 修改一站式社区模块：社区建设
     */
    @PreAuthorize("@ss.hasPermi('staff:oneStopCommunityConstruction:edit')")
    @Log(title = "一站式社区模块：社区建设", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改一站式社区模块：社区建设")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    public AjaxResult edit(@RequestBody SrsStaffOneStopCommunityConstruction srsStaffOneStopCommunityConstruction) {
        return toAjax(srsStaffOneStopCommunityConstructionService.updateSrsStaffOneStopCommunityConstruction(srsStaffOneStopCommunityConstruction));
    }

    /**
     * 删除一站式社区模块：社区建设
     */
    @PreAuthorize("@ss.hasPermi('staff:oneStopCommunityConstruction:remove')")
    @Log(title = "一站式社区模块：社区建设", businessType = BusinessType.DELETE)
    @PostMapping("/{constructIds}")
    @ApiOperation("删除一站式社区模块：社区建设")
    public AjaxResult remove(@PathVariable Long[] constructIds) {
        return toAjax(srsStaffOneStopCommunityConstructionService.deleteSrsStaffOneStopCommunityConstructionByConstructIds(constructIds));
    }
}
