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.LargePlan;
import com.project.zcustom.service.unit.ILargePlanService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 工程计划Controller
 *
 * @author change
 * @date 2024-12-30
 */
@RestController
@RequestMapping("/zcustom/plan")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class LargePlanController extends BaseController {

    private final ILargePlanService largePlanService;

    @GetMapping("/list")
    public AjaxResult list(LargePlan entity) {
        return AjaxResult.success("查询成功", largePlanService.pagingLargePlanList(entity));
    }

    @GetMapping("/listAll")
    public AjaxResult listAll(LargePlan entity) {
        return AjaxResult.success("查询成功", largePlanService.selectLargePlanList(entity));
    }

    @Log(title = "工程计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LargePlan entity) {
        List<LargePlan> list = largePlanService.selectLargePlanList(entity);
        ExcelUtil<LargePlan> util = new ExcelUtil<>(LargePlan.class);
        util.exportExcel(response, list, "工程计划数据");
    }

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

    @PreAuthorize("@ss.hasPermi('zcustom:plan:add')")
    @Log(title = "工程计划", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody LargePlan entity) {
        return toAjax(largePlanService.save(entity));
    }

    @PreAuthorize("@ss.hasPermi('zcustom:plan:edit')")
    @Log(title = "工程计划", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody LargePlan entity) {
        return toAjax(largePlanService.updateById(entity));
    }

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

    /**
     * 本周检查项目数
     */
    @GetMapping(value = "/getCheckProjectNum")
    public AjaxResult getCheckProjectNum(@RequestParam Date startDate, @RequestParam Date endDate){
        return AjaxResult.success("查询成功", largePlanService.getCheckProjectNum(startDate, endDate));
    }
}
