package com.zksy.controller.property;

import cn.hutool.core.date.DateTime;
import com.zksy.property.domain.AInnovation;
import com.zksy.property.domain.APropertyReceipt;
import com.zksy.property.service.AInnovationService;
import com.zksy.property.service.APropertyReceiptService;
import com.zksy.utils.AjaxResult;
import com.zksy.utils.ExcelExportUtil;
import com.zksy.utils.ExcelImportUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;

/**
 * @author Administrator
 * @version 1.0
 * @project enterprise-assets-service
 * @description 创新创业收入情况控制层
 * @date 2025/6/24 14:33:13
 */
@RestController
@RequestMapping("/ainnovation")
@Api(tags = "创新创业收入情况信息",description = "创新创业收入情况信息desc")
public class AInnovationController {
    @Autowired
    private AInnovationService service;
    @GetMapping("/findByPage")
    @ApiOperation(value = "创新创业收入情况信息查询分页")
    public AjaxResult findByPage(long pageNum, long pageSize, String receiptNumber,String building,String roomNumber){
        return AjaxResult.success(service.findByPage(pageNum, pageSize, receiptNumber,building,roomNumber));
    }
    @GetMapping("/getAInnovationList")
    @ApiOperation(value = "创新创业收入情况信息查询")
    public AjaxResult getAInnovationList(String receiptNumber,String building,String roomNumber){
        return AjaxResult.success(service.getAInnovationList(receiptNumber,building,roomNumber));
    }
    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据Id查询创新创业收入情况信息")
    public AjaxResult getById(@PathVariable String id){
        return AjaxResult.success(service.getById(id));
    }
    @PostMapping("/save")
    @ApiOperation(value = "创新创业收入情况信息保存")
    public AjaxResult save(@RequestBody AInnovation ainnovation) {
        return service.save(ainnovation) ? AjaxResult.success(ainnovation) : AjaxResult.error("保存失败");
    }
    @PostMapping("/update")
    @ApiOperation(value = "创新创业收入情况信息修改")
    public AjaxResult update(@RequestBody AInnovation ainnovation) {
        ainnovation.setUpdateTime(LocalDateTime.now());
        return service.updateById(ainnovation) ? AjaxResult.success(ainnovation) : AjaxResult.error("修改失败");
    }
    @PostMapping("/deleteBatch")
    @ApiOperation(value = "创新创业收入情况信息删除")
    public AjaxResult delete(@RequestBody String[] ids) {
        return service.removeBatchByIds(Arrays.asList(ids)) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }
    @PostMapping("/importData")
    @ApiOperation(value = "导入数据")
    public AjaxResult importData(MultipartFile file) {
        return AjaxResult.success(service.saveOrUpdateBatch(ExcelImportUtil.importExcel(file, AInnovation.class)));
    }
    @GetMapping("/exportData")
    @ApiOperation(value = "导出数据")
    public void exportData(HttpServletResponse response,String receiptNumber,String building,String roomNumber) {
        ExcelExportUtil.exportExcel(response,service.getAInnovationList(receiptNumber,building,roomNumber), AInnovation.class, "创新创业收入情况信息","创新创业收入情况信息");
    }

}
