SimplexSplash

Untitled

Nov 28th, 2021
548
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import com.groupstp.rtneo.core.bean.*
  2. // import org.apache.commons.lang.time.DateUtils;
  3. import com.groupstp.rtneo.entity.*
  4. import com.haulmont.cuba.core.entity.*
  5. import com.haulmont.cuba.core.global.*;
  6. import com.groupstp.rtneo.core.bean.tools.*
  7. import com.groupstp.rtneo.core.bean.calculation.*
  8.  
  9. import java.util.concurrent.ExecutorService
  10. import java.util.concurrent.Executors
  11. import java.util.stream.*
  12. import java.math.*
  13. import java.text.*
  14. import java.time.*
  15. import com.groupstp.rtneo.to.*
  16. import com.groupstp.rtneo.service.*
  17. import com.haulmont.cuba.core.*
  18. import com.groupstp.rtneo.data.*
  19. def view = //new View(RealEstateContainerYard.class).addProperty('contragentRealEstate',
  20.         new View(ContragentRealEstate.class)
  21.                 .addProperty('category', new View(RealEstateCategory.class).addProperty('name').addProperty('unit', new View(Unit.class).addProperty('name')))
  22.                 .addProperty('realEstate',
  23.                         new View(RealEstate.class).addProperty('cadastralNumber').addProperty('realEstateType',new View(RealEstateType.class)).addProperty('address').addProperty('latitude').addProperty('longitude')
  24.                 ).addProperty('contragent',new View(Contragent.class).addProperty('name').addProperty('inn')).addProperty('type',new View(RealEstateType.class))
  25. //).addProperty('containerYard', new View(ContainerYard.class).addProperty('latitude').addProperty('longitude').addProperty('code'))
  26.  
  27. datePeriodTools=AppBeans.get(DatePeriodTools.NAME)
  28. helper=AppBeans.get(CalculationWorkerHelper.NAME)
  29. calculationWorker = AppBeans.get(CalculationWorker.NAME)
  30. billService = AppBeans.get(BillService.NAME)
  31. def sdf = new SimpleDateFormat('dd.MM.yyyy')
  32.  
  33. def contractCreatorService = AppBeans.get(ContractService.NAME)
  34. def from = sdf.parse('01.12.2021')
  35. def to = sdf.parse('01.12.2022')
  36.  
  37. 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()
  38. def executorService = Executors.newCachedThreadPool()
  39. for(def contragent in contragents){
  40. executorService.submit({() -> {
  41.     def inn=contragent.inn
  42.     //  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')
  43.     // .parameter('id',contragent.getId())
  44.     // .view('contragentRealEstate-livingRealEstate')
  45.     // .list()
  46.     // living=living.stream().filter({e->isPeriodIncluded(e.validityFrom,e.validityTo,from,to)}).collect(Collectors.toSet())
  47.  
  48.     def notliving = dataManager.load(ContragentRealEstate.class).query('select distinct e.contragentRealEstate from rtneo$RealEstateContainerYard e where ' +
  49.             'e.contragentRealEstate.contragent.id = :id ' +
  50.             'and e.contragentRealEstate.category.isLiving=false ' +
  51.             'and e.validityFrom > :from and e.validityTo < :to')
  52.             .parameter('id',contragent.getId())
  53.             .parameter('from',from)
  54.             .parameter('to',to)
  55.             .view('contragentRealEstate-notlivingRealEstate')
  56.             .list()
  57. //    notliving = notliving.stream().filter({e->isPeriodIncluded(e.validityFrom,e.validityTo,from,to)}).collect(Collectors.toList())
  58.     if(notliving.isEmpty()) return
  59.     contractAttributes = new HashMap<>();
  60.     contractAttributes.put(AttributeContract.CONTRACT_DATE_FROM, from);
  61.     contractAttributes.put(AttributeContract.CONTRACT_DATE_BEFORE, to);
  62.     contractAttributes.put(AttributeContract.CONTRACT_DATE, from);
  63.     contractAttributes.put(AttributeContract.CONTRAGENT, contragent);
  64.     contractAttributes.put(AttributeContract.NUMBER_CONTRACT, contractCreatorService.createContractNumber(ContractType.BASE_CONTRACT));
  65.     contractAttributes.put(AttributeContract.NOT_LIVING_CRE, notliving);
  66.     contractAttributes.put(AttributeContract.LIVING_CRE, []);
  67.     contractAttributes.put(AttributeContract.PROJECTS, []);
  68.    
  69.     def  result =  contractCreatorService.createContract(ContractType.BASE_CONTRACT, contractAttributes);
  70.     if(!result.isCreated()){
  71.         log.debug(inn+'\tnotliving\t'+result.getMessage())
  72.     } else {
  73.         log.debug(inn+'\tnotliving created successfully\t')
  74.  
  75.     }
  76. }})
  77. }
  78.  
  79.  
  80.  
  81. def  isPeriodIncluded(Date periodStart, Date periodEnd, Date from, Date to) {
  82.  
  83.     if (Objects.nonNull(from)) {
  84.         if (periodEnd != null && periodEnd.compareTo(from) < 0) {
  85.             return false;
  86.         }
  87.     }
  88.     if (Objects.nonNull(to)) {
  89.         if (periodStart != null && periodStart.compareTo(to) > 0) {
  90.             return false;
  91.         }
  92.     }
  93.     return true;
  94. }
  95.  
  96.  
  97.  
RAW Paste Data