package com.ruoyi.oa.controller;

import java.util.Date;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.oa.domain.vo.SysOaCostAllVo;
import com.ruoyi.oa.domain.vo.SysOaCostRow;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.vo.SysOaCostVo;
import com.ruoyi.oa.domain.bo.SysOaCostBo;
import com.ruoyi.oa.service.ISysOaCostService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目成本分析
 *
 * @author ruoyi
 * @date 2025-03-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/cost")
public class SysOaCostController extends BaseController {

    private final ISysOaCostService iSysOaCostService;

    /**
     * 查询项目成本分析列表
     */
    @GetMapping("/list1")
    public TableDataInfo<SysOaCostVo> list1(SysOaCostBo bo, PageQuery pageQuery) {
        return iSysOaCostService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出项目成本分析列表
     */
    @Log(title = "项目成本分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysOaCostBo bo, HttpServletResponse response) {
        List<SysOaCostVo> list = iSysOaCostService.queryList(bo);
        ExcelUtil.exportExcel(list, "项目成本分析", SysOaCostVo.class, response);
    }

    /**
     * 获取项目成本分析详细信息
     *
     * @param costId 主键
     */
    @GetMapping("/old/{costId}")
    public R<SysOaCostVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long costId) {
        return R.ok(iSysOaCostService.queryById(costId));
    }

    /**
     * 新增项目成本分析
     */
    @Log(title = "项目成本分析", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add1(@Validated(AddGroup.class) @RequestBody SysOaCostBo bo) {
        return toAjax(iSysOaCostService.insertByBo(bo));
    }

    /**
     * 修改项目成本分析
     */
    @Log(title = "项目成本分析", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysOaCostBo bo) {
        return toAjax(iSysOaCostService.updateByBo(bo));
    }



//    /**
//     * 查询所有项目成本
//     */
//    @SaCheckPermission("oa:oaCost:list")
//    @GetMapping("/list")
//    public TableDataInfo<SysOaCostAllVo> AllList(@RequestParam(required = false) String projectName) {
//        return iSysOaCostService.AllList(projectName);
//    }

        /**
     * 查询所有项目成本
     */
    @GetMapping("/list")
    public TableDataInfo<SysOaCostAllVo> AllList(SysOaCostBo bo,PageQuery pageQuery) {
        return iSysOaCostService.calcProjectCostList(bo,pageQuery);
    }




    /**
     * 查询详情
     */
    @GetMapping("/{projectId}")
    public R<SysOaCostRow> getDetail(@NotNull(message = "项目id不能为空")
                                     @PathVariable Long projectId) {
        return R.ok(iSysOaCostService.calcProjectDetail(projectId));
    }

    /**
     * 新增成本
     */
    @Log(title = "项目成本分析", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysOaCostBo bo) {
        return toAjax(iSysOaCostService.insertByBo(bo));
    }

    /**
     * 删除项目成本分析
     *
     * @param ids 主键串
     */
    @Log(title = "项目成本分析", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iSysOaCostService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


}
