Перемещение в группу через 3 месяца если не было движения денег в наработке
Материал из BiTel WiKi
(Различия между версиями)
Zavndw (Обсуждение | вклад) м |
Skyb (Обсуждение | вклад) |
||
Строка 68: | Строка 68: | ||
5.2 Динамический java код | 5.2 Динамический java код | ||
<source lang="java"> | <source lang="java"> | ||
- | package ru.skyb; | + | package ru.skyb.scripts.global; |
import ru.bitel.bgbilling.kernel.script.server.dev.GlobalScriptBase; | import ru.bitel.bgbilling.kernel.script.server.dev.GlobalScriptBase; | ||
import ru.bitel.bgbilling.server.util.Setup; | import ru.bitel.bgbilling.server.util.Setup; | ||
import ru.bitel.common.sql.ConnectionSet; | import ru.bitel.common.sql.ConnectionSet; | ||
- | |||
import java.sql.*; | import java.sql.*; | ||
import java.util.*; | import java.util.*; | ||
import java.util.Date; | import java.util.Date; | ||
- | |||
import bitel.billing.common.TimeUtils; | import bitel.billing.common.TimeUtils; | ||
- | |||
- | |||
- | |||
- | |||
import bitel.billing.server.contract.bean.*; | import bitel.billing.server.contract.bean.*; | ||
- | public class archive | + | public class archive extends GlobalScriptBase { |
- | + | @Override | |
- | { | + | public void execute(Setup setup1, ConnectionSet connectionSet2) |
- | + | throws Exception { | |
- | + | ||
- | + | Connection con = connectionSet2.getConnection(); | |
- | + | Calendar calendar = Calendar.getInstance(); | |
- | + | GregorianCalendar nowDate = (GregorianCalendar) calendar.clone();// клонируем | |
- | + | // дату | |
- | + | // для | |
- | + | // дальнейшей | |
- | + | // работы | |
- | + | nowDate.get(Calendar.DATE); | |
- | + | GregorianCalendar sqlDate = (GregorianCalendar) calendar.clone(); | |
- | + | Date dateSql = TimeUtils.convertCalendarToSqlDate(sqlDate); | |
+ | Date dateNow = TimeUtils.convertCalendarToDate(nowDate);// переводим | ||
+ | // дату в тип | ||
+ | // Date с типа | ||
+ | // Calendar | ||
+ | String query = "select id from contract where gr&(1<<3)>0"; | ||
+ | PreparedStatement contractPs = con.prepareStatement(query); | ||
+ | ResultSet contractRs = contractPs.executeQuery(); | ||
+ | int cid; | ||
+ | int i = 0; | ||
+ | while (contractRs.next()) { | ||
+ | cid = contractRs.getInt(1); | ||
+ | |||
+ | ContractManager contract = new ContractManager(con); | ||
+ | Contract ct = contract.getContractById(cid); | ||
+ | /* | ||
+ | * getLastBalanceMonth public | ||
+ | * java.util.Date getLastBalanceMonth(Contract contract) возращает | ||
+ | * самый старший месяц, за который есть данные по Балансу | ||
+ | */ | ||
+ | BalanceUtils balance = new BalanceUtils(con); | ||
+ | Date contract_balance = (Date) balance.getLastBalanceMonth(ct); | ||
+ | if (contract_balance == null) { | ||
+ | continue; | ||
+ | } | ||
+ | // ==========================close==============================// | ||
+ | int mounth = TimeUtils.monthsDelta(contract_balance, dateNow); | ||
+ | if (mounth > 6) { | ||
+ | print("Контракт с сидом " + cid); | ||
+ | /* | ||
+ | * String update_query = "update contract set gr=0 where id = "+ | ||
+ | * cid; PreparedStatement ps = con.prepareStatement( | ||
+ | * update_query ); ps.executeUpdate() ; String close_query = | ||
+ | * "update contract set date2 = '" + dateSql + "' where id = "+ | ||
+ | * cid; PreparedStatement rs = con.prepareStatement( close_query | ||
+ | * ); rs.executeUpdate() ; | ||
+ | */ | ||
+ | contract.closeContract(cid); | ||
+ | ContractParameterManager cpu = new ContractParameterManager(con); | ||
+ | cpu.setGroup(cid, 19); | ||
+ | cpu.unsetGroup(cid, 3); | ||
+ | cpu.unsetGroup(cid, 0); | ||
+ | i++; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | print("кол-во " + i); | ||
+ | } | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
} | } | ||
</source> | </source> |
Текущая версия на 04:39, 15 ноября 2012
5.0 и 5.1 Перемещение происходит в группу 19, снимает все остальные группы, и устанавливает закрытый период
import java.math.BigDecimal; import java.sql.*; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.*; import bitel.billing.server.tariff.*; import bitel.billing.common.TimeUtils; import bitel.billing.server.util.*; import ru.bitel.bgbilling.server.util.DefaultServerSetup; import ru.bitel.bgbilling.server.util.ServerUtils; import bitel.billing.common.KernelConst; import bitel.billing.server.contract.bean.*; public void main( setup, con, conSlave ) { Calendar calendar = new GregorianCalendar(); nowDate = calendar.clone();//клонируем дату для дальнейшей работы nowDate.get(Calendar.DATE); sqlDate = calendar.clone(); Date dateSql = TimeUtils.convertCalendarToSqlDate(sqlDate); Date dateNow = TimeUtils.convertCalendarToDate(nowDate);//переводим дату в тип Date с типа Calendar String query = "select id from contract where gr&(1<<19)=0"; PreparedStatement contractPs = con.prepareStatement( query ); ResultSet contractRs = contractPs.executeQuery(); int cid; int i = 0; while ( contractRs.next() ) { cid = contractRs.getInt( 1 ); contract = new ContractManager(con); BalanceUtils balance = new BalanceUtils(con); Contract ct = contract.getContractById(cid); Date contract_balance = balance.getLastBalanceMonth(ct); if( contract_balance == null) { contract_balance = new Date(); } int mounth = TimeUtils.monthsDelta(contract_balance,dateNow); if (mounth > 3 ) { print ("Контракт с сидом " + cid); String update_query = "update contract set gr=0 where id = "+ cid; PreparedStatement ps = con.prepareStatement( update_query ); ps.executeUpdate() ; //устанавливает закрытый период=начало String close_query = "update contract set date2 = '" + dateSql + "' where id = "+ cid; PreparedStatement rs = con.prepareStatement( close_query ); rs.executeUpdate() ; //устанавливает закрытый период=конец cpu = new ContractParamUtils( con ); cpu.setGroup( cid, 19 ); i++; } } print("кол-во " +i ); contractRs.close(); contractPs.close(); }
5.2 Динамический java код
package ru.skyb.scripts.global; 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.*; import java.util.*; import java.util.Date; import bitel.billing.common.TimeUtils; import bitel.billing.server.contract.bean.*; public class archive extends GlobalScriptBase { @Override public void execute(Setup setup1, ConnectionSet connectionSet2) throws Exception { Connection con = connectionSet2.getConnection(); Calendar calendar = Calendar.getInstance(); GregorianCalendar nowDate = (GregorianCalendar) calendar.clone();// клонируем // дату // для // дальнейшей // работы nowDate.get(Calendar.DATE); GregorianCalendar sqlDate = (GregorianCalendar) calendar.clone(); Date dateSql = TimeUtils.convertCalendarToSqlDate(sqlDate); Date dateNow = TimeUtils.convertCalendarToDate(nowDate);// переводим // дату в тип // Date с типа // Calendar String query = "select id from contract where gr&(1<<3)>0"; PreparedStatement contractPs = con.prepareStatement(query); ResultSet contractRs = contractPs.executeQuery(); int cid; int i = 0; while (contractRs.next()) { cid = contractRs.getInt(1); ContractManager contract = new ContractManager(con); Contract ct = contract.getContractById(cid); /* * getLastBalanceMonth public * java.util.Date getLastBalanceMonth(Contract contract) возращает * самый старший месяц, за который есть данные по Балансу */ BalanceUtils balance = new BalanceUtils(con); Date contract_balance = (Date) balance.getLastBalanceMonth(ct); if (contract_balance == null) { continue; } // ==========================close==============================// int mounth = TimeUtils.monthsDelta(contract_balance, dateNow); if (mounth > 6) { print("Контракт с сидом " + cid); /* * String update_query = "update contract set gr=0 where id = "+ * cid; PreparedStatement ps = con.prepareStatement( * update_query ); ps.executeUpdate() ; String close_query = * "update contract set date2 = '" + dateSql + "' where id = "+ * cid; PreparedStatement rs = con.prepareStatement( close_query * ); rs.executeUpdate() ; */ contract.closeContract(cid); ContractParameterManager cpu = new ContractParameterManager(con); cpu.setGroup(cid, 19); cpu.unsetGroup(cid, 3); cpu.unsetGroup(cid, 0); i++; } } print("кол-во " + i); } }