e2lc5's blog

e2lc5's blog

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

static class MySqlC {
AtomicBoolean free = new AtomicBoolean(true);
private SqlSession session;
private BbItemInfoMapper mapper;

public MySqlC(SqlSession session) {
this.session = session;
this.mapper = session.getMapper(BbItemInfoMapper.class);
}
}

private final ArrayList<MySqlC> connectionLists = new ArrayList<>();

private MySqlC getFreeConnection() {
for (MySqlC connectionList : connectionLists) {
if (connectionList.free.get()) {
return connectionList;
}
}
return null;
}

public void importPlu(String filePath, Long batchId) {
try {
File file = new File(filePath);
CsvReader reader = CsvUtil.getReader();
//设置文件读取的分隔符
reader.setFieldSeparator('|');
String charSet = FileUtils.getCharSet(new BufferedInputStream(new FileInputStream(file)));
//根据特定的编码方式读取File的内容
CsvData data = reader.read(file, Charset.forName(charSet));
if (data == null) {
log.error("read csvData got null");
return;
}
ArrayList<BbItemInfo> nInfoList = new ArrayList<>();
int insertCount = 0;
CsvRow firstRow;
String storeNum = "";
int batchCount = 0;
CountDownLatch countDownLatch = new CountDownLatch(data.getRowCount());

connectionLists.add(new MySqlC(sqlSessionFactory.openSession(ExecutorType.BATCH, false)));
connectionLists.add(new MySqlC(sqlSessionFactory.openSession(ExecutorType.BATCH, false)));
connectionLists.add(new MySqlC(sqlSessionFactory.openSession(ExecutorType.BATCH, false)));
connectionLists.add(new MySqlC(sqlSessionFactory.openSession(ExecutorType.BATCH, false)));

// SqlSession sqlsession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
// BbItemInfoMapper bbItemInfoMapper = sqlsession.getMapper(BbItemInfoMapper.class);

for (int i = 0; i < data.getRowCount(); i++) {
if (i == 0) {
firstRow = data.getRow(i);
log.debug(JSON.toJSONString(firstRow));
storeNum = firstRow.get(6);
countDownLatch.countDown();
} else {
CsvRow row = data.getRow(i);
if (row == null) {
log.warn("line 0 is null ");
} else {
log.debug(JSON.toJSONString(row));
BbItemInfo info = new BbItemInfo();
info.setPlu_btch_nbr(row.get(0));
info.setItm_id(StringUtils.parseStr2Int(row.get(2)));
info.setStr_hier_id(StringUtils.parseStr2Int(row.get(3)));
info.setDspl_descr(row.get(6));
info.setRcpt_descr(row.get(8));
info.setTaxability_cd(row.get(9));
info.setSls_auth_fg(row.get(19));
info.setRtl_prc(row.get(23));
info.setTax_rate1_fg(row.get(47));
info.setTax_rate3_fg(row.get(48));
info.setTax_rate4_fg(row.get(49));
info.setTax_rate5_fg(row.get(50));
info.setTax_rate6_fg(row.get(51));
info.setTax_rate7_fg(row.get(52));
info.setTax_rate8_fg(row.get(53));
info.setSubdep_id(StringUtils.parseStr2Int(row.get(61)));
info.setRcpt_descr1(row.get(78));
info.setRcpt_descr2(row.get(79));
info.setRcpt_descr3(row.get(80));
info.setIntrnl_id(StringUtils.parseStr2Int(row.get(85)));
info.setBns_by_descr(row.get(108));
info.setComp_prc(row.get(110));
info.setVnd_itm_id2(row.get(137));
info.setBatch_id(batchId);
info.setStatus_id(0);
info.setAdd_time(new Date());
info.setOp_code(StringUtils.parseStr2Int(row.get(1)));
info.setStore_num(storeNum);
batchCount++;
nInfoList.add(info);
}
}
if (batchCount > 999) {
long startSave = System.currentTimeMillis();

int finalBatchCount = batchCount;
final ArrayList<BbItemInfo> insertList = nInfoList;
PriorityThreadFactory.getPool().execute(new PriorityThread() {
@Override
public void run() {
MySqlC c;
while ((c = getFreeConnection()) != null) {
c.free.set(false);
commit(insertList, c.session, c.mapper);
c.free.set(true);
for (int j = 0; j < finalBatchCount; j++) {
countDownLatch.countDown();
}
break;
}
}

@Override
public String getThreadName() {
return "t" + System.currentTimeMillis();
}
});

log.info("保存耗费 :" + (System.currentTimeMillis() - startSave) + "ms");
insertCount += batchCount;
batchCount = 0;
nInfoList = new ArrayList<>();
}
}

int finalBatchCount = batchCount;
final ArrayList<BbItemInfo> insertList = nInfoList;
PriorityThreadFactory.getPool().execute(new PriorityThread() {
@Override
public void run() {
MySqlC c;
while ((c = getFreeConnection()) != null) {
commit(insertList, c.session, c.mapper);
for (int j = 0; j < finalBatchCount; j++) {
countDownLatch.countDown();
}
break;
}
}

@Override
public String getThreadName() {
return "t" + System.currentTimeMillis();
}
});

insertCount += batchCount;

countDownLatch.await();
for (int i = 0; i < connectionLists.size(); i++) {
connectionLists.get(i).session.close();
}

log.info(String.format("\n导入itemInfo(" + filePath + "), 单据数:%s, 导入数量:%s ", data.getRowCount(), insertCount));
} catch (Exception e) {
e.printStackTrace();
log.error("导入itemInfo", e);
}
}

