SyncController.java 10.7 KB
Newer Older
412743165@qq.com committed
1 2
package com.jarvis.dataCenter.controller;

3 4 5 6
import com.jarvis.dataCenter.config.OpenReplicatorCofig;
import com.jarvis.dataCenter.enums.SyncEnum;
import com.jarvis.dataCenter.runner.OpenReplicatorRunner;
import com.jarvis.dataCenter.service.impl.report.ThreadServiceImpl;
412743165@qq.com committed
7 8 9 10 11 12
import com.jarvis.lib.common.base.message.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
13
import org.springframework.web.bind.annotation.RequestParam;
412743165@qq.com committed
14 15 16 17 18 19 20 21 22 23 24 25
import org.springframework.web.bind.annotation.RestController;


/**
 * @author jinzhaopo
 * @date 2019-10-21 14:48
 */
@RestController
@Slf4j
@Api("SYNC")
public class SyncController {

26 27
    @Autowired
    private ThreadServiceImpl threadserviceImpl;
412743165@qq.com committed
28

29 30
    @Autowired
    private OpenReplicatorRunner openReplicatorRunner;
412743165@qq.com committed
31

32 33
    @Autowired
    private OpenReplicatorCofig openReplicatorCofig;
412743165@qq.com committed
34 35 36


    /**
37
     * 查询控制同步的状态
412743165@qq.com committed
38
     *
39
     * @param syncEnum
412743165@qq.com committed
40 41
     * @return
     */
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    @ApiOperation("获取状态信息")
    @GetMapping("/getSyncBol")
    public Message<String> getSyncBol(SyncEnum syncEnum) {
        Boolean status = null;
        if (syncEnum == SyncEnum.REPORT_SKU) {
            status = ThreadServiceImpl.syncSku;
        } else if (syncEnum == SyncEnum.REPORT_ADDRESS) {
            status = ThreadServiceImpl.syncAddress;
        } else if (syncEnum == SyncEnum.REPORT_AGENCY) {
            status = ThreadServiceImpl.syncAgency;
        } else if (syncEnum == SyncEnum.REPORT_CS) {
            status = ThreadServiceImpl.syncCsInfo;
        } else if (syncEnum == SyncEnum.REPORT_DO) {
            status = ThreadServiceImpl.sycnDoInfo;
        } else if (syncEnum == SyncEnum.REPORT_INVOICE) {
            status = ThreadServiceImpl.syncInvoiceInfo;
        } else if (syncEnum == SyncEnum.REPORT_SO) {
            status = ThreadServiceImpl.syncSoInfo;
        }
412743165@qq.com committed
61

62
        return Message.success(status + "");
412743165@qq.com committed
63 64 65
    }

    /**
66 67
     * @param syncEnum
     * @param status
412743165@qq.com committed
68 69
     * @return
     */
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    @ApiOperation("设置状态信息")
    @GetMapping("/setSyncBol")
    public Message<String> setSyncBol(SyncEnum syncEnum, @RequestParam boolean status) {
        if (syncEnum == SyncEnum.REPORT_SKU) {
            ThreadServiceImpl.syncSku = status;
        } else if (syncEnum == SyncEnum.REPORT_ADDRESS) {
            ThreadServiceImpl.syncAddress = status;
        } else if (syncEnum == SyncEnum.REPORT_AGENCY) {
            ThreadServiceImpl.syncAgency = status;
        } else if (syncEnum == SyncEnum.REPORT_CS) {
            ThreadServiceImpl.syncCsInfo = status;
        } else if (syncEnum == SyncEnum.REPORT_DO) {
            ThreadServiceImpl.sycnDoInfo = status;
        } else if (syncEnum == SyncEnum.REPORT_INVOICE) {
            ThreadServiceImpl.syncInvoiceInfo = status;
        } else if (syncEnum == SyncEnum.REPORT_SO) {
            ThreadServiceImpl.syncSoInfo = status;
        }
412743165@qq.com committed
88

89 90 91 92 93 94 95 96 97 98 99
        return Message.success(status + "");
    }


