|
|||||||
temp
Время создания: 28.04.2020 01:50
Раздел: INFO - JOB - rtneo - Работа над задачами - Создание договоров
Запись: wwwlir/Tetra/master/base/1588009836nzrbw9w3gm/text.html на raw.githubusercontent.com
|
|||||||
|
|||||||
import com.haulmont.cuba.core.global.* import com.groupstp.rtneo.entity.* import com.groupstp.rtneo.service.* import com.groupstp.rtneo.core.bean.* import java.text.DateFormat; import java.text.SimpleDateFormat; ContractService contractService = AppBeans.get(ContractService.class) CalculationWorker calculationWorker = AppBeans.get(CalculationWorker.NAME) SnapshotHistoryService snapshotHistoryService = AppBeans.get(SnapshotHistoryService.NAME); DateFormat df = new SimpleDateFormat("dd.MM.yyyy"); Date start = df.parse('01.01.2019') Date end = df.parse('31.12.2019') //Отобрать которые не заходили List<Contragent> contragents = dataManager.load(Contragent.class) // .query('select c from rtneo$Contragent c where c.user.login is null or (select count(s) from sec$SessionLogEntry s where s.user.login = c.user.login) = 0') // .query('select c from rtneo$Contragent c where size(c.contracts) <=1 and c.user.login is null or (select count(s) from sec$SessionLogEntry s where s.user.login = c.user.login) = 0') .query('select c from rtneo$Contragent c where size(c.contracts) <=1 and (c.user.login is null or (select count(s) from sec$SessionLogEntry s where s.user.login = c.user.login) = 0) and size(c.realEstates)>0') .firstResult(0) .maxResults(1000) .view("contragent-create-contract") .list() List<String> contragentsLoging = new ArrayList<>() List<Contract> suppContracts = new ArrayList<>() //contract = contractService.createNewBaseContract(contragents.get(0), start, end) //contract = contractService.createNewBaseContractClean(contragent, start, end) //contractService.fillBaseContract(contragent, contract, start, end) //Сначала создавать колекции, потом договора Date dateCre1 = df.parse('31.12.2018') Date date0Cre2 = df.parse('01.01.2019') Date date1Cre2 = df.parse('30.04.2019') Date date1Cre3 = df.parse('01.05.2019') for(Contragent contragent : contragents){ Contract contract; Contract suppContract; _(contragent.getInn()+' - '+contragent.getName())
//Удалять старые договора!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! cleanContracts(contragent) if(contragent.getRealEstates().size() == 0){ _('Not object') //Создать контракт по среднему т.к. нету объектов // Contract contract = contractService.createNewBaseContractClean(contragent, start, end) // contractService.fillBaseContract(contragent, contract, start, end) // contractService.buildContractPositionsForAWG(contragent, contract, start); // // //сразу делаем начисление по базовому договору // calculationWorker.calculateAccruals(contract.getFrom(), contract.getBefore(), contragent, new Date(), contract); // calculationWorker.setupRelevanceOfBills(contract); // snapshotHistoryService.createSnapshotsFromContract(contract); continue }
List<ContragentRealEstate> cre1 = new ArrayList<>() List<ContragentRealEstate> cre2 = new ArrayList<>() List<ContragentRealEstate> cre3 = new ArrayList<>() List<ContragentRealEstate> cre4 = new ArrayList<>()
for(ContragentRealEstate cre : contragent.getRealEstates()){ if(cre.getValidityFrom() == null){ cre4.add(cre) continue }
if(cre.getValidityFrom().compareTo(dateCre1)<=0){ cre1.add(cre) continue }
if(cre.getValidityFrom().compareTo(date0Cre2)>=0 && cre.getValidityFrom().compareTo(date1Cre2)<=0){ cre2.add(cre) continue }
if(cre.getValidityFrom().compareTo(date1Cre3)>=0){ cre3.add(cre) continue } }
_("cre1") _(cre1) _("cre2") _(cre2) _("cre3") _(cre3) _("cre4") _(cre4)
if(cre1.size() > 0){ //Создаем пустой договор //Узнать на какие периоды создавать договора //ПНООЛР обрабатывать отдельно contract = createContractForCRE(contragent, start, end, cre1) suppContract = createSuppContractForCRE(contragent, contract, start, end, cre1) }
if(cre2.size() > 0){ contract = createContractForCRE(contragent, start, end, cre2) suppContract = createSuppContractForCRE(contragent, contract, start, end, cre2) }
if(cre3.size() > 0){ contract = createContractForCRE(contragent, start, end, cre3) suppContract = createSuppContractForCRE(contragent, contract, start, end, cre3) }
if(cre4.size() > 0){ contract = createContractForCRE(contragent, start, end, cre4) suppContract = createSuppContractForCRE(contragent, contract, start, end, cre4) }
suppContracts.add(suppContract) contragentsLoging.add(contragent.getName()) } //Убираем признак принятия допа //unaccepted(suppContracts) _("*****************************************************************************") contragentsLoging.each({_(it)}) public Contract createContractForCRE(Contragent contragent, Date start, Date end, List<ContragentRealEstate> cre){ ContractService contractService = AppBeans.get(ContractService.class) CalculationWorker calculationWorker = AppBeans.get(CalculationWorker.NAME) SnapshotHistoryService snapshotHistoryService = AppBeans.get(SnapshotHistoryService.NAME); Contract contract; try{ contract = contractService.createNewBaseContractClean(contragent, start, end) contractService.fillBaseContract(contragent, contract, start, end) contractService.buildContractPositionsForRealEstate(contragent, contract, start, cre); }catch(Exception e){ _('No created clean contract') return dataManager.create(Contract.class); }
//сразу делаем начисление по базовому договору //Нужно определить дату начисления // calculationWorker.calculateAccruals(contract.getFrom(), contract.getBefore(), contragent, timeSource.currentTimestamp(), contract); calculationWorker.calculateAccruals(contract.getFrom(), contract.getBefore(), contragent, new Date(), contract); calculationWorker.setupRelevanceOfBills(contract); snapshotHistoryService.createSnapshotsFromContract(contract); return contract } public Contract createSuppContractForCRE(Contragent contragent, Contract baseContract, Date start, Date end, List<ContragentRealEstate> cre){ ContractService contractService = AppBeans.get(ContractService.class) CalculationWorker calculationWorker = AppBeans.get(CalculationWorker.NAME) SnapshotHistoryService snapshotHistoryService = AppBeans.get(SnapshotHistoryService.NAME);
baseContract = dataManager.reload(baseContract, "contract-view-createSupplementaryAggrements") Contract contract; try{ contract = contractService.createNewSuppContractClean(contragent, baseContract, start, end) }catch(Exception e){ _('No created clean contract') return dataManager.create(Contract.class); } contractService.buildContractPositionsForRealEstateSupp(contragent, contract, start, cre);
//сразу делаем начисление по базовому договору //Нужно определить дату начисления calculationWorker.calculateAccruals(contract.getFrom(), contract.getBefore(), contragent, new Date(), contract); calculationWorker.setupRelevanceOfBills(contract); snapshotHistoryService.createSnapshotsFromContract(contract);
processContract(contract, true, false)
return contract } public void cleanContracts(Contragent contragent){ List<Contract> contracts = dataManager.load(Contract.class) .query('select c from rtneo$Contract c where c.contragent.id = :contragent') .parameter("contragent", contragent.getId()) .view("_local") .list() contracts.each({dataManager.remove(it)}) } public void processContract(Contract contract, boolean accepted, boolean confirm) { CalculationWorker calculationWorker = AppBeans.get(CalculationWorker.NAME) //получаем предыдущий договор Contract lastContract = null; if (contract.getMainContract() != null) { List<Contract> contracts = dataManager.load(Contract.class) .query('select c from rtneo$Contract c where (c.mainContract.id=:mainContract OR c.id=:mainContract) ' + 'AND NOT c.id=:id ' + 'order by c.createTs DESC') .parameter("mainContract", contract.getMainContract().getId()) .parameter("id", contract.getId()) .view("contract-edit") .maxResults(1) .list(); if (contracts.size() > 0) { lastContract = contracts.get(0); } } if (accepted) { contract.setAccepted(accepted); contract.setAcceptanceDate(new Date()); //делаем предыдущий неактивным if (lastContract != null) { makeContractObsolete(lastContract, false); } //текущий делаем активным makeContractObsolete(contract, true); //коммит dataManager.commit(contract); //Bills calculationWorker.setupRelevanceOfBills(contract); // snapshotHistoryService.createSnapshotsForContract(contract); } else { if(!confirm) dataManager.remove(contract); } // //Убираем признак принятия допа // contract.setAccepted(false); // contract.setAcceptanceDate(null); // dataManager.commit(contract)
} private void makeContractObsolete(Contract contract, Boolean reverse) { contract = dataManager.reload(contract, "contract-edit"); CommitContext commitContext = new CommitContext(); for (ContractPosition position : contract.getPositions()) { position.setRelevance(reverse); commitContext.addInstanceToCommit(position); } dataManager.commit(commitContext); } public void unaccepted(List<Contract> contracts){ CommitContext ctx = new CommitContext() for(Contract contract : contracts){ contract.setAccepted(false); contract.setAcceptanceDate(null); ctx.addInstanceToCommit(contract) }
dataManager.commit(ctx) } /** * Логирование */ import com.haulmont.cuba.core.app.serialization.EntitySerializationAPI; import com.groupstp.rtneo.util.JsonUtil; import java.text.DateFormat; import java.text.SimpleDateFormat; private _(Object obj, String... options){ if(obj == null){log("LOG.ERROR: Object is null!!!");return} if(options.size() == 0){log(obj)} for(def option : options){ if(option.equals("str")){log(obj)} if(option.equals("for")){obj.each({_(it)})} if(option.equals("json")){ EntitySerializationAPI entitySerializationAPI = AppBeans.get(EntitySerializationAPI.NAME) try{log(entitySerializationAPI.toJson(obj))} catch(Exception e){log("LOG.ERROR: JSON entity serialization failed")} } if(option.equals("objJson")){ JsonUtil jsonUtil = AppBeans.get(JsonUtil.NAME) try{log.(jsonUtil.toJson(obj))} catch(Exception e){log("LOG.ERROR: JSON object serialization failed")} } if(option.equals("date")){ DateFormat df = new SimpleDateFormat("dd.MM.yyyy"); try{log(df.format(obj))} catch(Exception e){log("LOG.ERROR: Failed date format")} } } } private log(Object obj){log.debug(obj)} |
|||||||
Так же в этом разделе:
|
|||||||
|
|||||||
|