package com.engine.htsc.jgzxzysx.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.jgzxzysx.service.JgzxzysxService;
import com.engine.htsc.jgzxzysx.service.impl.JgzxzysxServiceImp;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
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.Set;
import java.util.stream.Collectors;

/**
 * @author K1810015
 * @version 1.0.0
 * @ClassName JgzxzysxAction.java
 * @createTime 2022年05月11日 13:47:00
 */
public class JgzxzysxAction {



    private JgzxzysxService jgzxzysxService= ServiceUtil.getService(JgzxzysxServiceImp.class);

    @POST
    @Path("/getdonewkconfidential")
    @Produces({MediaType.TEXT_PLAIN})
    public String getdonewkconfidential(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        JAVATools.SetCmdwritelog("-------------JgzxzysxAction.getdonewkconfidential-------------");
        User user = HrmUserVarify.getUser(request, response);
        try {
            boolean flag = jgzxzysxService.donewkconfidential(user, ParamUtil.request2Map(request));
            return JAVATools.Apiretrun("200", flag);
        } catch (Exception e) {
            return JAVATools.Apiretrun("400", "error");
        }
    }

    @POST
    @Path("/getdwkonetosuer")
    @Produces({MediaType.TEXT_PLAIN})
    public String getwkdonetosuer(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        JAVATools.SetCmdwritelog("-------------JgzxzysxAction.getdonewkconfidential-------------");
        User user = HrmUserVarify.getUser(request, response);

        try{
            Set<String> set=jgzxzysxService.getwkdonetosuer(user, ParamUtil.request2Map(request));
            if(set==null || set.size()<=0){
                return JAVATools.Apiretrun("200","");
            }
            return JAVATools.Apiretrun("200",set.stream().collect(Collectors.joining(",")));
        }catch (Exception e){
            return JAVATools.Apiretrun("400","error");
        }
    }


    @POST
    @Path("/getDataRange")
    @Produces({MediaType.TEXT_PLAIN})
    public String getDataRange(@Context HttpServletRequest request, @Context HttpServletResponse response){
            JAVATools.SetCmdwritelog("-------------JgzxzysxAction.getDataRange-------------");
        User user = HrmUserVarify.getUser(request, response);
        try{
            JSONObject jsonObject=jgzxzysxService.getDataRange(user, ParamUtil.request2Map(request));
            return JAVATools.Apiretrun("200",jsonObject);
        }catch (Exception e){
            return JAVATools.Apiretrun("400","error");
        }
    }



    @POST
    @Path("/getnumber")
    @Produces({MediaType.TEXT_PLAIN})
    public String getnumber(@Context HttpServletRequest request, @Context HttpServletResponse response){
        JAVATools.SetCmdwritelog("-------------JgzxzysxAction.getnumber-------------");
        User user = HrmUserVarify.getUser(request, response);
        try{
            String value=jgzxzysxService.getnumber(user, ParamUtil.request2Map(request));
            return JAVATools.Apiretrun("200",value);
        }catch (Exception e){
            return JAVATools.Apiretrun("400","error");
        }
    }

    @POST
    @Path("/getleaderallname")
    @Produces({MediaType.TEXT_PLAIN})
    public String getleaderallname(@Context HttpServletRequest request, @Context HttpServletResponse response){
        JAVATools.SetCmdwritelog("-------------JgzxzysxAction.getfreenodeadmin-------------");
        User user = HrmUserVarify.getUser(request, response);
        try{
            JSONObject value=jgzxzysxService.getleaderallname(user, ParamUtil.request2Map(request));
            return JAVATools.Apiretrun("200",value);
        }catch (Exception e){
            return JAVATools.Apiretrun("400","error");
        }
    }
    @POST
    @Path("/getleadercflag")
    @Produces({MediaType.TEXT_PLAIN})
    public String getleadercflag(@Context HttpServletRequest request, @Context HttpServletResponse response){
        JAVATools.SetCmdwritelog("-------------JgzxzysxAction.getnumber-------------");
        User user = HrmUserVarify.getUser(request, response);
        try{
            Boolean value=jgzxzysxService.getleadercflag(user, ParamUtil.request2Map(request));
            return JAVATools.Apiretrun("200",value);
        }catch (Exception e){
            return JAVATools.Apiretrun("400","error");
        }
    }

}
