package com.sqx.modules.resumes.controller;

import com.sqx.common.utils.DateUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.resumes.entity.Invoice;
import com.sqx.modules.resumes.service.InvoiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@Api(value = "发票管理", tags = {"发票管理"})
@RequestMapping(value = "/invoice")
public class InvoiceController {

    @Autowired
    private InvoiceService invoiceService;

    @PostMapping("/insertInvoice")
    @ApiOperation("添加发票记录")
    public Result insertInvoice(@RequestBody Invoice invoice){
        invoice.setCreateTime(DateUtils.format(new Date()));
        invoiceService.save(invoice);
        return Result.success();
    }

    @PostMapping("/updateInvoice")
    @ApiOperation("修改发票记录")
    public Result  updateInvoice(@RequestBody Invoice invoice){
        invoiceService.updateById(invoice);
        return Result.success();
    }

    @PostMapping("/deleteInvoice")
    @ApiOperation("删除发票记录")
        public Result deleteInvoice(Long invoiceId){
        invoiceService.removeById(invoiceId);
        return Result.success();
    }

    @GetMapping("/selectInvoiceList")
    @ApiOperation("查询发票记录")
    public Result selectInvoiceList(Integer page,Integer limit,Long userId,String userName,String companyName,String title,String content,String phone,Integer status){
        return invoiceService.selectInvoiceList(page, limit, userId, userName, companyName, title, content, phone,status);
    }

    @PostMapping("/updateInvoiceStatus")
    @ApiOperation("修改发票记录状态")
    public Result updateInvoiceStatus(String ids,String status){
        for(String id:ids.split(",")){
            Invoice invoice=new Invoice();
            invoice.setInvoiceId(Long.parseLong(id));
            invoice.setStatus(status);
            invoiceService.updateById(invoice);
        }
        return Result.success();
    }









}
