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

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

import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;
import cn.ezhizao.project.business.outsourceBalanceAccount.domain.BizOutsourceBalanceAccount;
import cn.ezhizao.project.business.outsourceBalanceAccount.service.IBizOutsourceBalanceAccountService;
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;


/**
 * 外协结算Controller
 *
 * @author ezhizao
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/business/account")
public class BizOutsourceBalanceAccountController extends BaseController
{
    @Resource
    private IBizOutsourceBalanceAccountService bizOutsourceBalanceAccountService;

    /**
     * 查询外协结算列表
     */
    @PreAuthorize("@ss.hasPermi('business:account:list')")
    @Log(title = "外协结算查询", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(BizOutsourceBalanceAccount bizOutsourceBalanceAccount) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizOutsourceBalanceAccount);
        startPage();
        List<BizOutsourceBalanceAccount> list = bizOutsourceBalanceAccountService.getList(bizOutsourceBalanceAccount);
        return getDataTable(list);
    }

    /**
     * 导出外协结算列表
     */
    @PreAuthorize("@ss.hasPermi('business:account:export')")
    @Log(title = "外协结算导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizOutsourceBalanceAccount bizOutsourceBalanceAccount) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizOutsourceBalanceAccount);
        List<BizOutsourceBalanceAccount> list = bizOutsourceBalanceAccountService.getList(bizOutsourceBalanceAccount);
        ExcelUtil<BizOutsourceBalanceAccount> util = new ExcelUtil<BizOutsourceBalanceAccount>(BizOutsourceBalanceAccount.class);
        util.exportExcel(response, list, "外协结算数据");
    }

    /**
     * 获取外协结算详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:account:query')")
    @Log(title = "外协结算查询详细信息", businessType = BusinessType.SELECT)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizOutsourceBalanceAccountService.getById(id));
    }

    /**
     * 新增外协结算
     */
    @PreAuthorize("@ss.hasPermi('business:account:add')")
    @Log(title = "外协结算新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizOutsourceBalanceAccount bizOutsourceBalanceAccount) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizOutsourceBalanceAccount);
        return toAjax(bizOutsourceBalanceAccountService.save(bizOutsourceBalanceAccount));
    }

    /**
     * 修改外协结算
     */
    @PreAuthorize("@ss.hasPermi('business:account:edit')")
    @Log(title = "外协结算编辑", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizOutsourceBalanceAccount bizOutsourceBalanceAccount) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizOutsourceBalanceAccount);
        return toAjax(bizOutsourceBalanceAccountService.updateById(bizOutsourceBalanceAccount));
    }

    /**
     * 删除外协结算
     */
    @PreAuthorize("@ss.hasPermi('business:account:remove')")
    @Log(title = "外协结算删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizOutsourceBalanceAccountService.removeBatchByIds(ids));
    }
}
