package com.hotent.baseInfo.controller;


import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.baseInfo.req.CostBaseInfoPageReq;
import com.hotent.common.CrudService;
import com.hotent.req.IdReq;
import com.hotent.resp.PageResp;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
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.CostCatalogUnit;
import com.hotent.baseInfo.manager.CostCatalogUnitManager;

/**
 * 成本监审目录-提交资料清单 前端控制器
 *
 * @author 超级管理员
 * @company 山西清众科技股份有限公司
 * @since 2025-09-29
 */
@RestController
@RequestMapping("/api/costCatalogUnit/v1/")
@ApiGroup(group = {ApiGroupConsts.GROUP_COST})
@Api(tags = "成本监审目录-提交资料清单表")
public class CostCatalogUnitController extends BaseController<CostCatalogUnitManager, CostCatalogUnit> {


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

    /**
     * 根据id获取成本监审目录-提交资料清单数据详情
     *
     * @param id
     * @return
     * @throws Exception ModelAndView
     */

    @GetMapping(value = "/getDetail")
    @ApiOperation(value = "根据id获取成本监审目录-提交资料清单数据详情", httpMethod = "GET", notes = "根据id获取成本监审目录-提交资料清单数据详情")
    public CommonResult<CostCatalogUnit> getDetail(@ApiParam(name = "id", value = "业务对象主键", required = true) @RequestParam(required = true) String id) throws Exception {
        return CommonResult.<CostCatalogUnit>ok().value(baseService.getDetail(id));
    }

    //分页查询

    @PostMapping(value = "/pageList")
    @ApiOperation(value = "分页查询成本监审目录-提交资料清单数据", httpMethod = "POST", notes = "分页查询成本监审目录-提交资料清单数据")
    public PageResp<CostCatalogUnit> pageList(@ApiParam(name = "CostCatalogUnit", value = "成本监审目录-提交资料清单对象", required = true) @RequestBody CostBaseInfoPageReq req) throws Exception {
        return crudService.pageQuery(req, baseService::pageList);
    }

    //创建
    @PostMapping(value = "/create")
    @ApiOperation(value = "添加实体的接口", httpMethod = "POST", notes = "添加实体的接口")
    public CommonResult<String> create(@Validated  @RequestBody CostCatalogUnit costCatalogUnit) {
        baseService.create(costCatalogUnit);
       return CommonResult.<String>ok().message("新增成功");

    }

    //更新
    @PostMapping(value = "/update")
    @ApiOperation(value = "更新成本监审目录-提交资料清单数据", httpMethod = "POST", notes = "更新成本监审目录-提交资料清单数据")
    public CommonResult<String> update(@Validated @RequestBody CostCatalogUnit costCatalogUnit) {
        CostCatalogUnit byId = this.getById(costCatalogUnit.getId());
        if (byId == null) {
            return CommonResult.<String>error().message("数据不存在");
        }
        baseService.update(costCatalogUnit);
        return CommonResult.<String>ok().message("修改成功");
    }

    //取消关联文件
    @PostMapping(value="/cleanByIds")
    @ApiOperation(value="取消关联文件",httpMethod = "POST",notes = "取消关联文件")
    public CommonResult<String> cleanByIds(@ApiParam(name="ids", value="id集合") @RequestBody IdReq req){
        baseService.removeByIds(req.getIds());
        return CommonResult.<String>ok().message("批量取消关联文件成功");
    }
}
