package com.propertyManagement.web.controller.business;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.propertyManagement.common.annotation.RepeatSubmit;
import com.propertyManagement.common.annotation.Log;
import com.propertyManagement.common.core.controller.BaseController;
import com.propertyManagement.common.core.domain.PageQuery;
import com.propertyManagement.common.core.domain.R;
import com.propertyManagement.common.core.validate.AddGroup;
import com.propertyManagement.common.core.validate.EditGroup;
import com.propertyManagement.common.core.validate.QueryGroup;
import com.propertyManagement.common.enums.BusinessType;
import com.propertyManagement.common.utils.poi.ExcelUtil;
import com.propertyManagement.business.domain.vo.WxSlideshowVo;
import com.propertyManagement.business.domain.bo.WxSlideshowBo;
import com.propertyManagement.business.service.IWxSlideshowService;
import com.propertyManagement.common.core.page.TableDataInfo;

/**
 * 轮播图

 *
 * @author liushuai
 * @date 2025-06-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/slideshow")
public class WxSlideshowController extends BaseController {

    private final IWxSlideshowService iWxSlideshowService;

    /**
     * 查询轮播图
列表
     */
    @SaCheckPermission("business:slideshow:list")
    @GetMapping("/list")
    public TableDataInfo<WxSlideshowVo> list(WxSlideshowBo bo, PageQuery pageQuery) {
        return iWxSlideshowService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出轮播图
列表
     */
    @SaCheckPermission("business:slideshow:export")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WxSlideshowBo bo, HttpServletResponse response) {
        List<WxSlideshowVo> list = iWxSlideshowService.queryList(bo);
        ExcelUtil.exportExcel(list, "轮播图 ", WxSlideshowVo.class, response);
    }

    /**
     * 获取轮播图
详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:slideshow:query")
    @GetMapping("/{id}")
    public R<WxSlideshowVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iWxSlideshowService.queryById(id));
    }

    /**
     * 新增轮播图

     */
    @SaCheckPermission("business:slideshow:add")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WxSlideshowBo bo) {
        return toAjax(iWxSlideshowService.insertByBo(bo));
    }

    /**
     * 修改轮播图

     */
    @SaCheckPermission("business:slideshow:edit")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WxSlideshowBo bo) {
        return toAjax(iWxSlideshowService.updateByBo(bo));
    }

    /**
     * 删除轮播图

     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:slideshow:remove")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iWxSlideshowService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
