package com.engine.htsc.zgk.flfgk.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.zgk.flfgk.service.FlfgkService;
import com.engine.htsc.zgk.flfgk.service.impl.FlfgkServiceImpl;
import com.engine.integration.util.StringUtils;
import weaver.general.Util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 法律法规库 和 宣传素材库 相关接口
 * @author K1810039
 */
public class FlfgkAction {

    FlfgkService getService(){
        return ServiceUtil.getService(FlfgkServiceImpl.class);
    }

    /**
     * 获取法规类别
     */
    @POST
    @Path("/getFglb")
    @Produces({MediaType.TEXT_PLAIN})
    public String getFglb(){
        List<Map<String, String>> listMap = new ArrayList<>();
        try {
            listMap = getService().getFglb();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JSONObject.toJSONString(listMap);
    }

    /**
     * 根据法规类别查询该类别下的所有法规的相关数据
     */
    @POST
    @Path("/getFgInfo")
    @Produces({MediaType.APPLICATION_JSON})
    public String getFgInfo(String id){
        List<Map<String, String>> listMap = new ArrayList<>();
        // 法规类别ID
        String fglbId = Util.null2String(id);
        if (StringUtils.isBlank(fglbId)){
            return null;
        }
        try {
            listMap = this.getService().getFgInfo(fglbId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JSONObject.toJSONString(listMap);
    }

    /**
     * 法律法规库 和 宣传材料库 校验文件重复性
     */
    @POST
    @Path("/checkFile")
    @Produces({MediaType.APPLICATION_JSON})
    public String checkFile(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String , String > apidatas = new HashMap<>();
        String docId = request.getParameter("docId");
        String tableName = request.getParameter("tableName");
        apidatas  = this.getService().checkFile(docId,tableName);
        apidatas.put("success","true");
        return JSONObject.toJSONString(apidatas);
    }


}
