package com.seeyon.ctp.rest.resources.esign;

import cn.hutool.log.Log;
import com.seeyon.apps.esign.service.EsignFileTemplateService;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.rest.resources.BaseResource;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import java.util.Map;

@Path("/etemplate")
public class EsignTemplateResource extends BaseResource {

    private static final Log log = Log.get(EsignTemplateResource.class);
    private EsignFileTemplateService esignFileTemplateService = (EsignFileTemplateService) AppContext.getBean("esignFileTemplateService");

    @GET
    @Produces({"application/json"})
    @Consumes({"application/json"})
    @Path("/querypage")
    public Response queryTemplates(@QueryParam("pageNum") Integer pageNum) {
        try {
            Map<String, Object> map = esignFileTemplateService.queryTemplates("",pageNum);
            return success(map);
        }catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage(),e);
        }
        return fail("失败");
    }

    @POST
    @Produces({"application/json"})
    @Consumes({"application/json"})
    @Path("/compareurl")
    public Response compare(@QueryParam("templateRefId") String templateRefId,@QueryParam("contractRefId") String contractRefId) {
        try {
            String compareDetailUrl = esignFileTemplateService.getCompareDetailUrl("",templateRefId, contractRefId);
            return success(compareDetailUrl);
        }catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage(),e);
        }
        return fail("失败");
    }
}
