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

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

import cn.ezhizao.project.business.invoice.domain.BizCopyInfo;
import cn.ezhizao.project.business.invoice.service.IBizCopyInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.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 2024-08-26
 */
@RestController
@RequestMapping("/business/info")
public class BizCopyInfoController extends BaseController
{
    @Resource
    private IBizCopyInfoService bizCopyInfoService;

    /**
     * 查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BizCopyInfo bizCopyInfo) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCopyInfo);
        startPage();
        List<BizCopyInfo> list = bizCopyInfoService.getList(bizCopyInfo);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCopyInfo bizCopyInfo) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCopyInfo);
        List<BizCopyInfo> list = bizCopyInfoService.getList(bizCopyInfo);
        ExcelUtil<BizCopyInfo> util = new ExcelUtil<BizCopyInfo>(BizCopyInfo.class);
        util.exportExcel(response, list, "企业租户数据");
    }


    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCopyInfoService.getById(id));
    }
    @GetMapping(value = "/tenantId")
    public AjaxResult getInfoByTenantId(){
        Long tenantId = getTenantId();
        BizCopyInfo one = bizCopyInfoService.getOne(new LambdaQueryWrapper<BizCopyInfo>().eq(BizCopyInfo::getTenantId, tenantId));
        return success(one);
    }
    @PostMapping
    public AjaxResult add(@RequestBody BizCopyInfo bizCopyInfo) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCopyInfo);
        return toAjax(bizCopyInfoService.save(bizCopyInfo));
    }


    @PutMapping
    public AjaxResult edit(@RequestBody BizCopyInfo bizCopyInfo) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizCopyInfo);
        return toAjax(bizCopyInfoService.updateById(bizCopyInfo));
    }


	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizCopyInfoService.removeBatchByIds(ids));
    }
}
