package com.hotent.baseInfo.controller;


import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.baseInfo.model.CostDistrict;
import com.hotent.baseInfo.req.CostDocumentTemplatePageReq;
import com.hotent.baseInfo.req.CostDocumentTemplateReq;
import com.hotent.common.CrudService;
import com.hotent.req.IdReq;
import com.hotent.resp.PageResp;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.StringUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.hotent.base.controller.BaseController;
import com.hotent.baseInfo.model.CostDocumentTemplate;
import com.hotent.baseInfo.manager.CostDocumentTemplateManager;

import java.util.List;

/**
 * 监审文书 前端控制器
 *
 * @company 山西清众科技股份有限公司
 * @author 超级管理员
 * @since 2025-09-17
 */
@RestController
@RequestMapping("/api/costDocumentTemplate/v1/")
@Api(tags = "监审文书管理")
@ApiGroup(group = {ApiGroupConsts.GROUP_COST})
public class CostDocumentTemplateController extends BaseController<CostDocumentTemplateManager, CostDocumentTemplate> {

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

	/**
	 * 获取文号分类
	 */
	@GetMapping(value="/getWhCateList")
	@ApiOperation(value="获取文号分类",httpMethod = "GET",notes = "获取文号分类")
	public CommonResult<List<CostDocumentTemplate>> getWhCateList() throws Exception{
		List<CostDocumentTemplate> whCateList = baseService.getWhCateList();
		return CommonResult.<List<CostDocumentTemplate>>ok().value(whCateList);
	}

	//分页查询
	@PostMapping(value="/pageList")
	@ApiOperation(value="分页查询pageList",httpMethod = "POST",notes = "分页查询pageList")
	public PageResp<CostDocumentTemplate> pageList(@RequestBody CostDocumentTemplatePageReq req) throws Exception{
		return  crudService.pageQuery(req, baseService::getTemplateList);
	}

	//新增文书
	@PostMapping(value="/save")
	@ApiOperation(value="新增文书",httpMethod = "POST",notes = "新增文书")
	public  CommonResult<String> save(@RequestBody CostDocumentTemplateReq req) throws Exception{
		String id = costDocumentTemplateManager.create(req);
		return CommonResult.<String>ok().value(id).message("保存成功");

	}
	//修改文书
	@PutMapping(value="/update")
	@ApiOperation(value="修改文书",httpMethod = "Put",notes = "修改文书")
	public  CommonResult<String> update(@RequestBody CostDocumentTemplateReq req) throws Exception{
		costDocumentTemplateManager.updateTemplate(req);
		return CommonResult.<String>ok().message("修改成功");

	}

	@PostMapping(value="/deleteByIds")
	@ApiOperation(value="根据id删除数据",httpMethod = "POST",notes = "根据id删除数据")
	public CommonResult<String> deleteByIds(@ApiParam(name="ids", value="id集合") @RequestBody IdReq req){
		costDocumentTemplateManager.deleteByIds(req.getIds());
		return CommonResult.<String>ok().message("删除文书成功");
	}

}
