package com.dsk.cscec.controller;

import cn.hutool.core.lang.Assert;
import com.dsk.common.core.controller.BaseController;
import com.dsk.common.core.domain.R;
import com.dsk.cscec.domain.CbProjectRecord;
import com.dsk.cscec.domain.bo.AddCbProjectBo;
import com.dsk.cscec.service.CbProjectRecordService;
import com.dsk.cscec.service.IDProjectService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * 项目台账表(CbProjectRecord)表控制层
 *
 * @author sxk
 * @since 2024-02-05 11:37:49
 */
@RestController
@RequestMapping("cbProjectRecord")
public class CbProjectRecordController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private CbProjectRecordService baseService;
    @Resource
    private IDProjectService dProjectService;

    /**
     * 校验项目编码是否存在
     */
    @GetMapping("/checkProjectCodeExist/{projectCode}")
    public R<Boolean> checkProjectCodeExist(@NotBlank(message = "项目编码不能为空") @PathVariable String projectCode) {
        return R.ok(dProjectService.checkProjectCodeExist(projectCode));
    }

    /**
     * 新增项目
     */
    @PostMapping("/addProject")
    public R<CbProjectRecord> addProject(@Validated @RequestBody AddCbProjectBo addCbProjectBo) {
        CbProjectRecord projectRecord = baseService.addProject(addCbProjectBo);
        Assert.notNull(projectRecord, "新增项目失败,请联系管理员");
        return R.ok(projectRecord);
    }

    ///**
    // * 根据项目文件导入数据
    // */
    //@PostMapping("/importData")
    //public R<Void> importData(@Validated @RequestBody ImportCbProjectDataBo importDataBo){
    //    return toAjax(baseService.importData(importDataBo));
    //}

}

