package com.ruoyi.ibs.list.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ibs.list.domain.CorporateShareholder;
import com.ruoyi.ibs.list.service.ICorporateShareholderService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业，商户法人，关联经营人Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/system/shareholder")
public class CorporateShareholderController extends BaseController
{
    @Autowired
    private ICorporateShareholderService corporateShareholderService;

    /**
     * 查询企业，商户法人，关联经营人列表
     */
    @PreAuthorize("@ss.hasPermi('system:shareholder:list')")
    @GetMapping("/list")
    public TableDataInfo list(CorporateShareholder corporateShareholder)
    {
        startPage();
        List<CorporateShareholder> list = corporateShareholderService.selectCorporateShareholderList(corporateShareholder);
        return getDataTable(list);
    }

    /**
     * 导出企业，商户法人，关联经营人列表
     */
    @PreAuthorize("@ss.hasPermi('system:shareholder:export')")
    @Log(title = "企业，商户法人，关联经营人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CorporateShareholder corporateShareholder)
    {
        List<CorporateShareholder> list = corporateShareholderService.selectCorporateShareholderList(corporateShareholder);
        ExcelUtil<CorporateShareholder> util = new ExcelUtil<CorporateShareholder>(CorporateShareholder.class);
        util.exportExcel(response, list, "企业，商户法人，关联经营人数据");
    }

    /**
     * 获取企业，商户法人，关联经营人详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:shareholder:query')")
    @GetMapping(value = "/{socialCreditCode}")
    public AjaxResult getInfo(@PathVariable("socialCreditCode") String socialCreditCode)
    {
        return success(corporateShareholderService.selectCorporateShareholderBySocialCreditCode(socialCreditCode));
    }

    /**
     * 新增企业，商户法人，关联经营人
     */
    @PreAuthorize("@ss.hasPermi('system:shareholder:add')")
    @Log(title = "企业，商户法人，关联经营人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CorporateShareholder corporateShareholder)
    {
        return toAjax(corporateShareholderService.insertCorporateShareholder(corporateShareholder));
    }

    /**
     * 修改企业，商户法人，关联经营人
     */
    @PreAuthorize("@ss.hasPermi('system:shareholder:edit')")
    @Log(title = "企业，商户法人，关联经营人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CorporateShareholder corporateShareholder)
    {
        return toAjax(corporateShareholderService.updateCorporateShareholder(corporateShareholder));
    }

    /**
     * 删除企业，商户法人，关联经营人
     */
    @PreAuthorize("@ss.hasPermi('system:shareholder:remove')")
    @Log(title = "企业，商户法人，关联经营人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{socialCreditCodes}")
    public AjaxResult remove(@PathVariable String[] socialCreditCodes)
    {
        return toAjax(corporateShareholderService.deleteCorporateShareholderBySocialCreditCodes(socialCreditCodes));
    }
}
