/*
 * Author: Zev
 * 生成controller
 */
package com.tofly.gpsboot.controller.report;

import com.tofly.common.core.entity.ResultRespone;

import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.pojo.plan.dto.ReportAuditDto;
import com.tofly.gpsboot.exception.BusinessException;
import com.tofly.gpsboot.strategy.context.ReportStrategyContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 上报通用接口
 *
 * @author admin
 * @date Thu Mar 18 00:00:00 CST 2021
 */
@RestController
@RequestMapping("/report")
@Api(tags = "上报接口")
public class ReportController {
    @Autowired
    private ReportStrategyContext reportStrategyContext;

    @ApiOperation(value = "上报处理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "templateServiceType", value = "上报类型: 0:年计划 1:月计划上报 2:隐患上报 3:隐患消除上报 4:工地上报 5:工地监护消除上报 6:任务暂停上报 7:任务作废上报 8:抢维修年计划上报 9:抢维修工单派工 10:抢维修工单处理上报 11抢维修月计划上报", required = true, dataType = "String"),
    })
    @PostMapping("/reportDispose")
    @ToFlyAppLog(title = "上报处理")
    public ResultRespone<Object> reportDispose(String templateServiceType, @RequestBody ReportAuditDto dto) {
        ResultRespone<Object> rest = new ResultRespone<>();
        try {
            reportStrategyContext.report(templateServiceType, dto);
        }catch (BusinessException e){
            rest.setCode(e.getRetCd());
            rest.setMessage(e.getMessage());
        }
        return rest;
    }

}
