Skip to content

Instantly share code, notes, and snippets.

@shestakow1993
Created November 29, 2017 11:22
Show Gist options
  • Save shestakow1993/36c353145e41e9692b8307080b9ebf25 to your computer and use it in GitHub Desktop.
Save shestakow1993/36c353145e41e9692b8307080b9ebf25 to your computer and use it in GitHub Desktop.
/**
* Artur Shestakov
*/
package kg.drongo.event.additional.action;
import bitel.billing.common.TimeUtils;
import bitel.billing.server.call.bean.Login;
import bitel.billing.server.contract.bean.ContractManager;
import bitel.billing.server.contract.bean.ContractService;
import bitel.billing.server.contract.bean.ContractServiceManager;
import bitel.billing.server.dialup.bean.DialUpLoginManager;
import ru.bitel.bgbilling.kernel.script.server.dev.GlobalScriptBase;
import ru.bitel.bgbilling.server.util.Setup;
import ru.bitel.common.sql.ConnectionSet;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
/**
* Класс должен открывать все модули.
*
*/
public class OpenContractAfterClosed
extends GlobalScriptBase
{
@Override
public void execute( Setup setup, ConnectionSet connectionSet )
throws Exception
{
Connection con = connectionSet.getConnection();
int cid = 105785;
ContractManager contractManager = new ContractManager(con);
Date contractClosedDate= contractManager.getContractById(cid).getDateTo();
System.out.println("договор действителен до "+contractClosedDate);
contractManager.closeContract(cid,0,0,null); //открываем договор
Statement st = con.createStatement();
Date date = new Date();
//создаем новый контракт скрипт
String queryContractScript ="INSERT INTO contract_script (cid, date1, date2, script_id) VALUES ('"+cid+"',DATE (now()),null ,'1')";
st.executeUpdate( queryContractScript );
//открываем логин интернет PPPoE
DialUpLoginManager dialUpLoginManager = new DialUpLoginManager(con,1);
List<Login> logins=dialUpLoginManager.getContractLogins(cid);
Iterator<Login> loginsIterator = logins.iterator();
while (loginsIterator.hasNext()) {
int loginId=loginsIterator.next().getId();
System.out.println(loginId);
String query="UPDATE user_login_1 set date2=NULL where id="+loginId;
st.executeUpdate(query);
}
//открываем разрешенные услуги
ContractServiceManager contractServiceManager = new ContractServiceManager(con);
List<ContractService> contractServices = contractServiceManager.getContractServiceList(cid,1);
Iterator<ContractService> contractServicesIterator =contractServices.iterator();
System.out.println(contractServices.size());
while(contractServicesIterator.hasNext()) {
int contractServicesId=contractServicesIterator.next().getId();
System.out.print(contractServicesId+" ");
String query = "UPDATE contract_service set date2=NULL WHERE id="+contractServicesId;
st.executeUpdate(query);
}
//открываем актуальные не закрытые на дату
String query = "SELECT * from object where cid="+cid;
PreparedStatement ps = con.prepareStatement(query);
ResultSet rs = ps.executeQuery();
if (rs.next()) // Проверка на пустое значение
{
int objectId=rs.getInt("id");
int objectCid=rs.getInt("cid");
String objectTitle=rs.getString("title");
Date date1=rs.getDate("date1");
Date date2= rs.getDate("date2");
if (TimeUtils.daysDelta(date2,contractClosedDate)==0){
String deleteDate2="UPDATE object set date2=NULL where id ="+objectId;
st.executeUpdate(deleteDate2);
}
System.out.println("\n"+objectId+" "+objectCid+" "+objectTitle+" "+date1+" "+date2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment