package com.ruoyi.ibs.list.controller;

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

import com.ruoyi.ibs.list.domain.*;
import com.ruoyi.ibs.list.service.ICustInfoRecordService;
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-12-19
 */
@RestController
@RequestMapping("/system/record")
@Api(tags = "营销建档")
public class CustInfoRecordController extends BaseController
{
    @Autowired
    private ICustInfoRecordService custInfoRecordService;

    /**
     * 查询建档客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @Log(title = "营销建档-查询建档客户信息列表")
    @GetMapping("/list")
    public TableDataInfo list(CustInfoRecord custInfoRecord)
    {
        startPage();
        List<CustInfoRecord> list = custInfoRecordService.selectCustInfoRecordList(custInfoRecord);
        return getDataTable(list);
    }

    /**
     * 查询建档客户信息列表
     */
    //@PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/listByCustType")
    @Log(title = "营销建档-根据客户类型与关键词查询客户列表")
    @ApiOperation("根据客户类型与关键词查询客户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "custType", value = "客户类型，0个人，1商户，2企业", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "keyword", value = "关键词，可以是客户名，证件号，手机号", dataType = "String", dataTypeClass = String.class)
    })
    public TableDataInfo list(String custType,String keyword)
    {
        startPage();
        List<CustInfoRecord> list = custInfoRecordService.selectCustInfoRecordListByCustTypeAndKeywords(custType,keyword);
        return getDataTable(list);
    }

    /**
     * 导出建档客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "营销建档-建档客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustInfoRecord custInfoRecord)
    {
        List<CustInfoRecord> list = custInfoRecordService.selectCustInfoRecordList(custInfoRecord);
        ExcelUtil<CustInfoRecord> util = new ExcelUtil<CustInfoRecord>(CustInfoRecord.class);
        util.exportExcel(response, list, "建档客户信息数据");
    }

    /**
     * 获取建档客户信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    @Log(title = "营销建档-新增走访任务统计点评")
    @ApiOperation("查询客户营销建档详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(custInfoRecordService.selectCustInfoRecordDetailById(id));
    }

    /**
     * 新增建档客户信息
     */
    //@PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "营销建档-建档客户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("客户营销建档")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "custType", value = "客户类型，0个人，1商户，2企业", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "relateMerchant", value = "关联商户名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "relateBusiness", value = "关联企业名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "relateMerchantCode", value = "关联商户统信码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "relateBusinessCode", value = "关联企业统信码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "relateMerchantCode", value = "关联商户统信码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "relateBusinessCode", value = "关联企业统信码", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "relatePerson", value = "关联人", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "relateCustIdc", value = "关联人身份证号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "fmyName", value = "家庭成员名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "belongBusi", value = "家庭成员行业", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "tel", value = "家庭成员手机号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "fmyRln", value = "成员与本人关系", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "fmyCustIdc", value = "家庭成员身份证号", dataType = "String", dataTypeClass = String.class),

    })
    public AjaxResult add(@RequestBody RecordAddDTO recordAddDTO)
    {
        return toAjax(custInfoRecordService.insertCustInfoRecordDetail(recordAddDTO.getCustInfoRecord(),recordAddDTO.getFamilyMembersRecords(),recordAddDTO.getRecordRelates()));
    }

    /**
     * 修改建档客户信息
     */
    //@PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "营销建档-建档客户信息", businessType = BusinessType.UPDATE)
    @ApiOperation("客户营销建档信息编辑")
    @PutMapping("/edit")
    public AjaxResult edit(CustInfoRecord custInfoRecord)
    {
        return toAjax(custInfoRecordService.updateCustInfoRecord(custInfoRecord));
    }

    /**
     * 删除建档客户信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "营销建档-建档客户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(custInfoRecordService.deleteCustInfoRecordByIds(ids));
    }


    @PostMapping("/editLable")
    @Log(title = "营销建档-修改客户标签")
    @ApiOperation("修改客户标签")
    public AjaxResult editLable(@RequestBody CustLableDTO custLableDTO)
    {
        return toAjax(custInfoRecordService.updateLable(custLableDTO));
    }
}
