SUPPORT-8471: new fix
This commit is contained in:
parent
5fa5d5a3d6
commit
4ea6831a0c
14 changed files with 75 additions and 468 deletions
|
|
@ -24,7 +24,7 @@ public class EsnsiOkopfClient {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(EsnsiOkopfClient.class);
|
||||
|
||||
@Value("${ervu.esnsi.okopf.file.url:https://esnsi.gosuslugi.ru/rest/ext/v1/classifiers/11465/file?extension=JSON&encoding=UTF_8}")
|
||||
@Value("${esnsi.okopf.url:#{null}")
|
||||
private String uri;
|
||||
|
||||
@Retryable(value = {TimeoutException.class}, backoff =
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
package ervu.dao.classifier;
|
||||
|
||||
|
||||
import ervu.service.classifier.model.OkopfAttributeModel;
|
||||
|
||||
/**
|
||||
* @author Artyom Hackimullin
|
||||
*/
|
||||
public interface OkopfAttributeDao {
|
||||
void save(OkopfAttributeModel[] okopfAttributeModels);
|
||||
|
||||
void deleteIfNotExistRecords();
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package ervu.dao.classifier;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
import ervu.service.classifier.model.OkopfAttributeModel;
|
||||
import org.jooq.DSLContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
/**
|
||||
* @author Artyom Hackimullin
|
||||
*/
|
||||
@Repository
|
||||
public class OkopfAttributeDaoImpl implements OkopfAttributeDao {
|
||||
|
||||
@Autowired
|
||||
private DSLContext dsl;
|
||||
|
||||
public void save(OkopfAttributeModel[] okopfAttributeModels) {
|
||||
var queries = Arrays.stream(okopfAttributeModels).map(attribute -> {
|
||||
var uid = UUID.fromString(attribute.getUid());
|
||||
return dsl.insertInto(OKOPF_ATTRIBUTES)
|
||||
.set(OKOPF_ATTRIBUTES.OKOPF_ATTRIBUTE_ID, uid)
|
||||
.set(OKOPF_ATTRIBUTES.ATTRIBUTE_NAME, attribute.getName())
|
||||
.onConflict(OKOPF_ATTRIBUTES.OKOPF_ATTRIBUTE_ID)
|
||||
.doUpdate()
|
||||
.set(OKOPF_ATTRIBUTES.ATTRIBUTE_NAME, attribute.getName());
|
||||
}).toList();
|
||||
dsl.batch(queries).execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteIfNotExistRecords() {
|
||||
dsl.deleteFrom(OKOPF_ATTRIBUTES).whereNotExists(dsl.selectOne()
|
||||
.from(OKOPF_ATTRIBUTES)
|
||||
.where(OKOPF_RECORDS.ATTRIBUTE_ID.eq(OKOPF_ATTRIBUTES.OKOPF_ATTRIBUTE_ID)))
|
||||
.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,17 +1,16 @@
|
|||
package ervu.dao.classifier;
|
||||
|
||||
|
||||
import ervu.service.classifier.model.OkopfGroupRecordModel;
|
||||
import java.util.List;
|
||||
|
||||
import ervu.service.classifier.model.OkopfRecordModel;
|
||||
|
||||
|
||||
/**
|
||||
* @author Artyom Hackimullin
|
||||
*/
|
||||
public interface OkopfRecordDao {
|
||||
void save(OkopfGroupRecordModel[] recordModels, String version);
|
||||
void save(List<OkopfRecordModel> recordModels, int version);
|
||||
|
||||
String fetchTitleByLeg(String leg);
|
||||
|
||||
void deleteAllByVersion(String version);
|
||||
|
||||
String fetchVersion();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,93 +0,0 @@
|
|||
package ervu.service.classifier.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Artyom Hackimullin
|
||||
*/
|
||||
public class OkopfAttributeModel implements Serializable {
|
||||
private final static long serialVersionUID = 1L;
|
||||
|
||||
private String uid;
|
||||
|
||||
private String type;
|
||||
|
||||
private String name;
|
||||
|
||||
private String techName;
|
||||
|
||||
private Boolean required;
|
||||
|
||||
private Boolean unique;
|
||||
|
||||
private Integer length;
|
||||
|
||||
public String getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(String uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getTechName() {
|
||||
return techName;
|
||||
}
|
||||
|
||||
public void setTechName(String techName) {
|
||||
this.techName = techName;
|
||||
}
|
||||
|
||||
public Boolean getRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
public void setRequired(Boolean required) {
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
public Boolean getUnique() {
|
||||
return unique;
|
||||
}
|
||||
|
||||
public void setUnique(Boolean unique) {
|
||||
this.unique = unique;
|
||||
}
|
||||
|
||||
public Integer getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(Integer length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OkopfAttributeModel{" +
|
||||
"uid='" + uid + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", techName='" + techName + '\'' +
|
||||
", required=" + required +
|
||||
", unique=" + unique +
|
||||
", length=" + length +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package ervu.service.classifier.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* @author Artyom Hackimullin
|
||||
*/
|
||||
public class OkopfFormDataModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@JsonProperty("classifier")
|
||||
private OkopfOrgModel okopfOrg;
|
||||
|
||||
@JsonProperty("data")
|
||||
private OkopfNodeModel okopfNode;
|
||||
|
||||
public OkopfOrgModel getOkopfOrg() {
|
||||
return okopfOrg;
|
||||
}
|
||||
|
||||
public void setOkopfOrg(OkopfOrgModel okopfOrg) {
|
||||
this.okopfOrg = okopfOrg;
|
||||
}
|
||||
|
||||
public OkopfNodeModel getOkopfNode() {
|
||||
return okopfNode;
|
||||
}
|
||||
|
||||
public void setOkopfNode(OkopfNodeModel okopfNode) {
|
||||
this.okopfNode = okopfNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OkopfOrgModel{" +
|
||||
"classifier=" + okopfOrg +
|
||||
", data=" + okopfNode +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
package ervu.service.classifier.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* @author Artyom Hackimullin
|
||||
*/
|
||||
public class OkopfGroupRecordModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String uid;
|
||||
|
||||
@JsonProperty("attributeValues")
|
||||
private OkopfRecordModel[] okopfRecords;
|
||||
|
||||
public OkopfRecordModel[] getOkopfRecords() {
|
||||
return okopfRecords;
|
||||
}
|
||||
|
||||
public void setOkopfRecords(OkopfRecordModel[] okopfRecords) {
|
||||
this.okopfRecords = okopfRecords;
|
||||
}
|
||||
|
||||
public String getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(String uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
package ervu.service.classifier.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* @author Artyom Hackimullin
|
||||
*/
|
||||
public class OkopfNodeModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@JsonProperty("classifierUid")
|
||||
private String okopfUid;
|
||||
|
||||
@JsonProperty("records")
|
||||
private OkopfGroupRecordModel[] okopfGroups;
|
||||
|
||||
public String getOkopfUid() {
|
||||
return okopfUid;
|
||||
}
|
||||
|
||||
public void setOkopfUid(String okopfUid) {
|
||||
this.okopfUid = okopfUid;
|
||||
}
|
||||
|
||||
public OkopfGroupRecordModel[] getOkopfGroups() {
|
||||
return okopfGroups;
|
||||
}
|
||||
|
||||
public void setOkopfGroups(OkopfGroupRecordModel[] okopfGroups) {
|
||||
this.okopfGroups = okopfGroups;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,153 +0,0 @@
|
|||
package ervu.service.classifier.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
/**
|
||||
* @author Artyom Hackimullin
|
||||
*/
|
||||
public class OkopfOrgModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String uid;
|
||||
|
||||
private String code;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
private String version;
|
||||
|
||||
private String publicId;
|
||||
|
||||
private String techName;
|
||||
|
||||
private String updatePeriod;
|
||||
|
||||
private OkopfAttributeModel[] attributes;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX")
|
||||
private LocalDateTime revisionTimestamp;
|
||||
|
||||
private String keyAttributeUid;
|
||||
|
||||
private String type;
|
||||
|
||||
public String getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(String uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getPublicId() {
|
||||
return publicId;
|
||||
}
|
||||
|
||||
public void setPublicId(String publicId) {
|
||||
this.publicId = publicId;
|
||||
}
|
||||
|
||||
public String getTechName() {
|
||||
return techName;
|
||||
}
|
||||
|
||||
public void setTechName(String techName) {
|
||||
this.techName = techName;
|
||||
}
|
||||
|
||||
public String getUpdatePeriod() {
|
||||
return updatePeriod;
|
||||
}
|
||||
|
||||
public void setUpdatePeriod(String updatePeriod) {
|
||||
this.updatePeriod = updatePeriod;
|
||||
}
|
||||
|
||||
public OkopfAttributeModel[] getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(OkopfAttributeModel[] attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public LocalDateTime getRevisionTimestamp() {
|
||||
return revisionTimestamp;
|
||||
}
|
||||
|
||||
public void setRevisionTimestamp(LocalDateTime revisionTimestamp) {
|
||||
this.revisionTimestamp = revisionTimestamp;
|
||||
}
|
||||
|
||||
public String getKeyAttributeUid() {
|
||||
return keyAttributeUid;
|
||||
}
|
||||
|
||||
public void setKeyAttributeUid(String keyAttributeUid) {
|
||||
this.keyAttributeUid = keyAttributeUid;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ClassifierOrgModel{" +
|
||||
"uid='" + uid + '\'' +
|
||||
", code='" + code + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", version='" + version + '\'' +
|
||||
", publicId='" + publicId + '\'' +
|
||||
", techName='" + techName + '\'' +
|
||||
", updatePeriod='" + updatePeriod + '\'' +
|
||||
", attributes=" + Arrays.toString(attributes) +
|
||||
", revisionTimestamp=" + revisionTimestamp +
|
||||
", keyAttributeUid='" + keyAttributeUid + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -8,23 +8,36 @@ import java.io.Serializable;
|
|||
public class OkopfRecordModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String attributeUid;
|
||||
private String code;
|
||||
|
||||
private String value;
|
||||
private String name;
|
||||
|
||||
public String getAttributeUid() {
|
||||
return attributeUid;
|
||||
public OkopfRecordModel(String code, String name) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setAttributeUid(String attributeUid) {
|
||||
this.attributeUid = attributeUid;
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OkopfRecordModel{" +
|
||||
"code='" + code + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
package ervu.service.scheduer;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.List;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import ervu.client.classified.EsnsiOkopfClient;
|
||||
import ervu.dao.classifier.OkopfAttributeDao;
|
||||
import ervu.dao.classifier.OkopfRecordDao;
|
||||
import ervu.service.classifier.model.OkopfAttributeModel;
|
||||
import ervu.service.classifier.model.OkopfFormDataModel;
|
||||
import ervu.service.classifier.model.OkopfGroupRecordModel;
|
||||
import ervu.service.classifier.model.OkopfRecordModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -23,32 +22,44 @@ public class EsnsiOkopfSchedulerServiceImpl implements EsnsiOkopfSchedulerServic
|
|||
@Autowired
|
||||
private EsnsiOkopfClient esnsiOkopfClient;
|
||||
@Autowired
|
||||
private OkopfAttributeDao okopfAttributeDao;
|
||||
@Autowired
|
||||
private OkopfRecordDao okopfRecordDao;
|
||||
@Autowired
|
||||
private ObjectMapper mapper;
|
||||
|
||||
@Scheduled(cron = "${ervu.esnsi.okopf.cron:0 0 */1 * * *}")
|
||||
@Scheduled(cron = "${esnsi.okopf.cron:0 0 */1 * * *}")
|
||||
@Transactional
|
||||
public void load() {
|
||||
String data = esnsiOkopfClient.getJsonOkopFormData();
|
||||
try {
|
||||
String json = Objects.requireNonNull(esnsiOkopfClient.getJsonOkopFormData());
|
||||
OkopfFormDataModel classifierFormModel = mapper.readValue(json, OkopfFormDataModel.class);
|
||||
OkopfAttributeModel[] okopfAttributeModels = classifierFormModel.getOkopfOrg()
|
||||
.getAttributes();
|
||||
OkopfGroupRecordModel[] recordModels = classifierFormModel.getOkopfNode().getOkopfGroups();
|
||||
String currentVersion = classifierFormModel.getOkopfOrg().getVersion();
|
||||
var newVersion = Integer.parseInt(classifierFormModel.getOkopfOrg().getVersion());
|
||||
var versionFromDb = Integer.parseInt(okopfRecordDao.fetchVersion());
|
||||
|
||||
okopfAttributeDao.save(okopfAttributeModels);
|
||||
okopfRecordDao.save(recordModels, currentVersion);
|
||||
|
||||
if (versionFromDb != 0 && versionFromDb < newVersion) {
|
||||
okopfRecordDao.deleteAllByVersion(String.valueOf(versionFromDb));
|
||||
okopfAttributeDao.deleteIfNotExistRecords();
|
||||
List<OkopfRecordModel> okopfRecords = mapToOkopfRecords(data);
|
||||
int currentVersion = mapper.readTree(data).findValue("version").asInt();
|
||||
okopfRecordDao.save(okopfRecords, currentVersion);
|
||||
}
|
||||
catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private List<OkopfRecordModel> mapToOkopfRecords(String data) {
|
||||
try {
|
||||
JsonNode nodes = mapper.readTree(data).at("/data/records");
|
||||
return StreamSupport.stream(nodes.spliterator(), false).map(it -> {
|
||||
JsonNode attributeValues = it.get("attributeValues");
|
||||
String code = null;
|
||||
String name = null;
|
||||
for (JsonNode record : attributeValues) {
|
||||
String value = record.get("value").asText();
|
||||
if (value.matches("\\d+")) {
|
||||
code = value;
|
||||
}
|
||||
else {
|
||||
name = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new OkopfRecordModel(code, name);
|
||||
})
|
||||
.toList();
|
||||
}
|
||||
catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
|||
|
|
@ -6,25 +6,12 @@
|
|||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
|
||||
|
||||
<changeSet id="create-table-classifier_attributes" author="a.khakimullin">
|
||||
<sql>
|
||||
CREATE TABLE okopf_attributes
|
||||
(
|
||||
okopf_attribute_id uuid primary key,
|
||||
attribute_name varchar unique
|
||||
);
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="create-table-record-attributes" author="a.khakimullin">
|
||||
<sql>
|
||||
CREATE TABLE okopf_records
|
||||
(
|
||||
okopf_record_id bigserial primary key,
|
||||
record_id uuid not null,
|
||||
attribute_id uuid not null references okopf_attributes (okopf_attribute_id),
|
||||
value varchar,
|
||||
version varchar not null,
|
||||
CONSTRAINT uni_record_uid_attribute_uid UNIQUE (record_id, attribute_id)
|
||||
okopf_records_id varchar primary key,
|
||||
name varchar unique,
|
||||
version int not null
|
||||
);
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
|
|
|||
|
|
@ -676,6 +676,13 @@ JBPM использует 3 корневых категории логирова
|
|||
<level name="TRACE"/>
|
||||
</logger>
|
||||
```
|
||||
# Взаимодействие с ЕСНСИ в части получения справочника ОКОПФ
|
||||
|
||||
Свойства задаются в файле config/standalone/dev/standalone.xml
|
||||
|
||||
## Параметры
|
||||
- `esnsi.okopf.cron.load` - указываем расписание для загрузки справочника окопф и сохранения данных по справкам в БД
|
||||
- `esnsi.okopf.url` - url который обращается к еснси для получения справочника окопф и скачивает данные спровочников организации в виде заархивированного json файл.
|
||||
|
||||
# Описание параметров конфигурации клиентской части
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@
|
|||
<property name="ervu.fileupload.max_file_size" value="5242880"/>
|
||||
<property name="ervu.fileupload.max_request_size" value="6291456"/>
|
||||
<property name="ervu.fileupload.file_size_threshold" value="0"/>
|
||||
<property name="ervu.cron.load.time" value="0 0 */1 * * *"/>
|
||||
<property name="ervu.esnsi.classifier.url.load" value="https://esnsi.gosuslugi.ru/rest/ext/v1/classifiers/11465/file?extension=JSON&encoding=UTF_8"/>
|
||||
<property name="esnsi.okopf.cron.load" value="0 0 */1 * * *"/>
|
||||
<property name="esnsi.okopf.url" value="https://esnsi.gosuslugi.ru/rest/ext/v1/classifiers/11465/file?extension=JSON&encoding=UTF_8"/>
|
||||
</system-properties>
|
||||
<management>
|
||||
<audit-log>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue