SnTcpClientService.java
3.04 KB
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
package com.huaheng.pc.config.sn.service;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.pc.config.sn.tcp.TCPServerHandler;
import com.huaheng.pc.config.sn.tcp.TcpClientService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.OkHttpUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.domain.AjaxResultLisenes;
import com.huaheng.pc.config.address.domain.Address;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.config.sn.domain.*;
import com.huaheng.pc.config.supplier.service.SupplierSyncService;
import com.huaheng.pc.config.syncTime.domain.SyncTime;
import com.huaheng.pc.config.syncTime.service.SyncTimeService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
@Service
public class SnTcpClientService {
@Resource
private SnService snService;
@Resource
private SnPartDetailService snPartDetailService;
@Resource
private AddressService addressService;
@Resource
private TcpClientService tcpClientService;
public AjaxResult jgPrint(String ids,Integer num){
String warehouseCode= ShiroUtils.getWarehouseCode();
String addressUrl= addressService.selectAddress("TCP",warehouseCode,num.toString());
if(StringUtils.isEmpty(addressUrl)){
return AjaxResult.error("未配置tcp地址");
}
LambdaQueryWrapper<Sn> wrapper=new LambdaQueryWrapper<>();
wrapper.in(Sn::getId, Convert.toIntArray(ids));
List<Sn> details = snService.list(wrapper);
int lengthnum=12;
StringBuffer stringBuffer=new StringBuffer();
for(Sn sn:details){
stringBuffer.append(sn.getCode()+",");
}
stringBuffer.deleteCharAt(stringBuffer.length()-1);
System.out.println(TCPServerHandler.channelGroup);
TCPServerHandler.channelGroup.forEach(ch->{
System.out.println("客户端ip及port:"+ch.remoteAddress());
String addressIpPort=ch.remoteAddress().toString();
String[] str=addressIpPort.split(":");
if(addressUrl.equals(str[0])){
ch.writeAndFlush(stringBuffer.toString());
}
// if(clientIpPort.equals(ch.remoteAddress().toString())){
// ch.writeAndFlush(stringBuffer.toString());
// }
});
return AjaxResult.success();
}
}