package com.hotent.enterpriseDeclare.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.StringUtil;
import com.hotent.baseInfo.manager.AuditedUnitManager;
import com.hotent.baseInfo.manager.CostDistrictManager;
import com.hotent.baseInfo.model.AuditedUnit;
import com.hotent.baseInfo.model.CostDistrict;
import com.hotent.constant.NodeConstant;
import com.hotent.constant.TaskStatusConstant;
import com.hotent.enterpriseDeclare.req.CostAuditTaskPageReq;
import com.hotent.enterpriseDeclare.req.CostTaskPageReq;
import com.hotent.project.manager.CostProjectApprovalManager;
import com.hotent.project.manager.CostProjectTaskManager;
import com.hotent.project.manager.CostProjectTaskNodeManager;
import com.hotent.project.manager.CostProjectTaskProccessManager;
import com.hotent.project.model.*;
import com.hotent.project.resp.CostProjectApprovalDetailResp;
import com.hotent.uc.api.model.IUser;
import com.hotent.uc.manager.OrgManager;
import com.hotent.uc.util.ContextUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "成本监审任务填报")
@RestController
@RequestMapping("/api/enterprise/castTask")
@ApiGroup(group = {ApiGroupConsts.GROUP_COST})
public class CostAuditTaskController {

    @Autowired
    private AuditedUnitManager auditedUnitManager;

    @Autowired
    private CostProjectApprovalManager costProjectApprovalManager;

    @Autowired
    private CostProjectTaskManager costProjectTaskManager;


    /**
     * 分页查询当前用户企业需要填写的监审任务
     * @param req 分页查询请求参数
     * @return 已发布的任务分页列表
     */
    @PostMapping(value = "/pageList")
    @ApiOperation(value = "分页查询当前用户企业需要填写的监审任务", httpMethod = "POST", notes = "分页查询当前用户企业需要填写的监审任务")
    public CommonResult<IPage<CostProjectApproval>> pageList(@RequestBody CostAuditTaskPageReq req) {
        IPage<CostProjectApproval> pageResult = costProjectApprovalManager.pageListForAuditTask(req);
        return CommonResult.<IPage<CostProjectApproval>>ok().value(pageResult);
    }



    @GetMapping(value="/getDetail")
    @ApiOperation(value="任务立项详情",httpMethod = "GET",notes = "任务立项详情")
    public CommonResult<CostProjectApprovalDetailResp> getDetail(@ApiParam(name="id",value="业务对象主键", required = true)@RequestParam(required=true) String id) throws Exception{
        return CommonResult.<CostProjectApprovalDetailResp>ok().value(costProjectApprovalManager.getDetail(id));
    }


    @PostMapping(value="/save")
    @ApiOperation(value="提交任务填报",httpMethod = "POST",notes = "提交任务填报")
    public CommonResult<String> save(@RequestBody CostTaskPageReq costTaskPageReq) throws Exception{
        return CommonResult.<String>ok().value(costProjectTaskManager.saveTask(costTaskPageReq));
    }

    @PostMapping(value="/yjsave")
    @ApiOperation(value="意见反馈任务填报",httpMethod = "POST",notes = "意见反馈")
    public CommonResult<String> yjsave(@RequestBody CostProjectTaskPreliminaryOpinion costProjectTaskPreliminaryOpinion) throws Exception{
        return CommonResult.<String>ok().value(costProjectTaskManager.saveYjTask(costProjectTaskPreliminaryOpinion));
    }
}
