package com.fangxuele.tool.push.logic;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.fangxuele.tool.push.ui.form.PushForm;
import me.chanjar.weixin.mp.api.WxMpService;

import javax.swing.table.DefaultTableModel;
import java.util.List;

/**
 * <pre>
 * 消息发送服务线程父类
 * </pre>
 *
 * @author <a href="https://github.com/rememberber">RememBerBer</a>
 * @since 2017/3/29.
 */
public class BaseMsgServiceThread extends Thread {

    public static final Log logger = LogFactory.get();

    /**
     * 起始索引
     */
    private int startIndex;

    /**
     * 截止索引
     */
    private int endIndex;

    /**
     * 页大小
     */
    private int pageSize;

    /**
     * 当前线程要发送的list
     */
    public List<String[]> list;

    /**
     * 微信工具服务
     */
    WxMpService wxMpService;

    /**
     * 当前线程成功数
     */
    int currentThreadSuccessCount;

    /**
     * 当前线程失败数
     */
    int currentThreadFailCount;

    /**
     * 线程列表tableModel
     */
    public DefaultTableModel tableModel;

    /**
     * 当前线程所在的线程列表行
     */
    int tableRow;

    /**
     * 构造函数
     *
     * @param start 起始页
     * @param end   截止页
     */
    public BaseMsgServiceThread(int start, int end) {
        this.startIndex = start;
        this.endIndex = end;
    }

    @Override
    public void run() {

    }

    /**
     * 初始化当前线程
     */
    void initCurrentThread() {
        PushManage.console("线程" + this.getName() + "负责处理:" + startIndex + "-" +
                endIndex + "的分片数据");

        list = PushData.toSendList.subList(startIndex, endIndex);

        // 初始化线程列表行
        tableModel = (DefaultTableModel) PushForm.pushForm.getPushThreadTable().getModel();
        currentThreadSuccessCount = 0;
        currentThreadFailCount = 0;
        tableModel.setValueAt(currentThreadSuccessCount, tableRow, 2);
        tableModel.setValueAt(currentThreadFailCount, tableRow, 3);
        tableModel.setValueAt(list.size(), tableRow, 4);
        tableModel.setValueAt(0, tableRow, 5);
    }

    /**
     * 当前线程结束
     */
    void currentThreadFinish() {
        PushManage.console(this.getName() + "已处理完第" + startIndex + "-" +
                endIndex + "页的数据");

        PushData.increaseStopedThread();
    }

    public WxMpService getWxMpService() {
        return wxMpService;
    }

    void setWxMpService(WxMpService wxMpService) {
        this.wxMpService = wxMpService;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getEndIndex() {
        return endIndex;
    }

    public void setEndIndex(int endIndex) {
        this.endIndex = endIndex;
    }

    public int getTableRow() {
        return tableRow;
    }

    void setTableRow(int tableRow) {
        this.tableRow = tableRow;
    }
}

@@ -1427,16 +1427,17 @@
  + %22%E8%B4%9F%E8%B4%A3%E5%A4%84%E7%90%86
+%E7%AC%AC
 :%22 + sta
@@ -1484,11 +1484,10 @@
  + %22
+%E6%9D%A1
 %E7%9A%84
-%E5%88%86%E7%89%87
 %E6%95%B0%E6%8D%AE%22)
@@ -2157,17 +2157,17 @@
 ndex + %22
-%E9%A1%B5
+%E6%9D%A1
 %E7%9A%84%E6%95%B0%E6%8D%AE%22);%0A%0A

fix log text words