Skip to content

Commit

Permalink
Read persons sovm flag for 1c import
Browse files Browse the repository at this point in the history
  • Loading branch information
uralm1 committed Apr 18, 2022
1 parent 01708f1 commit 2904973
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file.

## [Unreleased]
- Чтение информации о видах занятости из 1C. Определение сотрудников с Внутренним Совместительством.
-

## [1.22] - 2022-04-18
- Исправление проблем с буквами 'Ёё' в именах сотрудников и наименованиях подразделений.
Expand Down
5 changes: 5 additions & 0 deletions lib/Adup/Plugin/Migrations.pm
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,8 @@ CREATE TABLE IF NOT EXISTS `_fio_otd_dedup` (
DROP TABLE IF EXISTS `_fio_dedup`;
DROP TABLE IF EXISTS `_fio_otd_dedup`;
-- 8 up
ALTER TABLE `persons` ADD `sovm` TINYINT(3) UNSIGNED NOT NULL AFTER `dup`;
-- 8 down
5 changes: 3 additions & 2 deletions lib/Adup/Task/Preprocess.pm
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ sub _process_dbf {
process_dept_a(\%path_id_h, \%id_dept_h, \$id_gen_val, split(/\\/, $otdel));

$e = eval {
$db_adup->query("INSERT INTO persons (gal_id, fio, dup, f, i, o, dept_id, flatdept_id, otdel, dolj, tabn) \
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
$db_adup->query("INSERT INTO persons (gal_id, fio, dup, sovm, f, i, o, dept_id, flatdept_id, otdel, dolj, tabn) \
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
$id,
$fio,
0, #v1.7 must be 0, some will update later
0, # sovm, not used for galaktika import
$fio_f, $fio_i, $fio_o,
$path_id_h{$otdel},
$flatdept_dedup_h{$otdel},
Expand Down
42 changes: 40 additions & 2 deletions lib/Adup/Ural/ZupLoader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sub new {
#$self->{url_base}
#$self->{org_key}
#$self->{si}
#$self->{sovm_hash}
#$self->{kis_array}

#timeouts
Expand Down Expand Up @@ -125,6 +126,37 @@ sub read_si {
}


# load 'ВидыЗанятости' information register into sovm_hash attribute
# returns a number of loaded records on success,
# dies on errors.
sub read_vzs {
my $self = shift;
croak 'Org key is not loaded!' unless $self->{org_key};

my $now = strftime '%Y-%m-%dT%H:%M:%S', localtime;

# Перечисление.ВидыЗанятости
my $vnsovm_zan = 'ВнутреннееСовместительство';

my $obj = "InformationRegister_ВидыЗанятостиСотрудниковИнтервальный";
my $select = 'ДатаОкончания,ДатаНачала,Сотрудник_Key,ФизическоеЛицо_Key,ВидЗанятости,ДействуетДо';
my $filter = "ГоловнаяОрганизация_Key eq guid'$self->{org_key}' and ДатаОкончания gt datetime'$now' and ДатаНачала le datetime'$now' and ВидЗанятости eq '$vnsovm_zan'";
my $top = undef;

my $url_vzs = Mojo::URL->new($obj)->to_abs($self->{url_base})->query({'$select'=>$select, '$filter'=>$filter, '$top'=>$top});
#say $url_vzs->to_unsafe_string;

my $vzs_array = $self->read_url($url_vzs);
my $sovm_hash = {};
$sovm_hash->{$_->{'Сотрудник_Key'}} = $_->{'ФизическоеЛицо_Key'} for @$vzs_array;
$self->{sovm_hash} = $sovm_hash;

my $cnt = scalar @{$vzs_array};
$self->get_log->info("Loaded [$obj], $cnt records.");
return $cnt;
}


# load main information register into kis_array attribute
# returns a number of loaded records on success,
# dies on errors.
Expand Down Expand Up @@ -166,6 +198,7 @@ sub upload_data {
$self->progress(5, '5% Загрузка справочников');
$self->read_si($_) for keys %{$self->{si}};
$self->progress(10, '10% Загрузка данных сотрудников');
$self->read_vzs;
$self->read_kis;
return 1;
}
Expand Down Expand Up @@ -193,6 +226,7 @@ sub process_data {
my $_fl = $self->{si}{'ФизическиеЛица'}{hash};
my $_dl = $self->{si}{'Должности'}{hash};
my $_pod = $self->{si}{'ПодразделенияОрганизаций'}{hash};
my $_sovm = $self->{sovm_hash};

my $dept_id_gen_val = 1;

Expand Down Expand Up @@ -257,12 +291,16 @@ sub process_data {
# flatdept dedup
$flatdept_dedup_h{$otdel} = $flatdept_id_gen_val++ unless exists $flatdept_dedup_h{$otdel};

# sovm
my $sovm = exists $_sovm->{$sot_key} && $_sovm->{$sot_key} eq $fl_key ? 1 : 0;

$e = eval {
$self->get_db->query("INSERT INTO persons (gal_id, fio, dup, f, i, o, dept_id, flatdept_id, otdel, dolj, tabn) \
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
$self->get_db->query("INSERT INTO persons (gal_id, fio, dup, sovm, f, i, o, dept_id, flatdept_id, otdel, dolj, tabn) \
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
$id,
$fio,
0, # must be 0, some will update later
$sovm,
$fio_f, $fio_i, $fio_o,
$_pod->{$pod_key}{_id},
$flatdept_dedup_h{$otdel},
Expand Down
5 changes: 3 additions & 2 deletions t2/preprocess.pl
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@
process_dept_a(\%path_id_h, \%id_dept_h, \$id_gen_val, split(/\\/, $otdel));

$e = eval {
$db_adup->query("INSERT INTO persons (gal_id, fio, dup, f, i, o, dept_id, flatdept_id, otdel, dolj, tabn) \
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
$db_adup->query("INSERT INTO persons (gal_id, fio, dup, sovm, f, i, o, dept_id, flatdept_id, otdel, dolj, tabn) \
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
$id,
$fio,
0, #1.7 will update later
0, # sovm, not used for galaktika import
$fio_f, $fio_i, $fio_o,
$path_id_h{$otdel},
$flatdept_dedup_h{$otdel},
Expand Down

0 comments on commit 2904973

Please sign in to comment.