|
|||||||
Определение категорий
Время создания: 17.02.2020 13:48
Раздел: INFO - JOB - rtneo - Работа над задачами - Категоризация
Запись: wwwlir/Tetra/master/base/1581918535yhwyoz4g9a/text.html на raw.githubusercontent.com
|
|||||||
|
|||||||
import com.groupstp.rtneo.entity.* import java.util.* import com.haulmont.cuba.core.global.* import com.groupstp.rtneo.entity.* import com.haulmont.cuba.core.entity.FileDescriptor import com.haulmont.cuba.core.app.FileStorageAPI import java.io.InputStream import java.io.InputStreamReader import java.io.ByteArrayOutputStream import org.apache.commons.io.IOUtils import java.nio.charset.StandardCharsets; import com.opencsv.CSVReader; import com.groupstp.rtneo.util.JsonUtil; import com.groupstp.rtneo.core.bean.CategorizationWorker; import com.haulmont.cuba.core.global.ViewRepository; ViewRepository vRep = AppBeans.get(ViewRepository.NAME) CategorizationWorker worker = AppBeans.get(CategorizationWorker.NAME) JsonUtil jsonUtil = AppBeans.get(JsonUtil.NAME) FileStorageAPI fileStorageAPI=AppBeans.get(FileStorageAPI.NAME); //String id='68c27473-1032-c74a-2da3-c94fb19e73b3' String id='e6af52c7-4cc3-bdb3-88e3-5622b60cf9ba' FileDescriptor fd = dataManager.load(FileDescriptor.class) .id(UuidProvider.fromString(id)) .view(View.MINIMAL) .optional() .orElse(null); if (fd == null) { throw new RuntimeException("fileNotFound"); }
InputStream inputStream=fileStorageAPI.openStream(fd) CSVReader reader = new CSVReader(new InputStreamReader(inputStream, "UTF-8")); _(reader) def count = 0 for(row in reader){ count++ if(count > 100){_("BREAK - count");break;} _("---------------------------") if(row == null || row[0] == ''){_("continue - cad is null");continue;} _(row[0]) List<ContragentRealEstate> listCre = dataManager.load(ContragentRealEstate.class) .query('select c from rtneo$ContragentRealEstate c where c.realEstate.cadastralNumber = :cad') .parameter("cad", row[0]) .view(vRep.getView(ContragentRealEstate.class, "_local") .addProperty("category", vRep.getView(RealEstateCategory.class, "_local")) .addProperty("realEstate", vRep.getView(RealEstate.class, "_local"))) .list();
if(listCre.size() == 0){_("continue - cre not faund");continue;}
_(listCre[0].getRealEstate().getAddress())
if(listCre.stream().allMatch({e -> e.getCategory() != null})){_("continue - all cre category not is null");continue;}
RealEstateCategory rec = null rec = worker.determineContragentRealEstateCategory(listCre[0]) if(rec == null){_("continue - category not faund");continue;} _(rec, "json")
for(def cre : listCre){ if(cre.getCategory() != null){_("continue - cre category not is null");continue;} _("set category") cre.setCategory(rec) } } /** * Логирование */ 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)} |
|||||||
Так же в этом разделе:
|
|||||||
|
|||||||
|