Перемещение в группу через 3 месяца если не было движения денег в наработке
Материал из BiTel WiKi
(Различия между версиями)
Skyb (Обсуждение | вклад) |
Zavndw (Обсуждение | вклад) м |
||
Строка 1: | Строка 1: | ||
- | 5.0 | + | 5.0 и 5.1 |
Перемещение происходит в группу 19, снимает все остальные группы, и устанавливает закрытый период | Перемещение происходит в группу 19, снимает все остальные группы, и устанавливает закрытый период | ||
<source lang="java"> | <source lang="java"> | ||
Строка 37: | Строка 37: | ||
contract = new ContractManager(con); | contract = new ContractManager(con); | ||
BalanceUtils balance = new BalanceUtils(con); | BalanceUtils balance = new BalanceUtils(con); | ||
- | Contract ct = contract. | + | Contract ct = contract.getContractById(cid); |
Date contract_balance = balance.getLastBalanceMonth(ct); | Date contract_balance = balance.getLastBalanceMonth(ct); | ||
if( contract_balance == null) | if( contract_balance == null) | ||
Строка 51: | Строка 51: | ||
PreparedStatement ps = con.prepareStatement( update_query ); | PreparedStatement ps = con.prepareStatement( update_query ); | ||
ps.executeUpdate() ; | ps.executeUpdate() ; | ||
+ | //устанавливает закрытый период=начало | ||
String close_query = "update contract set date2 = '" + dateSql + "' where id = "+ cid; | String close_query = "update contract set date2 = '" + dateSql + "' where id = "+ cid; | ||
PreparedStatement rs = con.prepareStatement( close_query ); | PreparedStatement rs = con.prepareStatement( close_query ); | ||
rs.executeUpdate() ; | rs.executeUpdate() ; | ||
+ | //устанавливает закрытый период=конец | ||
cpu = new ContractParamUtils( con ); | cpu = new ContractParamUtils( con ); | ||
cpu.setGroup( cid, 19 ); | cpu.setGroup( cid, 19 ); |
Версия 02:56, 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; import ru.bitel.bgbilling.kernel.script.server.dev.GlobalScriptBase; import ru.bitel.bgbilling.server.util.Setup; import ru.bitel.common.sql.ConnectionSet; import java.math.BigDecimal; import java.sql.*; import java.util.*; import java.util.Date; 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 class archive extends GlobalScriptBase { @Override public void execute( Setup setup1, ConnectionSet connectionSet2 ) throws Exception { Connection con = connectionSet2.getConnection(); Calendar calendar = new GregorianCalendar(); 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<<19)=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); BalanceUtils balance = new BalanceUtils(con); Contract ct = contract.getContractById(cid); Date contract_balance = (Date) balance.getLastBalanceMonth(ct); if( contract_balance == null) { contract_balance = new Date(i); } 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() ; ContractParamUtils cpu = new ContractParamUtils( con ); cpu.setGroup( cid, 19 ); i++; } } print("кол-во " +i ); } }