package com.yeejoin.amos.supervision.business.controller;

import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.supervision.business.service.intfc.IPlanAuditService;
import com.yeejoin.amos.supervision.core.framework.PersonIdentify;
import com.yeejoin.amos.supervision.dao.entity.PlanAuditLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;

@RestController
@RequestMapping(value = "/api/planAudit")
@Api(tags = "计划审核api")
public class PlanAuditController extends AbstractBaseController {

    private final Logger log = LoggerFactory.getLogger(PlanAuditController.class);

    @Autowired
    private IPlanAuditService planAuditService;

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @PersonIdentify
    @ApiOperation(value = "计划工作流审核", notes = "计划工作流审核")
    @RequestMapping(value = "/auditWorkFlow", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public ResponseModel auditWorkFlow(
            @ApiParam(value = "工作流流水实例", required = true) @RequestBody PlanAuditLog planAuditLog,
            @ApiParam(value = "当前计划状态", required = true) @RequestParam Integer status,
            @ApiParam(value = "执行控制条件", required = true) @RequestParam String condition) throws Exception {
        ReginParams reginParams = getSelectedOrgInfo();
        return ResponseHelper.buildResponse(planAuditService.auditWorkFlow(planAuditLog, status, condition, reginParams));
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "指定计划的执行日志")
    @GetMapping(value = "/{planId}/timeLine")
    public ResponseModel timeLineLog(@PathVariable Long planId) {
        return ResponseHelper.buildResponse(planAuditService.listByPlanId(planId));
    }

}
