我制作了一个机器人,该机器人使用POI从Excel文件发送信息。这是我的第一个帖子,欢迎任何批评家或建议。 代码正在读取Excel文件(该机器人的目的是销售智能手机)并获取标题和价格,然后获取URL并将其发送给用户。但是,当我同时使用两个帐户的bot时,bot首先将照片发送给第一个用户,然后再发送给另一个用户。如何使它同时适用于所有用户?
class Methods extends Bot {
private static String caption( Sheet sheet,int i ) {
return sheet.getRow( i ).getcell( 4 ).toString( ) + " "
+ sheet.getRow( i ).getcell( 6 ).toString( ) + "\n "
+ sheet.getRow( i ).getcell( 7 ).toString( ) + " "
+ sheet.getRow( i ).getcell( 8 ).toString( ) + " ";
}
private static String photo( Sheet sheet,int i ) {
return sheet.getRow( i ).getcell( 9 ) + " ";
}
public void senderOfGoods( String call_data,String excelProductTypeSorter,Long chat_id ) {
final String SAMPLE_XLSX_FILE_PATH = "C:/Users/user/Desktop/File.xlsx";
Workbook workbook = null;
try {
workbook = WorkbookFactory.create( new File( SAMPLE_XLSX_FILE_PATH ) );
} catch (IOException | InvalidFormatException e) {
e.printStackTrace( );
}
assert workbook != null;
for (Sheet sheet : workbook) {
sheet = workbook.getSheetat( 0 );
int counterTillFive = 0;
for (int i =0; i <= sheet.getLastRowNum( ); i++) {
String razdel_1 = String.valueOf( sheet.getRow( i ).getcell( 2 ) );
String caption = Methods.caption( sheet,i );
String photo = Methods.photo( sheet,i );
//Searching String from excel
//Here excelProductTypeSorter searches for string in excel if finds then send that row text as a caption
if ( razdel_1.contains( excelProductTypeSorter ) ) {
SendPhoto sendPhoto = new SendPhoto( )
.setChatId( chat_id )
.setCaption( caption )
.setPhoto( photo );
try {
sendPhoto( sendPhoto );
} catch (TelegramApiException e) {
e.printStackTrace( );
}
if ( counterTillFive % 5 == 0 && counterTillFive != 0 )
break;
counterTillFive++;
}
}
try {
workbook.close( );
} catch (IOException e) {
e.printStackTrace( );
}
}
}
}