package com.hotent.baseInfo.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.extension.api.R;
import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.query.PageList;
import com.hotent.baseInfo.model.CostCatalog;
import com.hotent.baseInfo.req.CostCatalogPageReq;
import com.hotent.baseInfo.req.CostDocumentWhPageReq;
import com.hotent.baseInfo.resp.AuditedUnitDetailResp;
import com.hotent.baseInfo.resp.CostDocumentWhDetailResp;
import com.hotent.common.CrudService;
import com.hotent.req.IdReq;
import com.hotent.resp.PageResp;
import io.swagger.annotations.Api;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
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 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.hotent.base.controller.BaseController;
import com.hotent.baseInfo.model.CostDocumentWh;
import com.hotent.baseInfo.manager.CostDocumentWhManager;

/**
 * 监审文号管理 前端控制器
 *
 * @company 山西清众科技股份有限公司
 * @author 超级管理员
 * @since 2025-09-14
 */
@RestController
@RequestMapping("/api/costDocumentWh/v1/")
@Api(tags = "监审文号管理")
@ApiGroup(group = {ApiGroupConsts.GROUP_COST})
public class CostDocumentWhController{

	@Autowired
	private CostDocumentWhManager costDocumentWhManager;

	// 创建通用服务实例
	private final CrudService crudService = new CrudService();

	/**
	 * 查询文号分页列表
	 */
	@SneakyThrows
    @PostMapping("/pageList")
	@ApiOperation(value = "分页查询pageList", notes = "分页查询pageList")
	public PageList<CostDocumentWh> getCatalogList(@RequestBody CostDocumentWhPageReq req) {
		PageList<CostDocumentWh> documentWhList = costDocumentWhManager.getDocumentWhList(req);
		return documentWhList;

	}

	/**
	 * 根据id获取监审文号管理表数据详情
	 * @param id
	 * @return
	 * @throws Exception 
	 * ModelAndView
	 */
	@GetMapping(value="/getDetail")
	@ApiOperation(value="根据id获取监审文号管理表数据详情",httpMethod = "GET",notes = "根据id获取监审文号管理表数据详情")
	public CommonResult<CostDocumentWhDetailResp> getDetail(@ApiParam(name="id",value="业务对象主键", required = true)@RequestParam(required=true) String id) throws Exception{
		try {
			CostDocumentWhDetailResp unit = costDocumentWhManager.getDetail(id);
			return CommonResult.<CostDocumentWhDetailResp>ok().value(unit);
		} catch (Exception e) {
			return CommonResult.<CostDocumentWhDetailResp>error().message("查询失败：" + e.getMessage());
		}
	}
	@PostMapping(value="/save")
	@ApiOperation(value = "新增/修改监审文号管理", httpMethod = "POST", notes = "新增,监审文号管理")
	public CommonResult<String> save(@ApiParam(name="CostDocumentWh",value="项目任务表对象", required = true)@RequestBody CostDocumentWh costDocumentWh) throws Exception{
		String msg = StringUtil.isEmpty(costDocumentWh.getId()) ? "添加成功" : "更新成功";
		costDocumentWhManager.createOrUpdate(costDocumentWh);
		return CommonResult.<String>ok().message(msg);
	}



//	@GetMapping(value="/getCurrentValue")
//	@ApiOperation(value="获取文号值",httpMethod = "GET",notes = "获取文号值")
//	public CommonResult<CostDocumentWh> getCurrentValue(@ApiParam(name="id",value="业务对象主键", required = true)@RequestParam(required=true) String id) throws Exception{
//		try {
//			CostDocumentWh unit = costDocumentWhManager.updateCurrentValue(id);
//			return CommonResult.<CostDocumentWh>ok().value(unit);
//		} catch (Exception e) {
//			return CommonResult.<CostDocumentWh>error().message("获取失败：" + e.getMessage());
//		}
//	}

	@GetMapping(value="/delete")
	@ApiOperation(value = "删除", httpMethod = "GET", notes = "删除")
	public CommonResult<String> delete(@ApiParam(name="id",value="业务对象主键", required = true)@RequestParam(required=true) String id) throws Exception{
		costDocumentWhManager.remove(id);
		return CommonResult.<String>ok().message("删除成功");
	}

	// 批量删除
	@PostMapping(value="/batchDelete")
	@ApiOperation(value = "批量删除", httpMethod = "POST", notes = "批量删除")
	public CommonResult<String> batchDelete(@ApiParam(name="ids",value="业务对象主键", required = true)@RequestBody IdReq idReq) throws Exception{
		costDocumentWhManager.deleteByIds(idReq.getIds());
		return CommonResult.<String>ok().message("批量删除成功");
	}

}
