package com.ruoyi.project.business.controller;

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

import com.ruoyi.project.business.domain.TcAccountRelation;
import com.ruoyi.project.business.service.ITcAccountRelationService;
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.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 组织(客户)合并关系Controller
 * 
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/business/relation")
public class TcAccountRelationController extends BaseController
{
    @Autowired
    private ITcAccountRelationService tcAccountRelationService;

    /**
     * 查询组织(客户)合并关系列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TcAccountRelation tcAccountRelation)
    {
        startPage();
        List<TcAccountRelation> list = tcAccountRelationService.selectTcAccountRelationList(tcAccountRelation);
        return getDataTable(list);
    }

    /**
     * 导出组织(客户)合并关系列表
     */
    @Log(title = "组织(客户)合并关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcAccountRelation tcAccountRelation)
    {
        List<TcAccountRelation> list = tcAccountRelationService.selectTcAccountRelationList(tcAccountRelation);
        ExcelUtil<TcAccountRelation> util = new ExcelUtil<TcAccountRelation>(TcAccountRelation.class);
        util.exportExcel(response, list, "组织(客户)合并关系数据");
    }

    /**
     * 获取组织(客户)合并关系详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tcAccountRelationService.selectTcAccountRelationById(id));
    }

    /**
     * 新增组织(客户)合并关系
     */
    @Log(title = "组织(客户)合并关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TcAccountRelation tcAccountRelation)
    {
        return toAjax(tcAccountRelationService.insertTcAccountRelation(tcAccountRelation));
    }

    /**
     * 修改组织(客户)合并关系
     */
    @Log(title = "组织(客户)合并关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TcAccountRelation tcAccountRelation)
    {
        return toAjax(tcAccountRelationService.updateTcAccountRelation(tcAccountRelation));
    }

    /**
     * 删除组织(客户)合并关系
     */
    @Log(title = "组织(客户)合并关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tcAccountRelationService.deleteTcAccountRelationByIds(ids));
    }
}
