package com.project.zcustom.controller.backManager.engineering;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;
import com.project.zcustom.domain.addional.LargeProject;
import com.project.zcustom.service.unit.ILargeProjectService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 工程项目Controller
 *
 * @author change
 * @date 2024-12-30
 */
@RestController
@RequestMapping("/zcustom/project")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class LargeProjectController extends BaseController {

    private final ILargeProjectService largeProjectService;

    @GetMapping("/list")
    public AjaxResult list(LargeProject entity) {
        return AjaxResult.success("查询成功", largeProjectService.pagingLargeProjectList(entity));
    }

    @GetMapping("/listAll")
    public AjaxResult listAll(LargeProject entity) {
        return AjaxResult.success("查询成功", largeProjectService.selectLargeProjectList(entity));
    }

    @Log(title = "工程项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LargeProject entity) {
        List<LargeProject> list = largeProjectService.selectLargeProjectList(entity);
        ExcelUtil<LargeProject> util = new ExcelUtil<>(LargeProject.class);
        util.exportExcel(response, list, "工程项目数据");
    }

    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", largeProjectService.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:project:add')")
    @Log(title = "工程项目", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody LargeProject entity) {
        return toAjax(largeProjectService.save(entity));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:project:edit')")
    @Log(title = "工程项目", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody LargeProject entity) {
        return toAjax(largeProjectService.updateById(entity));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:project:remove')")
    @Log(title = "工程项目", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(largeProjectService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }

    @PostMapping("/upload")
    public AjaxResult upload(@RequestParam("file") MultipartFile file) {
        return toAjax(largeProjectService.upload(file));
    }
}