    /**
     * @param syncEnum
     * @return
     */
    @ApiOperation("获取线程的状态")
    @GetMapping("/getThreadIsAlive")
    public Message<String> getThreadIsAlive(SyncEnum syncEnum) {
412743165@qq.com committed
100

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
        boolean alive = false;
        if (syncEnum == SyncEnum.REPORT_SKU) {
            alive = threadserviceImpl.getSyncSkuThread().isAlive();
        } else if (syncEnum == SyncEnum.REPORT_ADDRESS) {
            alive = threadserviceImpl.getSyncAddressThread().isAlive();
        } else if (syncEnum == SyncEnum.REPORT_AGENCY) {
            alive = threadserviceImpl.getSyncAgencyThread().isAlive();
        } else if (syncEnum == SyncEnum.REPORT_CS) {
            alive = threadserviceImpl.getSyncCsInfoThread().isAlive();
        } else if (syncEnum == SyncEnum.REPORT_DO) {
            alive = threadserviceImpl.getSycnDoInfoThread().isAlive();
        } else if (syncEnum == SyncEnum.REPORT_INVOICE) {
            alive = threadserviceImpl.getSyncInvoiceInfoThread().isAlive();
        } else if (syncEnum == SyncEnum.REPORT_SO) {
            alive = threadserviceImpl.getSyncSoInfoThread().isAlive();

        }

        return Message.success(alive + "");
412743165@qq.com committed
120 121
    }

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    /**
     * 获取线程的睡眠时间
     *
     * @param syncEnum
     * @return
     */
    @ApiOperation("获取线程的睡眠时间")
    @GetMapping("/getSleepTime")
    public Message<String> getSleepTime(SyncEnum syncEnum) {
        long time = 0;
        if (syncEnum == SyncEnum.REPORT_SKU) {
            time = ThreadServiceImpl.sleepSku;
        } else if (syncEnum == SyncEnum.REPORT_ADDRESS) {
            time = ThreadServiceImpl.sleepAddress;
        } else if (syncEnum == SyncEnum.REPORT_AGENCY) {
            time = ThreadServiceImpl.sleepAgency;
        } else if (syncEnum == SyncEnum.REPORT_CS) {
            time = ThreadServiceImpl.sleepCsInfo;
        } else if (syncEnum == SyncEnum.REPORT_DO) {
            time = ThreadServiceImpl.sleepDoInfo;
        } else if (syncEnum == SyncEnum.REPORT_INVOICE) {
            time = ThreadServiceImpl.sleepInvoiceInfo;
        } else if (syncEnum == SyncEnum.REPORT_SO) {
            time = ThreadServiceImpl.sleepSoInfo;
412743165@qq.com committed
146

147 148 149
        }
        return Message.success(time + "");
    }
412743165@qq.com committed
150

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
    /**
     * 设置线程的睡眠时间
     *
     * @param syncEnum
     * @param time
     * @return
     */
    @ApiOperation("设置线程的睡眠时间")
    @GetMapping("/setSleepTime")
    public Message<String> getSleepTime(SyncEnum syncEnum, @RequestParam long time) {
        if (syncEnum == SyncEnum.REPORT_SKU) {
            ThreadServiceImpl.sleepSku = time;
        } else if (syncEnum == SyncEnum.REPORT_ADDRESS) {
            ThreadServiceImpl.sleepAddress = time;
        } else if (syncEnum == SyncEnum.REPORT_AGENCY) {
            ThreadServiceImpl.sleepAgency = time;
        } else if (syncEnum == SyncEnum.REPORT_CS) {
            ThreadServiceImpl.sleepCsInfo = time;
        } else if (syncEnum == SyncEnum.REPORT_DO) {
            ThreadServiceImpl.sleepDoInfo = time;
        } else if (syncEnum == SyncEnum.REPORT_INVOICE) {
            ThreadServiceImpl.sleepInvoiceInfo = time;
        } else if (syncEnum == SyncEnum.REPORT_SO) {
            ThreadServiceImpl.sleepSoInfo = time;

        }
        return Message.success(time + "");
    }


