package cn.ezhizao.project.websocket.controller;

import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.project.websocket.domain.BizProcessInspecion;
import cn.ezhizao.project.websocket.service.TaskService;
import com.alibaba.fastjson2.JSONObject;
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.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/business/asyncExport")
public class AsyncExportController extends BaseController {
    @Resource
    private TaskService taskService;
//    @Resource
//    private WebSocketUser webSocketUser;

//    @PreAuthorize("@ss.hasPermi('business:asyncExport:export')")
    @Log(title = "外协审核导出", businessType = BusinessType.EXPORT)
    @PostMapping("/processInspectionexport")
    public AjaxResult export(HttpServletResponse response, @RequestBody BizProcessInspecion bizProcessInspecion) throws IOException {
        taskService.processTaskAsync(bizProcessInspecion, getUserId());
        JSONObject result = new JSONObject();
        result.put("status", "start");
//        WebSocketUser.sendInfo(result.toJSONString(), String.valueOf(getUserId()));
        // 开始导出
        return success();
    }
}
