package cokr.xit.fims.cmmn.web;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cokr.xit.fims.base.service.bean.OgdpBean;
import cokr.xit.fims.cmmn.dao.ExtrStngMapper;
import cokr.xit.fims.cmmn.service.LinkService;
import cokr.xit.fims.cmmn.service.bean.LinkBean;
import cokr.xit.foundation.UserInfo;
import cokr.xit.foundation.data.DataObject;
import cokr.xit.foundation.web.AbstractController;

@Controller
@RequestMapping(name = "연계 처리", value = "/link")
public class LinkController extends AbstractController {
	@Resource(name = "linkBean")
	private LinkBean linkBean;
	@Resource(name = "linkService")
	private LinkService linkService;
	@Resource(name = "ogdpBean")
	private OgdpBean ogdpBean;
	@Resource(name = "extrStngMapper")
	private ExtrStngMapper extrStngMapper;

	@RequestMapping(name = "파일 처리", value = "/fileProcess.do")
	public ModelAndView fileProcess(String filePath, String job, String param) {
    	boolean saved = false;
    	UserInfo userInfo = currentUser();
    	ogdpBean.initUserInfo(userInfo);
    	String sggCd = (String) userInfo.getInfo().get("sggCd");

    	System.out.println("파라미터 : "+ param);

    	DataObject dataObject = fromJson(param, DataObject.class);

    	//차세대 세외수입 pdf파일 정보 추출
    	if("01".equals(job)) {
    		String taskSeCd = dataObject.string("taskSeCd");
        	String tmplatId = dataObject.string("tmplatId");

    		linkService.insertElectronicNoticeSndng(filePath, sggCd, taskSeCd, tmplatId);
    	}

    	return new ModelAndView("jsonView")
    		.addObject("saved", saved);
	}
}