package com.xhpc.user.controller;

import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.util.LogUserUtils;
import com.xhpc.system.api.model.LoginUser;
import com.xhpc.user.domain.XhpcDonationInvoice;
import com.xhpc.user.service.IXhpcDonationInvoiceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yuyang
 * @date 2022/6/22 14:03
 */
@RestController
@RequestMapping("/donationInvoice")
public class XhpcDonationInvoiceController extends BaseController {

    @Resource
    IXhpcDonationInvoiceService xhpcDonationInvoiceService;
    @Resource
    LogUserUtils logUserUtils;

    @PostMapping("/addOrUpdate")
    public AjaxResult insertDonationInvoice(@RequestBody XhpcDonationInvoice xhpcDonationInvoice) {
        return xhpcDonationInvoiceService.insertDonationInvoice(xhpcDonationInvoice);
    }

    @GetMapping("/getDonationInvoiceById")
    public AjaxResult getDonationInvoiceById(Long  donationInvoiceId) {
        return xhpcDonationInvoiceService.getDonationInvoiceById(donationInvoiceId);
    }

    @GetMapping("/list")
    public TableDataInfo list(HttpServletRequest request, String name, String titleContent, String dutyNumber) {
        LoginUser loginUser = logUserUtils.getLogUser(request);
        startPage();
        Map<String, Object> params = new HashMap<>();
        params.put("tenantId", loginUser.getTenantId());
        params.put("titleContent", titleContent);
        params.put("dutyNumber", dutyNumber);
        params.put("name", name);
        return getDataTable(xhpcDonationInvoiceService.getPage(params));
    }

    @GetMapping("/deleteById")
    public AjaxResult deleteById(String  donationInvoiceId) {
        return xhpcDonationInvoiceService.deleteById(donationInvoiceId);
    }

}
