SnTcpClientService.java 3.04 KB
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();
    }



}