kimi
2020-05-27 c007f0ca1785db093d48f4846cda82fe8e955765
src/main/java/com/highdatas/mdm/job/JobClient.java
@@ -41,6 +41,12 @@
    private JobClient() {
        this.prefix = "/xxl-job-admin/";
    }
    /**
     *
     * @description: xxljob 登录接口
     * @return 具体数据
     *
     */
    public  boolean login() {
        String url = this.url + prefix + "login";
        Map<String, String> params = new LinkedHashMap<>();
@@ -56,6 +62,12 @@
        return  success;
    }
    /**
     *
     * @description: xxljob 参数转换
     * @return 是否请求成功
     *
     */
    private boolean parse(JSONObject result) {
        boolean success = true;
        Integer code = result.getInteger(Constant.Code);
@@ -67,7 +79,12 @@
        return success;
    }
    /**
     *
     * @description: xxljob 保存jobGroup
     * @return 是否请求成功
     *
     */
    public boolean saveJobGroup() {
        try {
            String url =  this.url + prefix + "xxlcustapi/saveJobGroup";
@@ -97,7 +114,47 @@
        }
    }
    /**
     *
     * @description: xxljob 保存自动获取ip的jobgroup
     * @return 是否请求成功
     *
     */
    public boolean saveAutoJobGroup() {
        try {
            String url =  this.url + prefix + "xxlcustapi/saveJobGroup";
            Map<String, String> params = new LinkedHashMap<>();
            params.put("appName","MDMApp");
            params.put("order", "1");
            params.put("title","数据汇集定时任务执行器");
            params.put("modelId","MDM");
            params.put("addressType","0");
//            params.put("addressList",local);
            String s = null;
            Map<String, Object> paramMap = new HashMap<>();
            paramMap.putAll(params);
            String urlParamsByMap = HttpUtils.getUrlParamsByMap(paramMap);
            s = HttpRestClient(url, HttpMethod.POST, null, urlParamsByMap, MediaType.APPLICATION_JSON);
            JSONObject result = (JSONObject) JSON.parse(s);
            boolean success = parse(result);
            if (!success){
                log.error("请求saveJobGroup失败:" + result.getString("msg"));
            }
            return success;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
    /**
     *
     * @description: xxljob 删除自动获取ip的jobgroup
     * @return 是否请求成功
     *
     */
    public boolean removeJobGroup() {
        try {
            String url =  this.url + prefix + "xxlcustapi/saveJobGroup";
@@ -120,7 +177,13 @@
    }
    /**
     *
     * @description: xxljob 添加一个job
     * @param  assemble 汇集任务
     * @return 是否请求成功
     *
     */
    public boolean addJob(SysAssemble assemble) {
        try {
            String jobId = createJobId(assemble.getId());
@@ -135,11 +198,11 @@
            params.put("cronGen_display",assemble.getCron());
            params.put("executorBlockStrategy","DISCARD_LATER");
            params.put("executorTimeout","0");
            params.put("executorFailRetryCount","3");
            params.put("executorFailRetryCount","0");
            params.put("triggerStatus","1");
            params.put("glueType","BEAN");
            params.put("executorRouteStrategy","FIRST");
            params.put("jobDesc","创建汇集job");
            params.put("jobDesc","创建汇集job" + jobId);
            Map<String, Object> paramMap = new HashMap<>();
            paramMap.putAll(params);
            String urlParamsByMap = HttpUtils.getUrlParamsByMap(paramMap);
@@ -159,22 +222,34 @@
        }
    }
    /**
     *
     * @description: xxljob 创建job id
     * @return 是否请求成功
     *
     */
    private String createJobId(String id) {
        if (StringUtils.isEmpty(id)) {
            id = DbUtils.getUUID();
        }
        try {
            String jobId  = "MDM-" + DbUtils.Bit16(id);
            String jobId  = "MDM-" + id;
            return jobId;
        } catch (Exception e) {
            e.printStackTrace();
            return id;
        }
    }
    /**
     *
     * @description: xxljob 更新job
     * @param assemble huiji renwu
     * @return 是否请求成功
     *
     */
    public boolean updateJob(SysAssemble assemble) {
        try {
            String jobId = createJobId(assemble.getId());
            String url =  this.url + prefix + "xxlcustapi/updateJob";
            Map<String, String> params = new LinkedHashMap<>();
            params.put("modelId","MDM");
@@ -190,7 +265,7 @@
            params.put("triggerStatus","1");
            params.put("glueType","BEAN");
            params.put("executorRouteStrategy","FIRST");
            params.put("jobDesc","更新汇集job");
            params.put("jobDesc","更新汇集job" + jobId);
            Map<String, Object> paramMap = new HashMap<>();
            paramMap.putAll(params);
            String urlParamsByMap = HttpUtils.getUrlParamsByMap(paramMap);
@@ -208,7 +283,13 @@
        }
    }
    /**
     *
     * @description: xxljob 删除job
     * @param  jobId job ID
     * @return 是否请求成功
     *
     */
    public boolean deleteJob(String jobId) {
        try {
@@ -263,6 +344,12 @@
    }
    /**
     *
     * @description: xxljob 触发一次
     * @return 是否请求成功
     *
     */
    public boolean trigger(SysAssemble assemble) {
        if (StringUtils.isEmpty(assemble.getJobId())) {
            return false;
@@ -292,7 +379,12 @@
    }
    /**
     *
     * @description: xxljob 使用的http请求工具方法
     * @return 是否请求成功
     *
     */
    private  String     HttpRestClient(String url, HttpMethod method, Map<String, String> formParams, String getParams,  MediaType mediaType) {
        if (!StringUtils.isEmpty(getParams)) {
            url = url + Constant.QUESTION + getParams;