public synchronized void commit(List<BbItemInfo> bbItemInfos, SqlSession sqlsession, BbItemInfoMapper bbItemInfoMapper) {
for (BbItemInfo bbItemInfo : bbItemInfos) {
bbItemInfoMapper.insert(bbItemInfo);
}
sqlsession.commit();
sqlsession.clearCache();
}

一段错误的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public boolean zipFile(String zipFileName, File inputFile) {
try {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
zipFileName)); // 创建ZipOutputStream类对象
zip(out, inputFile, ""); // 调用方法
System.out.println("压缩中…"); // 输出信息
out.close(); // 将流关闭
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

private void zip(ZipOutputStream out, File f, String base)
throws Exception { // 方法重载
if (f.isDirectory()) { // 测试此抽象路径名表示的文件是否是一个目录
File[] fl = f.listFiles(); // 获取路径数组
out.putNextEntry(new ZipEntry(base + "/")); // 写入此目录的entry
base = base.length() == 0 ? "" : base + "/"; // 判断参数是否为空
for (int i = 0; i < fl.length; i++) { // 循环遍历数组中文件
zip(out, fl[i], base + fl[i]);
}
} else {
out.putNextEntry(new ZipEntry(base)); // 创建新的进入点
// 创建FileInputStream对象
FileInputStream in = new FileInputStream(f);
int b; // 定义int型变量
System.out.println(base);
while ((b = in.read()) != -1) { // 如果没有到达流的尾部
out.write(b); // 将字节写入当前ZIP条目
}
in.close(); // 关闭流
}
}

mysql配置问题

  • show global variables like ‘%lower_case%’;

    1
    2
    3
    4
    5
    6
    +------------------------+-------+
    | Variable_name | Value |
    +------------------------+-------+
    | lower_case_file_system | ON |
    | lower_case_table_names | 0 |
    +------------------------+-------+

    此状态为区分大小写

  • 编辑 /etc/mysql/mysql.conf.d/mysqld.cnf
    增加 lower_case_table_names=1

  • 再次查看

    1
    2
    3
    4
    5
    6
    +------------------------+-------+
    | Variable_name | Value |
    +------------------------+-------+
    | lower_case_file_system | OFF |
    | lower_case_table_names | 1 |
    +------------------------+-------+

1
2
3
4
5
6
7
show session variables where variable_name ='wait_timeout' or variable_name = 'interactive_timeout';

-- 默认值 28800 8小时

set global wait_timeout = 31536000;

set global interactive_timeout = 31536000;

安装工具

yum-utils

1
sudo yum install -y yum-utils

添加repo

1
sudo yum-config-manager  --add-repo   https://download.docker.com/linux/centos/docker-ce.repo

安装Docker

1
sudo yum install docker-ce

启用Docker-ce

1
service docker start

创建用户和用户组

1
2
3
4
5
6
7
groupadd sftp #创建组
useradd -g sftp -s /sbin/nologin -M sftpuser
passwd sftpuser
cd /home
mkdir sftpuser
chown root:sftp sftpuser
chmod 755 sftpuser

修改 vi /etc/ssh/sshd_config

可以先备份一下

1
cp /etc/ssh/sshd_config /etc/ssh/sshd_config_bak

修改sshd_config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# override default of no subsystems
#Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp #添加这1个

# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server

#Match User sftp
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
ChrootDirectory /home/sftpuser

重启服务

1
systemctl restart sshd

验证

1
2
sftp sftpuser@127.0.0.1 
>sftp

已知问题

重启服务后会导致SecureCRT无法访问

备份原始的yum源

1
2
# cd /etc/yum.repos.d
# cp CentOS-Base.repo CentOS-Base.repo.bak

下载对应版本的repo文件

1
# wget -O CentOS-Linux-BaseOS.repo http://mirrors.aliyun.com/repo/Centos-8.repo

清除旧的yum缓存并生成新的yum缓存,这个过程会有点慢

1
2
# yum clean all
# yum makecache

更新,这一步不是必要的

1
# yum update -y

安装最新Git客户端后无法拉去更新任何仓库

  • 报错 no matching host key type found git

解决方法

  • .ssh 新建config文件
    1
    2
    3
    Host *
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedKeyTypes +ssh-rsa

龙珠TV版全集链接:
https://pan.xunlei.com/s/VM_YsOPv2pQ5n5JlExNtm1uMA1
提取码:f2ng(可在线观看)
龙珠GT全集链接:
https://pan.xunlei.com/s/VM_YsWSe7iE0NKH5Vj5i50NnA1
提取码:czfc
龙珠改全集链接:
https://pan.xunlei.com/s/VM_YsdEzhnLnNPa1qoIPdiXhA1
提取码:dm4t
龙珠Z蓝光全集链接:
https://pan.xunlei.com/s/VM_Yskh3hnLnNPa1qoIPdkDqA1
提取码:3k5x
龙珠剧场版20部全集链接:
https://pan.xunlei.com/s/VM_Yt081YIZeeBj5snaCqxcwA1
提取码:45vb
龙珠改布欧篇全集链接:
https://pan.xunlei.com/s/VM_YtFko7iE0NKH5Vj5i5AIKA1
提取码:z9te
龙珠超日语中字链接:
https://pan.xunlei.com/s/VMT-8s7LevEdvrnzcMMNw4gcA1
提取码:xg7z

0%