package com.propertyManagement.web.controller.business;

import java.util.List;
import java.util.Arrays;

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.enums.BusinessType;
import com.propertyManagement.common.utils.poi.ExcelUtil;
import com.propertyManagement.business.domain.vo.ConvenienceServiceVo;
import com.propertyManagement.business.domain.bo.ConvenienceServiceBo;
import com.propertyManagement.business.service.IConvenienceServiceService;
import com.propertyManagement.common.core.page.TableDataInfo;

/**
 * 便民服务
 *
 * @author Ashe
 * @date 2025-08-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/converienceService")
public class ConvenienceServiceController extends BaseController {

    private final IConvenienceServiceService iConvenienceServiceService;

    /**
     * 查询便民服务列表
     */
    @SaCheckPermission("business:converienceService:list")
    @GetMapping("/list")
    public TableDataInfo<ConvenienceServiceVo> list(ConvenienceServiceBo bo, PageQuery pageQuery) {
        return iConvenienceServiceService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出便民服务列表
     */
    @SaCheckPermission("business:converienceService:export")
    @Log(title = "便民服务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ConvenienceServiceBo bo, HttpServletResponse response) {
        List<ConvenienceServiceVo> list = iConvenienceServiceService.queryList(bo);
        ExcelUtil.exportExcel(list, "便民服务", ConvenienceServiceVo.class, response);
    }

    /**
     * 获取便民服务详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:converienceService:query")
    @GetMapping("/{id}")
    public R<ConvenienceServiceVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iConvenienceServiceService.queryById(id));
    }

    /**
     * 新增便民服务
     */
    @SaCheckPermission("business:converienceService:add")
    @Log(title = "便民服务", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ConvenienceServiceBo bo) {
        return toAjax(iConvenienceServiceService.insertByBo(bo));
    }

    /**
     * 修改便民服务
     */
    @SaCheckPermission("business:converienceService:edit")
    @Log(title = "便民服务", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ConvenienceServiceBo bo) {
        return toAjax(iConvenienceServiceService.updateByBo(bo));
    }

    /**
     * 删除便民服务
     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:converienceService:remove")
    @Log(title = "便民服务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iConvenienceServiceService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
