// CLowSuctionDlg.cpp: 实现文件
|
//
|
|
|
#include "common/pch.h"
|
#include "CLowSuctionDlg.h"
|
#include "afxdialogex.h"
|
#include "../common/JsonUtil.h"
|
#include "../common/TimeUtil.h"
|
#include "resource.h"
|
#include "../common/LowSuctionNetworkApi.h"
|
#include <thread>
|
#include "SSHUtil.h"
|
|
// CLowSuctionDlg 对话框
|
IMPLEMENT_DYNAMIC(CLowSuctionDlg, CDialogEx)
|
|
CLowSuctionDlg::CLowSuctionDlg(CWnd* pParent /*=nullptr*/)
|
: CDialogEx(IDD_DIALOG_LOW_SUCTION, pParent)
|
{
|
|
}
|
|
CLowSuctionDlg::~CLowSuctionDlg()
|
{
|
}
|
|
void CLowSuctionDlg::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
DDX_Control(pDX, IDC_LIST2, placeOrderListCtrl);
|
DDX_Control(pDX, IDC_CHECK_BUY, checkBuy);
|
}
|
|
|
BEGIN_MESSAGE_MAP(CLowSuctionDlg, CDialogEx)
|
ON_BN_CLICKED(IDC_BUTTON_REFRESH, &CLowSuctionDlg::OnBnClickedButtonRefresh)
|
ON_BN_CLICKED(IDC_BUTTON_UPDATE_LEADING_LIMIT_UP, &CLowSuctionDlg::OnBnClickedButtonUpdateLeadingLimitUp)
|
ON_BN_CLICKED(IDC_CHECK_BUY, &CLowSuctionDlg::OnClickedCheckBuy)
|
ON_BN_CLICKED(IDC_BUTTON_UPDATE_CODE_JX_BLOCKS, &CLowSuctionDlg::OnBnClickedButtonUpdateCodeJxBlocks)
|
ON_BN_CLICKED(IDC_BUTTON_INIT_DATAS, &CLowSuctionDlg::OnBnClickedButtonInitDatas)
|
ON_BN_CLICKED(IDC_BUTTON_LOGS_PKG_AND_DOWNLOAD, &CLowSuctionDlg::OnBnClickedButtonLogsPKGAndDownload)
|
END_MESSAGE_MAP()
|
|
|
// CLowSuctionDlg 消息处理程序
|
|
|
void CLowSuctionDlg::requestEnvInfo(bool needHistoryData,CLowSuctionDlg* dlg)
|
{
|
auto result = LowSuctionNetworkApi::get_env(needHistoryData);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"].GetInt() != 0) {
|
return;
|
}
|
auto data = doc[L"data"].GetObjectW();
|
auto real_time_data = data[L"real_time_data"].GetObjectW();
|
auto history_data = data[L"history_data"].GetObjectW();
|
if (real_time_data.HasMember(L"kpl_current_limit_up")) {
|
CString st = L"";
|
st.Append(L"【");
|
auto kpl_current_limit_up = real_time_data[L"kpl_current_limit_up"].GetArray();
|
st.Append(kpl_current_limit_up[0].GetString());
|
st.Append(L"】");
|
st.Append(L"【");
|
st.Append(to_wstring( kpl_current_limit_up[1].GetInt()).c_str());
|
st.Append(L"】");
|
((CStatic*)dlg->GetDlgItem(IDC_STATIC_LIMIT_UP_INFO))->SetWindowTextW(st);
|
}
|
|
if (real_time_data.HasMember(L"block_in")) {
|
CString st = L"";
|
st.Append(L"【");
|
auto block_in = real_time_data[L"block_in"].GetArray();
|
st.Append(block_in[0].GetString());
|
st.Append(L"】");
|
st.Append(L"【");
|
st.Append(to_wstring(block_in[1].GetInt()).c_str());
|
st.Append(L"】");
|
((CStatic*)dlg->GetDlgItem(IDC_STATIC_BLOCK_IN_INFO))->SetWindowTextW(st);
|
}
|
|
if (real_time_data.HasMember(L"ticks")) {
|
CString st = L"";
|
st.Append(L"【");
|
auto ticks = real_time_data[L"ticks"].GetArray();
|
st.Append(ticks[0].GetString());
|
st.Append(L"】");
|
st.Append(L"【");
|
st.Append(to_wstring(ticks[1].GetInt()).c_str());
|
st.Append(L"】");
|
((CStatic*)dlg->GetDlgItem(IDC_STATIC_TICK_INFO))->SetWindowTextW(st);
|
}
|
|
if (real_time_data.HasMember(L"big_order_update_time")) {
|
CString st = L"";
|
st.Append(L"【");
|
auto big_order_update_time = real_time_data[L"big_order_update_time"].GetString();
|
st.Append(big_order_update_time);
|
st.Append(L"】");
|
((CStatic*)dlg->GetDlgItem(IDC_STATIC_BIG_ORDER_INFO))->SetWindowTextW(st);
|
}
|
|
|
if (history_data.HasMember(L"leading_limit_up_block_codes_count")) {
|
CString st = L"";
|
st.Append(L"【");
|
auto leading_limit_up_block_codes_count = history_data[L"leading_limit_up_block_codes_count"].GetInt();
|
st.Append(to_wstring(leading_limit_up_block_codes_count).c_str());
|
st.Append(L"】");
|
((CStatic*)dlg->GetDlgItem(IDC_STATIC_LEADING_LIMIT_UP_INFO))->SetWindowTextW(st);
|
}
|
|
if (history_data.HasMember(L"k_bars_count")) {
|
CString st = L"";
|
st.Append(L"【");
|
auto k_bars_count = history_data[L"k_bars_count"].GetInt();
|
st.Append(to_wstring(k_bars_count).c_str());
|
st.Append(L"】");
|
((CStatic*)dlg->GetDlgItem(IDC_STATIC_HISTORY_BARS_INFO))->SetWindowTextW(st);
|
}
|
|
if (history_data.HasMember(L"kpl_code_jx_blocks_count")) {
|
CString st = L"";
|
st.Append(L"【");
|
st.Append(to_wstring(history_data[L"kpl_code_jx_blocks_count"].GetInt()).c_str());
|
st.Append(L"】");
|
((CStatic*)dlg->GetDlgItem(IDC_STATIC_CODE_JX_PLATES_COUNT))->SetWindowTextW(st);
|
}
|
|
}
|
}
|
|
void CLowSuctionDlg::cycleRequestEnvInfo(CLowSuctionDlg* dlg)
|
{
|
while (TRUE) {
|
try {
|
dlg->requestEnvInfo(FALSE, dlg);
|
}
|
catch (...) {
|
|
}
|
|
Sleep(3000);
|
}
|
|
|
|
}
|
|
void CLowSuctionDlg::requestPlaceOrderRecords(CLowSuctionDlg* dlg)
|
{
|
auto result = LowSuctionNetworkApi::get_place_order_records();
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"].GetInt() == 0) {
|
list<PlaceOrderInfo> orderList;
|
auto orders = doc[L"data"].GetArray();
|
for (int i = 0;i < orders.Size();i++) {
|
auto item = orders[i][3].GetObjectW();
|
PlaceOrderInfo info;
|
info.code = item[L"code"].GetString();
|
info.time = item[L"time_str"].GetString();
|
info.price = item[L"price"].GetFloat();
|
info.rate = item[L"rate"].GetFloat();
|
auto plates_info = item[L"plates_info"].GetObjectW();
|
auto plates = item[L"plates"].GetArray();
|
CString plates_str = L"";
|
for (int j = 0;j < plates.Size();j++) {
|
plates_str.Append(plates[j].GetString());
|
if (j != plates.Size() - 1) {
|
plates_str.Append(L"、");
|
}
|
}
|
info.plates = plates_str;
|
orderList.push_back(info);
|
}
|
|
// 如果数据无改变才需要更新数据
|
if (dlg->placeOrderRecordList.size() != orderList.size()) {
|
dlg->placeOrderRecordList = orderList;
|
dlg->placeOrderListCtrl.SetRedraw(false);
|
dlg->placeOrderListCtrl.DeleteAllItems();
|
|
int index = 0;
|
for (list<PlaceOrderInfo>::iterator el = orderList.begin(); el != orderList.end(); ++el) {
|
PlaceOrderInfo r = *el;
|
dlg->placeOrderListCtrl.InsertItem(index, L"");
|
dlg->placeOrderListCtrl.SetItemText(index, 0, r.time);
|
dlg->placeOrderListCtrl.SetItemText(index, 1, r.code);
|
dlg->placeOrderListCtrl.SetItemText(index, 2, CString(StringUtil::to_string(r.price).c_str()));
|
auto rate = CString(StringUtil::to_string(r.rate).c_str());
|
rate.Append(L"%");
|
dlg->placeOrderListCtrl.SetItemText(index, 3, rate);
|
dlg->placeOrderListCtrl.SetItemText(index, 4, r.plates);
|
dlg->placeOrderListCtrl.SetItemText(index, 5, r.plates_info);
|
index++;
|
}
|
dlg->placeOrderListCtrl.SetRedraw(true);
|
}
|
}
|
}
|
}
|
|
void CLowSuctionDlg::cycleRequestPlaceOrderRecords(CLowSuctionDlg* dlg)
|
{
|
while (TRUE) {
|
try {
|
dlg->requestPlaceOrderRecords(dlg);
|
}
|
catch (...) {
|
|
}
|
|
Sleep(3000);
|
}
|
}
|
|
void CLowSuctionDlg::OnBnClickedButtonRefresh()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
//LowSuctionNetworkApi::test_cancel_order("000323");
|
this->requestEnvInfo(TRUE, this);
|
}
|
|
|
void CLowSuctionDlg::OnBnClickedButtonUpdateLeadingLimitUp()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
auto result = LowSuctionNetworkApi::update_leading_limit_up_datas();
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"].GetInt() != 0) {
|
AfxMessageBox(doc[L"msg"].GetString());
|
return;
|
}
|
MessageBox(L"更新成功", L"提示");
|
}
|
else {
|
AfxMessageBox(L"网络请求出错");
|
}
|
}
|
|
|
void CLowSuctionDlg::OnClickedCheckBuy()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
}
|
|
|
void CLowSuctionDlg::OnBnClickedButtonUpdateCodeJxBlocks()
|
{
|
auto result = LowSuctionNetworkApi::update_leading_limit_up_datas();
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"].GetInt() != 0) {
|
AfxMessageBox(doc[L"msg"].GetString());
|
return;
|
}
|
MessageBox(L"更新成功", L"提示");
|
}
|
else {
|
AfxMessageBox(L"网络请求出错");
|
}
|
}
|
|
|
void CLowSuctionDlg::OnBnClickedButtonInitDatas()
|
{
|
auto result = LowSuctionNetworkApi::init_datas();
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"].GetInt() != 0) {
|
AfxMessageBox(doc[L"msg"].GetString());
|
return;
|
}
|
MessageBox(L"初始化成功", L"提示");
|
}
|
else {
|
AfxMessageBox(L"网络请求出错");
|
}
|
}
|
|
void CLowSuctionDlg::OnBnClickedButtonLogsPKGAndDownload()
|
{
|
CString ip, port, username, pwd, date, cmd, output;
|
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_IP))->GetWindowTextW(ip);
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_PORT))->GetWindowTextW(port);
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_USERNAME))->GetWindowTextW(username);
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_PWD))->GetWindowTextW(pwd);
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_DATE))->GetWindowTextW(date);
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_PKG_CMD))->GetWindowTextW(cmd);
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_PKG_OUTPUT))->GetWindowTextW(output);
|
|
try {
|
if (!StringUtil::isNumber(StringUtil::cstring2String( port))){
|
throw string("端口输出错误");
|
}
|
|
CFolderPickerDialog dlg;
|
dlg.m_ofn.lpstrTitle = _T("请选择下载路径"); // 设置对话框标题
|
|
// 显示对话框并检查用户是否点击"确定"
|
if (dlg.DoModal() == IDOK)
|
{
|
CString strFolderPath = dlg.GetFolderPath(); // 获取选择的文件夹路径
|
|
SSHServer server({ StringUtil::cstring2String(ip), _ttoi(port),StringUtil::cstring2String(username) ,StringUtil::cstring2String(pwd) });
|
SSHUtil::excuteCmd(StringUtil::cstring2String(cmd), server);
|
string remotePath = StringUtil::cstring2String(output);
|
string localPath = string(StringUtil::cstring2String(strFolderPath)).append("/").append(StringUtil::cstring2String(date)).append(".tar.gz");
|
SSHUtil::downloadFile(remotePath, localPath, server);
|
MessageBox(L"下载成功", L"提示");
|
}
|
}
|
catch (string msg) {
|
AfxMessageBox(CString(msg.c_str()));
|
}
|
|
}
|
|
|
BOOL CLowSuctionDlg::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
//初始化列表
|
placeOrderListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
|
CRect rect;
|
placeOrderListCtrl.GetClientRect(&rect);
|
|
int unitSize = (rect.Width() - 20) / 6.4f;
|
placeOrderListCtrl.InsertColumn(0, _T("下单时间"), LVCFMT_LEFT, unitSize * 1, 0);
|
placeOrderListCtrl.InsertColumn(1, _T("代码"), LVCFMT_LEFT, unitSize * 1, 1);
|
placeOrderListCtrl.InsertColumn(2, _T("成本价"), LVCFMT_LEFT, unitSize * 1, 2);
|
placeOrderListCtrl.InsertColumn(3, _T("成本涨幅"), LVCFMT_LEFT, unitSize * 1, 3);
|
placeOrderListCtrl.InsertColumn(4, _T("板块"), LVCFMT_LEFT, unitSize * 1.4, 4);
|
placeOrderListCtrl.InsertColumn(5, _T("板块详情"), LVCFMT_LEFT, rect.Width(), 5);
|
//======日志导出模块======
|
|
string nowDay = TimeUtil::getNowDate();
|
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_PWD))->SetPasswordChar('*');
|
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_IP))->SetWindowTextW(L"192.168.84.126");
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_PORT))->SetWindowTextW(L"22");
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_USERNAME))->SetWindowTextW(L"root");
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_PWD))->SetWindowTextW(L"Yeshi2016@");
|
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_DATE))->SetWindowTextW(CString(nowDay.c_str()));
|
|
string cmd = "cd /home/userzjj";
|
cmd.append(" && ").append("./copy_ls_data.sh ").append(nowDay);
|
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_PKG_CMD))->SetWindowTextW(CString(cmd.c_str()));
|
|
cmd = "/home/userzjj/export/";
|
cmd.append(nowDay).append(".tar.gz");
|
((CEdit*)GetDlgItem(IDC_EDIT_LOGS_PKG_OUTPUT))->SetWindowTextW(CString(cmd.c_str()));
|
|
|
std::thread(cycleRequestEnvInfo, this).detach();
|
std::thread(cycleRequestPlaceOrderRecords, this).detach();
|
return TRUE; // return TRUE unless you set the focus to a control
|
// 异常: OCX 属性页应返回 FALSE
|
}
|