package com.hotent.project.controller;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.StringUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.hotent.base.controller.BaseController;
import com.hotent.project.model.CostProjectTaskMaterial;
import com.hotent.project.manager.CostProjectTaskMaterialManager;
import javax.servlet.http.HttpServletResponse;

/**
 * 任务定制-报送资料要求 前端控制器
 *
 * @company 山西清众科技股份有限公司
 * @author 超级管理员
 * @since 2025-10-09
 */
@RestController
@RequestMapping("/costProjectTaskMaterial/v1/")
public class CostProjectTaskMaterialController extends BaseController<CostProjectTaskMaterialManager, CostProjectTaskMaterial> {

	/**
	 * 根据taskId获取任务定制-报送资料要求数据列表
	 * @param taskId 任务ID
	 * @return
	 * @throws Exception 
	 */
	@GetMapping(value="/listByTaskId")
	@ApiOperation(value="根据taskId获取任务定制-报送资料要求数据列表",httpMethod = "GET",notes = "根据taskId获取任务定制-报送资料要求数据列表")
	public CommonResult<List<CostProjectTaskMaterial>> listByTaskId(@ApiParam(name="taskId",value="任务ID", required = true)@RequestParam(required=true) String taskId) throws Exception{
		return CommonResult.<List<CostProjectTaskMaterial>>ok().value(baseService.listByTaskId(taskId));
	}
    /**
	 * 新增,更新任务定制-报送资料要求
	 * @param costProjectTaskMaterial
	 * @throws Exception
	 * @return
	 * @exception
	 */
	@PostMapping(value="/save")
	@ApiOperation(value = "新增,更新任务定制-报送资料要求数据", httpMethod = "POST", notes = "新增,更新任务定制-报送资料要求数据")
	public CommonResult<String> save(@ApiParam(name="CostProjectTaskMaterial",value="任务定制-报送资料要求对象", required = true)@RequestBody CostProjectTaskMaterial costProjectTaskMaterial) throws Exception{
		String msg = StringUtil.isEmpty(costProjectTaskMaterial.getId()) ? "添加任务定制-报送资料要求成功" : "更新任务定制-报送资料要求成功";

		// 如果有文件上传，设置上传状态和时间
		if(StringUtils.isNotBlank(costProjectTaskMaterial.getFileUrl())) {
			costProjectTaskMaterial.setIsUpload("1");
			costProjectTaskMaterial.setIsRequired("1");
			costProjectTaskMaterial.setUploadTime(LocalDateTime.now());
		}

		// 调用Manager层保存，会自动处理任务节点和资料类别
		baseService.createOrUpdate(costProjectTaskMaterial);
		return CommonResult.<String>ok().message(msg);
	}
}
