package com.njzscloud.supervisory.sys.resource.cotroller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.njzscloud.common.core.utils.R;
import com.njzscloud.supervisory.sys.resource.pojo.entity.ResourceEntity;
import com.njzscloud.supervisory.sys.resource.service.ResourceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 系统资源表
 */
@Slf4j
@RestController
@RequestMapping("/resource")
@RequiredArgsConstructor
public class ResourceController {
    private final ResourceService resourceService;

    @GetMapping("/list")
    public R<List<ResourceEntity>> list(
            @RequestParam(value = "tableName", required = false) String tableName,
            @RequestParam(value = "keywords", required = false) String keywords
    ) {
        return R.success(resourceService.list(Wrappers.<ResourceEntity>lambdaQuery()
                .eq(StrUtil.isNotBlank(tableName), ResourceEntity::getTableName, tableName)
                .and(StrUtil.isNotBlank(keywords), ew -> ew.like(ResourceEntity::getSn, keywords)
                        .or().like(ResourceEntity::getMemo, keywords))
        ));
    }

}
