package egovframework.rte.cvpl.util;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import egovframework.rte.cvpl.service.CvplCnsltVO;
import egovframework.rte.cvpl.service.EgovCvplCnsltService;
import egovframework.rte.itl.integration.EgovIntegrationMessage;
import egovframework.rte.itl.integration.EgovIntegrationServiceProvider;

@Repository("serviceProviderRegisterCvpl")
public class ServiceProviderRegisterCvpl implements EgovIntegrationServiceProvider {

    /** EgovCvplCnsltService */
    @Resource(name = "cvplCnsltService")
    private EgovCvplCnsltService cvplCnsltService;

    public void service(EgovIntegrationMessage requestMessage, EgovIntegrationMessage responseMessage) {
        Map<String, Object> requestBody = requestMessage.getBody();

        CvplCnsltVO vo = new CvplCnsltVO();
        vo.setCvplNo((String) requestBody.get("cvplNo"));
        vo.setCvplSj((String) requestBody.get("cvplSj"));
        vo.setCvplContents((String) requestBody.get("cvplContents"));
        vo.setCvplAtch1((String) requestBody.get("cvplAtch1"));
        vo.setCvplAtch2((String) requestBody.get("cvplAtch2"));
        vo.setCvplOthbcCode((String) requestBody.get("cvplOthbcCode"));
        vo.setOrgReceiptTime((String) requestBody.get("receiptTime"));
        vo.setUserId((String) requestBody.get("userId"));
        vo.setAnswerContents((String) requestBody.get("answerContents"));
        vo.setAnswerAtch1((String) requestBody.get("answerAtch1"));
        vo.setAnswerAtch2((String) requestBody.get("answerAtch2"));
        vo.setOrgAnswerTime((String) requestBody.get("answerTime"));
        vo.setAnswerUserId((String) requestBody.get("answerUserId"));
        vo.setEmailYn((String) requestBody.get("emailYn"));
        vo.setAdmnstmachCode((String) requestBody.get("admnstmachCode"));
        vo.setBestYn((String) requestBody.get("bestYn"));

        Map<String, Object> responseBody = new HashMap<String, Object>();
        try {
            cvplCnsltService.insertBestCvplCnslt(vo);
            responseBody.put("result", true);
        } catch (Exception e) {
            responseBody.put("result", false);
        }

        responseMessage.setBody(responseBody);
    }
}
