package com.gxwebsoft.shop.controller;

import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.shop.service.ShopStoreFenceService;
import com.gxwebsoft.shop.entity.ShopStoreFence;
import com.gxwebsoft.shop.param.ShopStoreFenceParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 黄家明_电子围栏控制器
 *
 * @author 科技小王子
 * @since 2026-02-07 18:10:25
 */
@Tag(name = "黄家明_电子围栏管理")
@RestController
@RequestMapping("/api/shop/shop-store-fence")
public class ShopStoreFenceController extends BaseController {
    @Resource
    private ShopStoreFenceService shopStoreFenceService;

    @PreAuthorize("hasAuthority('shop:shopStoreFence:list')")
    @Operation(summary = "分页查询黄家明_电子围栏")
    @GetMapping("/page")
    public ApiResult<PageResult<ShopStoreFence>> page(ShopStoreFenceParam param) {
        // 使用关联查询
        return success(shopStoreFenceService.pageRel(param));
    }

    @PreAuthorize("hasAuthority('shop:shopStoreFence:list')")
    @Operation(summary = "查询全部黄家明_电子围栏")
    @GetMapping()
    public ApiResult<List<ShopStoreFence>> list(ShopStoreFenceParam param) {
        // 使用关联查询
        return success(shopStoreFenceService.listRel(param));
    }

    @PreAuthorize("hasAuthority('shop:shopStoreFence:list')")
    @Operation(summary = "根据id查询黄家明_电子围栏")
    @GetMapping("/{id}")
    public ApiResult<ShopStoreFence> get(@PathVariable("id") Integer id) {
        // 使用关联查询
        return success(shopStoreFenceService.getByIdRel(id));
    }

    @PreAuthorize("hasAuthority('shop:shopStoreFence:save')")
    @OperationLog
    @Operation(summary = "添加黄家明_电子围栏")
    @PostMapping()
    public ApiResult<?> save(@RequestBody ShopStoreFence shopStoreFence) {
        if (shopStoreFenceService.save(shopStoreFence)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }

    @PreAuthorize("hasAuthority('shop:shopStoreFence:update')")
    @OperationLog
    @Operation(summary = "修改黄家明_电子围栏")
    @PutMapping()
    public ApiResult<?> update(@RequestBody ShopStoreFence shopStoreFence) {
        if (shopStoreFenceService.updateById(shopStoreFence)) {
            return success("修改成功");
        }
        return fail("修改失败");
    }

    @PreAuthorize("hasAuthority('shop:shopStoreFence:remove')")
    @OperationLog
    @Operation(summary = "删除黄家明_电子围栏")
    @DeleteMapping("/{id}")
    public ApiResult<?> remove(@PathVariable("id") Integer id) {
        if (shopStoreFenceService.removeById(id)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

    @PreAuthorize("hasAuthority('shop:shopStoreFence:save')")
    @OperationLog
    @Operation(summary = "批量添加黄家明_电子围栏")
    @PostMapping("/batch")
    public ApiResult<?> saveBatch(@RequestBody List<ShopStoreFence> list) {
        if (shopStoreFenceService.saveBatch(list)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }

    @PreAuthorize("hasAuthority('shop:shopStoreFence:update')")
    @OperationLog
    @Operation(summary = "批量修改黄家明_电子围栏")
    @PutMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody BatchParam<ShopStoreFence> batchParam) {
        if (batchParam.update(shopStoreFenceService, "id")) {
            return success("修改成功");
        }
        return fail("修改失败");
    }

    @PreAuthorize("hasAuthority('shop:shopStoreFence:remove')")
    @OperationLog
    @Operation(summary = "批量删除黄家明_电子围栏")
    @DeleteMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
        if (shopStoreFenceService.removeByIds(ids)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

}
