package com.reyun.saas.web.controller.user;

import com.reyun.saas.common.framework.ApiRestController;
import com.reyun.saas.common.restResult.RestResult;
import com.reyun.saas.mob.user.dto.user.WorkOrderLogDTO;
import com.reyun.saas.mob.user.service.WorkOrderService;
import com.reyun.saas.security.utils.SecurityUtils;
import com.reyun.saas.web.aop.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Slf4j
@Api(value = "/workOrder", tags = "工单模块")
@ApiRestController("/workOrder")
public class WorkOrderController {

    @Resource
    private WorkOrderService workOrderService;


    //创建到导出
    @Log(value = 1, description = "创建日志/报表", type = 5,insertDB = true)
    @ApiOperation(value = "创建工单", notes = "" , produces = "application/json")
    @PostMapping("createLog")
    public RestResult create(@RequestBody WorkOrderLogDTO source){
        return workOrderService.create(source, SecurityUtils.getLoginUserId());
    }

    //工单列表展示
    @Log(value = 4, description = "工单导出列表展示", type = 5)
    @ApiOperation(value = "工单导出列表展示", produces = "application/json"
            ,notes = "当前页数:page 每页条数:size 排序字段:sortField 排序格则:sortOrder(ASC正序 DESC倒序)" +
            "app:appkey 类型:type(日志和报表) 所属模块:model 创建者:createUser")
    @PostMapping("list")
    public RestResult list(@RequestBody Map<String,Object> map){
        return workOrderService.list(map,SecurityUtils.getLoginUserId());
    }



    //下载
    @Log(value = 8, description = "下载工单", type = 5,insertDB = true)
    @ApiOperation(value = "下载工单", notes = "" , produces = "application/json")
    @GetMapping("download/{wordOrderId}")
    public RestResult download(HttpServletRequest request, @PathVariable Long wordOrderId) {
       return workOrderService.download(request,wordOrderId,SecurityUtils.getLoginUserId());
    }


    //导出失败重试导出
    @Log(value = 3, description = "工单导出失败重试", type = 5,insertDB = true)
    @ApiOperation(value = "工单导出失败重试", notes = "" , produces = "application/json")
    @PutMapping("retry/{wordOrderId}")
    public RestResult retry(@PathVariable Long wordOrderId){
        return workOrderService.retry(wordOrderId,SecurityUtils.getLoginUserId());
    }



    //删除
    @Log(value = 2, description = "删除工单", type = 5,insertDB = true)
    @ApiOperation(value = "删除工单", notes = "" , produces = "application/json")
    @DeleteMapping("delete/{wordOrderId}")
    public RestResult delete(@PathVariable Long wordOrderId){
        return workOrderService.delete(wordOrderId, SecurityUtils.getLoginUserId());
    }


    @Log(value = 4, description = "查询筛选条件", type = 5)
    @ApiOperation(value = "筛选条件下拉列表", produces = "application/json",
            notes = "下拉列表标识 : key(app 或者 createUser) 系统: os")
    @GetMapping("screeningInfo")
    public RestResult screening(String key,String os){
        return workOrderService.screening(key,os,SecurityUtils.getLoginUserId());
    }



}
