package com.engine.htxc.tycgsq.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ServiceUtil;
import com.engine.htxc.tycgsq.service.TycgsqService;
import com.engine.htxc.tycgsq.service.impl.TycgsqServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.HashMap;

public class TycgsqAction  {
    private TycgsqService getTycgsqService(){return ServiceUtil.getService(TycgsqServiceImpl.class);};

    /**
     *
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getLxxmByCgxmlx")
    @Produces({MediaType.TEXT_PLAIN})
    public String getLxxmByCgxmlx(@Context HttpServletRequest request, @Context HttpServletResponse response){
        HashMap<String, Object> map = new HashMap<>();
        try{
            String cgxmlx = request.getParameter("cgxmlx");
            ArrayList<HashMap<String, Object>> lxxmByCgxmlx = getTycgsqService().getLxxmByCgxmlx(cgxmlx);
            map.put("code",200);
            map.put("msg","success");
            map.put("data",lxxmByCgxmlx);
        }catch (Exception e){
            map.put("code",500);
            map.put("msg","err");
            map.put("data","");
        }
        return JSONObject.toJSONString(map);
    }

    /**
     * 这个接口用来判断立项项目列表是否允许删除
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/allowDelete")
    @Produces({MediaType.TEXT_PLAIN})
    public String allowDelete(@Context HttpServletRequest request, @Context HttpServletResponse response){
        HashMap<String, Object> map = new HashMap<>();
        try{
            String ids = request.getParameter("ids");
            boolean b = getTycgsqService().allowDelete(ids);
            map.put("code",200);
            map.put("msg","success");
            map.put("data",b);
        }catch (Exception e){
            map.put("code",500);
            map.put("msg",e.getMessage());
        }
        return JSONObject.toJSONString(map);
    }

    /**
     * 这个接口是用来校验通用采购申请提交时，明细表采购项目是否存在在途流程
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/allowSubmit")
    @Produces({MediaType.TEXT_PLAIN})
    public String allowSubmit(@Context HttpServletRequest request, @Context HttpServletResponse response){
        HashMap<String, Object> map = new HashMap<>();
        try{
            String ids = request.getParameter("ids");
            String requestid = request.getParameter("requestid");
            ArrayList<String>  list = getTycgsqService().allowSubmit(ids,requestid);
            map.put("code",200);
            map.put("msg","success");
            map.put("data",list);
        }catch (Exception e){
            map.put("code",500);
            map.put("msg",e.getMessage());
        }
        return JSONObject.toJSONString(map);
    }

    /**
     * 根据
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getGllcByJmid")
    @Produces({MediaType.TEXT_PLAIN})
    public String getGllcByJmid(@Context HttpServletRequest request, @Context HttpServletResponse response){
        HashMap<String, Object> map = new HashMap<>();
        try{
            String ids = request.getParameter("ids");
            String requestid = request.getParameter("requestid");
            ArrayList<String>  list = getTycgsqService().allowSubmit(ids,requestid);
            map.put("code",200);
            map.put("msg","success");
            map.put("data",list);
        }catch (Exception e){
            map.put("code",500);
            map.put("msg",e.getMessage());
        }
        return JSONObject.toJSONString(map);
    }
}
