package com.jwipc.sys.controller.pc;

import com.jwipc.sys.logic.OaTrackLogic;
import com.jwipc.sys.util.FinancialShareUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

import static com.jwipc.sys.constant.ModuleConst.MODULE_ROOT;

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@RestController
@RequestMapping(MODULE_ROOT + "/oaTrack/rest")
@RequiredArgsConstructor
public class OaTrackController {
    private final OaTrackLogic oaTrackLogic;
    private final FinancialShareUtil financialShareUtil;
    @GetMapping("index")
    public ResponseEntity getOaTrack(String oaId, Integer type) throws UnsupportedEncodingException {
        return ResponseEntity.ok(oaTrackLogic.getUrl(oaId, type));
    }

    @GetMapping("/share/index")
    public ResponseEntity getShareTrack(String formId, String pkId) throws UnsupportedEncodingException {
        return ResponseEntity.ok(financialShareUtil.getFinancialShareFormUrl(formId, pkId));
    }

    @PostMapping("file")
    public ResponseEntity getOaFile(String url) throws UnsupportedEncodingException {
        return ResponseEntity.ok(oaTrackLogic.getUrl(url));
    }
}
