package com.boman.web.core.controller;

import com.boman.common.core.web.domain.AjaxResult;
import com.boman.web.core.domain.FormDataDto;
import com.boman.web.core.service.common.ICommonService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author shiqian
 * @date 2021年04月15日 16:25
 **/
@RestController
@RequestMapping("common/")
public class CommonController {

    @Resource
    private ICommonService commonService;

    /**
     * 功能描述: 根据表名和id查找
     *
     * @param tableName tableName
     * @param id        id
     * @return com.boman.common.core.web.domain.AjaxResult
     */
    @GetMapping("/tableName/{tableName}/id/{id}")
    public AjaxResult getById(@PathVariable("tableName") String tableName, @PathVariable("id") Long id) {
        return AjaxResult.success(commonService.getById(tableName, id));
    }

    /**
     * 功能描述: 根据表名和自定义字段查找
     *
     * @param tableName tableName
     * @param id        id
     * @return com.boman.common.core.web.domain.AjaxResult
     */
    @PostMapping
    public AjaxResult getByMap(@RequestBody FormDataDto dto) {
        return AjaxResult.success(commonService.getByMap(dto.getTable(), dto.getFixedData()));
    }

}
