Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.groupstp.rtneo.core.bean.*
- // import org.apache.commons.lang.time.DateUtils;
- import com.groupstp.rtneo.entity.*
- import com.haulmont.cuba.core.entity.*
- import com.haulmont.cuba.core.global.*;
- import com.groupstp.rtneo.core.bean.tools.*
- import com.groupstp.rtneo.core.bean.calculation.*
- import java.util.concurrent.ExecutorService
- import java.util.concurrent.Executors
- import java.util.stream.*
- import java.math.*
- import java.text.*
- import java.time.*
- import com.groupstp.rtneo.to.*
- import com.groupstp.rtneo.service.*
- import com.haulmont.cuba.core.*
- import com.groupstp.rtneo.data.*
- def view = //new View(RealEstateContainerYard.class).addProperty('contragentRealEstate',
- new View(ContragentRealEstate.class)
- .addProperty('category', new View(RealEstateCategory.class).addProperty('name').addProperty('unit', new View(Unit.class).addProperty('name')))
- .addProperty('realEstate',
- new View(RealEstate.class).addProperty('cadastralNumber').addProperty('realEstateType',new View(RealEstateType.class)).addProperty('address').addProperty('latitude').addProperty('longitude')
- ).addProperty('contragent',new View(Contragent.class).addProperty('name').addProperty('inn')).addProperty('type',new View(RealEstateType.class))
- //).addProperty('containerYard', new View(ContainerYard.class).addProperty('latitude').addProperty('longitude').addProperty('code'))
- datePeriodTools=AppBeans.get(DatePeriodTools.NAME)
- helper=AppBeans.get(CalculationWorkerHelper.NAME)
- calculationWorker = AppBeans.get(CalculationWorker.NAME)
- billService = AppBeans.get(BillService.NAME)
- def sdf = new SimpleDateFormat('dd.MM.yyyy')
- def contractCreatorService = AppBeans.get(ContractService.NAME)
- def from = sdf.parse('01.12.2021')
- def to = sdf.parse('01.12.2022')
- def contragents = dataManager.load(Contragent.class).query('select e from rtneo$Contragent e where size(e.realEstates)>=3').maxResults(100).view('contragent-create-contract').list()
- def executorService = Executors.newCachedThreadPool()
- for(def contragent in contragents){
- executorService.submit({() -> {
- def inn=contragent.inn
- // def living = dataManager.load(ContragentRealEstate.class).query('select distinct e.contragentRealEstate from rtneo$RealEstateContainerYard e where e.contragentRealEstate.contragent.id = :id and e.contragentRealEstate.category.isLiving=true and e.contragentRealEstate.calculationAmount is not null')
- // .parameter('id',contragent.getId())
- // .view('contragentRealEstate-livingRealEstate')
- // .list()
- // living=living.stream().filter({e->isPeriodIncluded(e.validityFrom,e.validityTo,from,to)}).collect(Collectors.toSet())
- def notliving = dataManager.load(ContragentRealEstate.class).query('select distinct e.contragentRealEstate from rtneo$RealEstateContainerYard e where ' +
- 'e.contragentRealEstate.contragent.id = :id ' +
- 'and e.contragentRealEstate.category.isLiving=false ' +
- 'and e.validityFrom > :from and e.validityTo < :to')
- .parameter('id',contragent.getId())
- .parameter('from',from)
- .parameter('to',to)
- .view('contragentRealEstate-notlivingRealEstate')
- .list()
- // notliving = notliving.stream().filter({e->isPeriodIncluded(e.validityFrom,e.validityTo,from,to)}).collect(Collectors.toList())
- if(notliving.isEmpty()) return
- contractAttributes = new HashMap<>();
- contractAttributes.put(AttributeContract.CONTRACT_DATE_FROM, from);
- contractAttributes.put(AttributeContract.CONTRACT_DATE_BEFORE, to);
- contractAttributes.put(AttributeContract.CONTRACT_DATE, from);
- contractAttributes.put(AttributeContract.CONTRAGENT, contragent);
- contractAttributes.put(AttributeContract.NUMBER_CONTRACT, contractCreatorService.createContractNumber(ContractType.BASE_CONTRACT));
- contractAttributes.put(AttributeContract.NOT_LIVING_CRE, notliving);
- contractAttributes.put(AttributeContract.LIVING_CRE, []);
- contractAttributes.put(AttributeContract.PROJECTS, []);
- def result = contractCreatorService.createContract(ContractType.BASE_CONTRACT, contractAttributes);
- if(!result.isCreated()){
- log.debug(inn+'\tnotliving\t'+result.getMessage())
- } else {
- log.debug(inn+'\tnotliving created successfully\t')
- }
- }})
- }
- def isPeriodIncluded(Date periodStart, Date periodEnd, Date from, Date to) {
- if (Objects.nonNull(from)) {
- if (periodEnd != null && periodEnd.compareTo(from) < 0) {
- return false;
- }
- }
- if (Objects.nonNull(to)) {
- if (periodStart != null && periodStart.compareTo(to) > 0) {
- return false;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement