package com.dsk.cscec.controller;

import com.dsk.common.core.controller.BaseController;
import com.dsk.common.core.domain.R;
import com.dsk.common.helper.LoginHelper;
import com.dsk.cscec.domain.CbProjectExpenseSummary;
import com.dsk.cscec.service.CbProjectExpenseSummaryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;

/**
 * 项目费用汇总表(CbProjectExpenseSummary)表控制层
 *
 * @author sxk
 * @since 2024-02-22 09:59:28
 */
@RestController
@RequestMapping("CbProjectExpenseSummary")
public class CbProjectExpenseSummaryController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private CbProjectExpenseSummaryService baseService;

    /**
     * 现场经费汇总数据解析
     */
    @GetMapping("/parseCbSceneExpenseData/{projectId}")
    public R<Void> parseCbSceneExpenseData(@PathVariable Long projectId) throws Exception {
        String username = Objects.requireNonNull(LoginHelper.getLoginUser()).getUsername();
        baseService.parseSceneExpenseSummaryData(projectId, 1, username);
        return R.ok();
    }

    /**
     * 获取现场经费汇总数据
     */
    @GetMapping("/getCbSceneExpenseSummaryData/{projectId}")
    public R<List<CbProjectExpenseSummary>> getCbSceneExpenseSummaryData(@NotNull(message = "项目ID不能为空") @PathVariable Long projectId) {
        return R.ok(baseService.getCbSceneExpenseSummaryData(projectId));
    }
}

