package cn.ezhizao.project.business.companyFollow.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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 cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.project.business.companyFollow.domain.BizCompanyFollowDetail;
import cn.ezhizao.project.business.companyFollow.service.IBizCompanyFollowDetailService;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.web.page.TableDataInfo;

/**
 * 客户跟进记录Controller
 *
 * @author ruoyi
 * @date 2023-10-17
 */
@RestController
@RequestMapping("/business/follow")
public class BizCompanyFollowDetailController extends BaseController
{
    @Resource
    private IBizCompanyFollowDetailService bizCompanyFollowDetailService;

    /**
     * 查询客户跟进记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:company:info')")
    @GetMapping("/list")
    public TableDataInfo list(BizCompanyFollowDetail bizCompanyFollowDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompanyFollowDetail);
        startPage();
        List<BizCompanyFollowDetail> list = bizCompanyFollowDetailService.getList(bizCompanyFollowDetail);
        return getDataTable(list);
    }

    /**
     * 导出客户跟进记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:follow:export')")
    @Log(title = "客户跟进记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCompanyFollowDetail bizCompanyFollowDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompanyFollowDetail);
        List<BizCompanyFollowDetail> list = bizCompanyFollowDetailService.getList(bizCompanyFollowDetail);
        ExcelUtil<BizCompanyFollowDetail> util = new ExcelUtil<BizCompanyFollowDetail>(BizCompanyFollowDetail.class);
        util.exportExcel(response, list, "客户跟进记录数据");
    }

    /**
     * 获取客户跟进记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:company:info')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCompanyFollowDetailService.getById(id));
    }

    /**
     * 新增客户跟进记录
     */
    @PreAuthorize("@ss.hasPermi('business:company:follow')")
    @Log(title = "客户跟进记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCompanyFollowDetail bizCompanyFollowDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompanyFollowDetail);
        return toAjax(bizCompanyFollowDetailService.save(bizCompanyFollowDetail));
    }

    /**
     * 修改客户跟进记录
     */
    @PreAuthorize("@ss.hasPermi('business:company:follow')")
    @Log(title = "客户跟进记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCompanyFollowDetail bizCompanyFollowDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCompanyFollowDetail);
        return toAjax(bizCompanyFollowDetailService.updateById(bizCompanyFollowDetail));
    }

    /**
     * 删除客户跟进记录
     */
    @PreAuthorize("@ss.hasPermi('business:company:follow:remove')")
    @Log(title = "客户跟进记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizCompanyFollowDetailService.removeBatchByIds(ids));
    }
}