    /**
     * @param syncEnum
     * @return
     */
    @ApiOperation("停止线程")
    @GetMapping("/stopThread")
    public Message<String> stopThread(SyncEnum syncEnum) {
        if (syncEnum == SyncEnum.REPORT_SKU) {
            boolean alive = threadserviceImpl.getSyncSkuThread().isAlive();
            if (alive) {
                threadserviceImpl.getSyncSkuThread().interrupt();
            }
        } else if (syncEnum == SyncEnum.REPORT_ADDRESS) {
            boolean alive = threadserviceImpl.getSyncAddressThread().isAlive();
            if (alive) {
                threadserviceImpl.getSyncAddressThread().interrupt();
            }
        } else if (syncEnum == SyncEnum.REPORT_AGENCY) {
            boolean alive = threadserviceImpl.getSyncAddressThread().isAlive();
            if (alive) {
                threadserviceImpl.getSyncAddressThread().interrupt();
            }
        } else if (syncEnum == SyncEnum.REPORT_CS) {
            boolean alive = threadserviceImpl.getSyncCsInfoThread().isAlive();
            if (alive) {
                threadserviceImpl.getSyncCsInfoThread().interrupt();
            }
        } else if (syncEnum == SyncEnum.REPORT_DO) {
            boolean alive = threadserviceImpl.getSycnDoInfoThread().isAlive();
            if (alive) {
                threadserviceImpl.getSycnDoInfoThread().interrupt();
            }
        } else if (syncEnum == SyncEnum.REPORT_INVOICE) {
            boolean alive = threadserviceImpl.getSyncInvoiceInfoThread().isAlive();
            if (alive) {
                threadserviceImpl.getSyncInvoiceInfoThread().interrupt();
            }
        } else if (syncEnum == SyncEnum.REPORT_SO) {
            boolean alive = threadserviceImpl.getSyncSoInfoThread().isAlive();
            if (alive) {
                threadserviceImpl.getSyncSoInfoThread().interrupt();
            }
        }
412743165@qq.com committed
224 225 226
        return Message.success(null);
    }

227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
    /**
     * @param syncEnum
     * @return
     */
    @ApiOperation("启动线程")
    @GetMapping("/startThread")
    public Message<String> startThread(SyncEnum syncEnum) {
        if (syncEnum == SyncEnum.REPORT_SKU) {
            boolean alive = threadserviceImpl.getSyncSkuThread().isAlive();
            if (!alive) {
                threadserviceImpl.getSyncSkuThread().start();
            }
        } else if (syncEnum == SyncEnum.REPORT_ADDRESS) {
            boolean alive = threadserviceImpl.getSyncAddressThread().isAlive();
            if (!alive) {
                threadserviceImpl.getSyncAddressThread().start();
            }
        } else if (syncEnum == SyncEnum.REPORT_AGENCY) {
            boolean alive = threadserviceImpl.getSyncAddressThread().isAlive();
            if (!alive) {
                threadserviceImpl.getSyncAgencyThread().start();
            }
        } else if (syncEnum == SyncEnum.REPORT_CS) {
            boolean alive = threadserviceImpl.getSyncCsInfoThread().isAlive();
            if (!alive) {
                threadserviceImpl.getSyncCsInfoThread().start();
            }
        } else if (syncEnum == SyncEnum.REPORT_DO) {
            boolean alive = threadserviceImpl.getSycnDoInfoThread().isAlive();
            if (!alive) {
                threadserviceImpl.getSycnDoInfoThread().start();
            }
        } else if (syncEnum == SyncEnum.REPORT_INVOICE) {
            boolean alive = threadserviceImpl.getSyncInvoiceInfoThread().isAlive();
            if (!alive) {
                threadserviceImpl.getSyncInvoiceInfoThread().start();
            }
        } else if (syncEnum == SyncEnum.REPORT_SO) {
            boolean alive = threadserviceImpl.getSyncSoInfoThread().isAlive();
            if (!alive) {
                threadserviceImpl.getSyncSoInfoThread().start();
            }
        }
        return Message.success(null);
    }
412743165@qq.com committed
272

273 274 275 276 277 278 279
    @GetMapping("/startOpenRe")
    @ApiOperation("启动监控")
    public Message<String> startOpenReplicator(Long binlogPosition) {
        openReplicatorRunner.initOpenReplicator();
        if (binlogPosition != null) {
            openReplicatorRunner.getOpenReplicator().setBinlogPosition(binlogPosition);
        }
412743165@qq.com committed
280

281 282 283
        openReplicatorRunner.start();
        return Message.success(true + "");
    }
412743165@qq.com committed
284

285 286 287 288 289 290 291 292 293
    @GetMapping("/stopOpenReplicator")
    @ApiOperation("停止监控")
    public Message<String> stopOpenReplicator() {
        try {
            openReplicatorRunner.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Message.success(true + "");
412743165@qq.com committed
294 295
    }

296

412743165@qq.com committed
297
}