package com.ruoyi.ibs.list.controller;

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

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.CustInfoBusiness;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.ibs.list.domain.CorporateShareholder;
import com.ruoyi.ibs.list.domain.CustInfoBusinessVo;
import com.ruoyi.ibs.list.service.ICorporateShareholderService;
import com.ruoyi.ibs.list.service.ICustInfoBusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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-28
 */
@RestController
@RequestMapping("/system/business")
@Api("企业客户信息")
public class CustInfoBusinessController extends BaseController
{
    @Autowired
    private ICustInfoBusinessService custInfoBusinessService;
    @Autowired
    private ICorporateShareholderService corporateShareholderService;

    /**
     * 查询企业客户基本信息列表
     */
   // @PreAuthorize("@ss.hasPermi('system:business:list')")
    @GetMapping("/list")
    @Log(title = "客户视图-根据关键词查询企业客户列表")
    @ApiOperation("根据关键词查询企业客户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "关键词，可以是企业名，法人名称，证件号，手机号", dataType = "String", dataTypeClass = String.class)
    })
    public TableDataInfo list(String keyword)
    {
        startPage();
        List<CustInfoBusiness> list = custInfoBusinessService.selectCustInfoBusinessListByKeyword(keyword);
        return getDataTable(list);
    }

//    /**
//     * 导出企业客户基本信息列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:business:export')")
//    @Log(title = "客户视图-企业客户基本信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, CustInfoBusiness custInfoBusiness)
//    {
//        List<CustInfoBusiness> list = custInfoBusinessService.selectCustInfoBusinessList(custInfoBusiness);
//        ExcelUtil<CustInfoBusiness> util = new ExcelUtil<CustInfoBusiness>(CustInfoBusiness.class);
//        util.exportExcel(response, list, "企业客户基本信息数据");
//    }

    /**
     * 获取企业客户基本信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:business:query')")
    @GetMapping(value = "/getInfoByCustId")
    @Log(title = "客户视图-根据客户号查询企业360客户详情")
    @ApiOperation("根据客户号查询企业360客户详情")
    public AjaxResult getInfo(String custId)
    {

        return success(custInfoBusinessService.selectCustInfoBusinessVoByCustId(custId));
    }

    @GetMapping(value = "/getBusinessInfoByCustId")
    @Log(title = "客户视图-查询企业客户详情")
    @ApiOperation("查询企业客户详情")
    public AjaxResult getBusinessInfo(String custId)
    {

        return success(custInfoBusinessService.selectCustInfoBusinessByCustId(custId));
    }

    /**
     * 新增企业客户基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:business:add')")
    @Log(title = "客户视图-企业客户基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustInfoBusiness custInfoBusiness)
    {
        return toAjax(custInfoBusinessService.insertCustInfoBusiness(custInfoBusiness));
    }

    /**
     * 企业营销建档
     */
    //@PreAuthorize("@ss.hasPermi('system:business:add')")
    @Log(title = "客户视图-企业客户营销建档", businessType = BusinessType.INSERT)
    @ApiOperation("企业客户营销建档")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "relatePerson", value = "关联人", dataType = "String", dataTypeClass = String.class),
    })
    @PostMapping("/addRecord")
    public AjaxResult addRecord( CustInfoBusiness custInfoBusiness,String relatePerson)
    {
        return custInfoBusinessService.insertCustInfoBusinessVo(custInfoBusiness,relatePerson);
    }


    /**
     * 修改企业客户基本信息
     */
    //@PreAuthorize("@ss.hasPermi('system:business:edit')")
    @Log(title = "客户视图-编辑企业客户详情", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("编辑企业客户详情")
    public AjaxResult edit( CustInfoBusiness custInfoBusiness)
    {
        return custInfoBusinessService.updateCustInfoBusiness(custInfoBusiness);
    }

    /**
     * 删除企业客户基本信息
     */
    @PreAuthorize("@ss.hasPermi('system:business:remove')")
    @Log(title = "客户视图-企业客户基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(custInfoBusinessService.deleteCustInfoBusinessByIds(ids));
    }

    @GetMapping(value = "/exportBusinessDetail")
    @Log(title = "客户视图-导出企业客户详情")
    @ApiOperation("导出企业客户详情")
    public void exportInfo(HttpServletResponse response,String custId) throws Exception {
        custInfoBusinessService.exportBusinessDetail(response,custId);
    }

    @ApiOperation("获取对公经营状态码值")
    @Log(title = "客户视图-获取对公经营状态码值;", businessType = BusinessType.UPDATE)
    @GetMapping("/getRegStatus")
    public R<List<SysDictData>> getRegStatus() {
        List<SysDictData> paramList = custInfoBusinessService.getRegStatus();
        return R.ok(paramList);
    }
}
