package cn.iocoder.yudao.module.company.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.company.entity.CompanyQuals;
import cn.iocoder.yudao.module.company.service.CompanyQualsService;
import cn.iocoder.yudao.module.company.vo.CompanyQualsRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.ok;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 企业资质信息表（每个租户的下属企业信息）;(dl_company_quals)表控制层
 *
 * @author : http://www.chiner.pro
 * @date : 2024-7-31
 */
@RestController
@RequestMapping("/base/company-quals")
@Tag(name = "管理后台 - BASE 企业资质管理")
@Validated
public class CompanyQualsController {
    @Autowired
    private CompanyQualsService companyQualsService;

    /**
     * 列表查询--不分页
     * @author vinjor-M
     * @date 9:52 2024/8/2
     * @param corpId 企业id
     **/
    @GetMapping("/list")
    @Operation(summary = "获得企业资质信息表不分页")
    @PreAuthorize("@ss.hasPermission('base:company-quals:query')")
    public CommonResult<List<?>> getCompanyPage(String corpId) {
        return success(companyQualsService.list(new LambdaQueryWrapperX<CompanyQuals>().
                eq(CompanyQuals::getCorpId,corpId).orderByDesc(CompanyQuals::getCreateTime)));
    }

    @PostMapping("/create")
    @Operation(summary = "创建企业资质")
    @PreAuthorize("@ss.hasPermission('base:company-quals:create')")
    public CommonResult<String> createCompanyQuals(@RequestBody CompanyQualsRespVO createReqVO) {
        companyQualsService.saveDataObj(createReqVO);
        return ok();
    }

    @PutMapping("/update")
    @Operation(summary = "更新企业资质")
    @PreAuthorize("@ss.hasPermission('base:company-quals:update')")
    public CommonResult<Boolean> updateCompanyQuals(@RequestBody CompanyQualsRespVO updateReqVO) {
        companyQualsService.updateDataObj(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除企业资质")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('base:company-quals:delete')")
    public CommonResult<Boolean> deleteCompanyQuals(@RequestParam("id") String id) {
        companyQualsService.removeDataObj(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得企业资质")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('base:company-quals:query')")
    public CommonResult<CompanyQuals> getCompanyQuals(@RequestParam("id") String id) {
        return success(companyQualsService.getById(id));
    }
}