package com.hotent.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.common.CrudService;
import com.hotent.project.req.CostProjectMemoQueryReq;
import com.hotent.project.req.CostProjectMemoUpdateReq;
import com.hotent.project.resp.CostProjectMemoDetailResp;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
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 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.project.model.CostProjectMemo;
import com.hotent.project.manager.CostProjectMemoManager;

/**
 * 监审项目备忘录表 前端控制器
 *
 * @company 山西清众科技股份有限公司
 * @author 超级管理员
 * @since 2025-09-25
 */
@Api(tags = "监审项目备忘录表")
@RestController
@RequestMapping("/api/costProjectMemo/v1/")
@ApiGroup(group = {ApiGroupConsts.GROUP_COST})
public class CostProjectMemoController extends BaseController<CostProjectMemoManager, CostProjectMemo> {
    @Autowired
    private CostProjectMemoManager costProjectMemoManager;

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

	//分页查询
	/*@PostMapping(value="/pageList")
	@ApiOperation(value="备忘录列表")
	public PageResp<CostProjectMemoQueryResp> pageList(@RequestBody CostProjectMemoQueryReq req) {
		return crudService.pageQuery(req, costProjectMemoManager::pageList);
	}*/

    @PostMapping(value="/pageList")
    @ApiOperation(value="备忘录列表")
    public CommonResult<IPage<CostProjectMemo>> pageList(@RequestBody CostProjectMemoQueryReq req) {
        return CommonResult.<IPage<CostProjectMemo>>ok().value(costProjectMemoManager.pageList(req));
    }

    @PostMapping(value="/pageIndexList")
    @ApiOperation(value="首页备忘录列表")
    public CommonResult<IPage<CostProjectMemo>> pageIndexList(@RequestBody CostProjectMemoQueryReq req){
        return  CommonResult.<IPage<CostProjectMemo>>ok().value(costProjectMemoManager.pageIndexList(req));
    }

    @PostMapping(value="/save")
    @ApiOperation(value="添加")
    @Transactional(rollbackFor = Exception.class)
    public CommonResult save(@RequestBody CostProjectMemo t) {
        Boolean result = costProjectMemoManager.saveData(t);
        return CommonResult.ok().value(result ? "添加成功" : "添加失败");
    }
    /**
     * 根据id获取监审项目备忘录表数据详情
     * @param id
     * @return
     * @throws Exception
     * ModelAndView
     */
    @GetMapping(value = "/getDetail")
    @ApiOperation(value = "根据id获取监审项目备忘录表数据详情", httpMethod = "GET", notes = "根据id获取监审项目备忘录表数据详情")
    public CommonResult<CostProjectMemoDetailResp> getDetail(@ApiParam(name = "id", value = "业务对象主键", required = true) @RequestParam(required = true) String id) throws Exception {
        return CommonResult.<CostProjectMemoDetailResp>ok().value(costProjectMemoManager.getDetail(id));
    }

    /**
     * 更新监审项目备忘录表
     * @param  req
     * @throws Exception
     * @return
     * @exception
     */
    @PostMapping(value = "/update")
    @ApiOperation(value = "更新监审项目备忘录表数据", httpMethod = "POST", notes = "更新监审项目备忘录表数据")
    public CommonResult update(@RequestBody CostProjectMemoUpdateReq req) throws Exception {
        int result = costProjectMemoManager.updateMemo(req);
        return CommonResult.ok().value(result > 0 ? "更新成功" : "更新失败");
    }

    @GetMapping(value = "/getDataMonth")
    @ApiOperation(value = "获取项目月度数据", httpMethod = "GET", notes = "获取项目月度数据")
    public CommonResult getDataMonth(@ApiParam(name = "month", value = "月", required = true) @RequestParam(required = false,name = "month")String month){
        return CommonResult.ok().value(costProjectMemoManager.getDataMonth(month));
    }

    @GetMapping(value = "/getIndexDataMonth")
    @ApiOperation(value = "获取首页项目月度数据", httpMethod = "GET", notes = "获取首页项目月度数据")
    public CommonResult getIndexDataMonth(@ApiParam(name = "month", value = "月", required = true) @RequestParam(required = false,name = "month")String month){
        return CommonResult.ok().value(costProjectMemoManager.getIndexDataMonth(month));
    }
}
