Skip to content

Instantly share code, notes, and snippets.

@stdray
Created October 30, 2015 14:41
Show Gist options
  • Select an option

  • Save stdray/73bbef9d266717e15996 to your computer and use it in GitHub Desktop.

Select an option

Save stdray/73bbef9d266717e15996 to your computer and use it in GitHub Desktop.
[Mapping]
public class ProtocolMapper : MapperBase
{
#region Классы
class OfferResultType
{
public Result : OfferTypeMainInfoResult? { get; set; }
public AppRating : decimal? { get;set; }
public IsRejected : bool? { get; set; }
public RejectedReason : ReasonType { get; set }
public Unconsidered : bool? { get;set; }
}
#endregion
#region Протокол
[NamedOverloads(src, zfcs_protocolEF1Type
, zfcs_protocolEF2Type
, zfcs_protocolEF3Type
, zfcs_protocolEFInvalidationType
, zfcs_protocolEFSingleAppType
, zfcs_protocolEFSinglePartType
, zfcs_protocolEvasionType
, zfcs_protocolDeviationType
, zfcs_protocolOK1Type
, zfcs_protocolOK2Type
, zfcs_protocolOKD1Type
, zfcs_protocolOKD2Type
, zfcs_protocolOKD3Type
, zfcs_protocolOKD4Type
, zfcs_protocolOKD5Type
, zfcs_protocolOKDSingleAppType
, zfcs_protocolOKOU1Type
, zfcs_protocolOKOU2Type
, zfcs_protocolOKOU3Type
, zfcs_protocolOKOUSingleAppType
, zfcs_protocolOKSingleAppType
, zfcs_protocolPOType
, zfcs_protocolZKType
, zfcs_protocolZKAfterProlongType
, zfcs_protocolZPType
, zfcs_protocolZPExtractType
, zfcs_protocolZPFinalType)]
public Protocol(src : zfcs_protocolZPType) : ProtocolType
{
entity <-
{
AbandonedLots = typeOf match(src)
{
| zfcs_protocolEF1Type
| zfcs_protocolEF3Type
| zfcs_protocolEFInvalidationType
| zfcs_protocolEFSingleAppType
| zfcs_protocolZKType
| zfcs_protocolZKAfterProlongType
| zfcs_protocolZKBIAfterProlongType
| zfcs_protocolZKBIType
| zfcs_protocolZPType
| zfcs_protocolZPFinalType
| zfcs_protocolZPExtractType =>
def reason = src.protocolLot?.abandonedReason;
collection entity when(reason != null) <-
{
AbandonedReason <-
{
Reason = reason.code;
ReasonInfo = reason.name;
}
LotNumber = str(1);
}
| _ => null;
}
Attachments =
from a in src.attachments
select attachment(a);
Commission = typeOf match(src)
{
| zfcs_protocolEvasionType
| zfcs_protocolZPExtractType => null
| _ => entity when(src.commission != null) <-
{
def com = src.commission;
AdditionInfo = com.addInfo;
CommissionMembers =
from m in com.commissionMembers?.commissionMember
select entity <-
{
IsVoted = m.role.rightVote == true;
MemberFio = $"$(m.lastName) $(m.firstName) $(m.middleName)";
MemberRole = m.role.name;
}
IsСompetence = nullable(com.competent);
Name = com.commissionName;
}
}
ExternalLinks = entity when(src.foundationProtocolNumber != null) <-
{
FoundationProtocolIdentity = src.foundationProtocolNumber;
}
IdentityInfo <-
{
ProtocolIdentity = businessKey(src.purchaseNumber, src.protocolNumber);
TenderIdentity = src.purchaseNumber;
}
MainInfo <-
{
ProtocolDate = date(src.protocolDate);
SignDate = date(src.signDate);
def protocolType = typeOf match(src)
{
| zfcs_protocolOKOU1Type
| zfcs_protocolOK1Type
| zfcs_protocolOKD1Type
| zfcs_protocolOKD4Type => ProtocolTypeMainInfoProtocolType.ProtocolOpening;
| zfcs_protocolEF2Type
| zfcs_protocolZPType => ProtocolTypeMainInfoProtocolType.ProtocolExecuting;
| zfcs_protocolEFInvalidationType => ProtocolTypeMainInfoProtocolType.ProtocolTenderInvalidation;
| zfcs_protocolEvasionType
| zfcs_protocolDeviationType => ProtocolTypeMainInfoProtocolType.ProtocolContractRefusal;
| zfcs_protocolOKD3Type => ProtocolTypeMainInfoProtocolType.ProtocolDiscussion;
| zfcs_protocolEF1Type
| zfcs_protocolEFSingleAppType
| zfcs_protocolOKOU2Type
| zfcs_protocolOKD2Type
| zfcs_protocolZPExtractType => ProtocolTypeMainInfoProtocolType.ProtocolAdmission;
| zfcs_protocolEF3Type
| zfcs_protocolEFSinglePartType
| zfcs_protocolOK2Type
| zfcs_protocolOKSingleAppType
| zfcs_protocolOKOU3Type
| zfcs_protocolOKOUSingleAppType
| zfcs_protocolOKD5Type
| zfcs_protocolOKDSingleAppType
| zfcs_protocolZKType
| zfcs_protocolZKAfterProlongType
| zfcs_protocolZKBIAfterProlongType
| zfcs_protocolZKBIType
| zfcs_protocolPOType
| zfcs_protocolZPFinalType => ProtocolTypeMainInfoProtocolType.ProtocolFinal;
}
ProtocolType = nullable(protocolType);
}
OptionalInfo <-
{
PlaceInfo = src.place;
ProtocolKindInfo = src.GetType().Name;
}
PublishInfo <-
{
Date = date(src.publishDate);
ModificationInfo = src.modification?.info;
Url = src.href;
Version = str(src.modification?.modificationNumber);
}
}
}
[NamedOverloads(src, zfcs_protocolZKBIType
, zfcs_protocolZKBIAfterProlongType)]
public Protocol(src : zfcs_protocolZKBIAfterProlongType) : ProtocolType
{
entity <-
{
Attachments = typeOf match(src)
{
| zfcs_protocolZKBIAfterProlongType => null
| zfcs_protocolZKBIType => from a in src.attachments select attachment(a);
}
IdentityInfo <-
{
ProtocolIdentity = src.purchaseNumber;
TenderIdentity = src.purchaseNumber;
}
MainInfo <-
{
SignDate = date(src.signDate);
ProtocolType = nullable(ProtocolTypeMainInfoProtocolType.ProtocolFinal);
}
PublishInfo <-
{
Date = date(src.docPublishDate);
ModificationInfo = src.modification?.info;
Url = src.href;
Version = str(src.modification?.modificationNumber);
}
}
}
public ProtocolCancel(protocol : ProtocolType, cancel : zfcs_protocolCancelType) : ProtocolType
{
protocol <<-
{
CancelInfo <-
{
CancelledDate = date(cancel.docPublishDate);
CancelledReason <-
{
ReasonInfo = cancel.addInfo;
Reason = cancelReason(cancel.cancelReason);
}
}
}
}
#endregion
#region Оффер
[NamedOverloads(src, zfcs_protocolEF1Type
, zfcs_protocolEF2Type
, zfcs_protocolEF3Type
//, zfcs_protocolEFInvalidationType
, zfcs_protocolEFSingleAppType
, zfcs_protocolEFSinglePartType
, zfcs_protocolDeviationType
, zfcs_protocolEvasionType
, zfcs_protocolOK1Type
, zfcs_protocolOK2Type
, zfcs_protocolOKD1Type
, zfcs_protocolOKD2Type
, zfcs_protocolOKD3Type
, zfcs_protocolOKD4Type
, zfcs_protocolOKD5Type
, zfcs_protocolOKDSingleAppType
, zfcs_protocolOKOU1Type
, zfcs_protocolOKOU2Type
, zfcs_protocolOKOU3Type
, zfcs_protocolOKOUSingleAppType
, zfcs_protocolOKSingleAppType
, zfcs_protocolPOType
, zfcs_protocolZKType
, zfcs_protocolZKAfterProlongType
, zfcs_protocolZPType
, zfcs_protocolZPExtractType
, zfcs_protocolZPFinalType
, zfcs_protocolZKBIType)]
public Offer(src : zfcs_protocolOKD3Type) : array[OfferType]
{
def lots = typeOf match(src)
{
| zfcs_protocolEF1Type
| zfcs_protocolEF2Type
| zfcs_protocolEF3Type
| zfcs_protocolPOType
| zfcs_protocolZKType
| zfcs_protocolZKAfterProlongType
| zfcs_protocolZKBIType
| zfcs_protocolZPType
| zfcs_protocolZPExtractType
| zfcs_protocolZPFinalType
| zfcs_protocolEFSingleAppType
| zfcs_protocolEFSinglePartType
| zfcs_protocolDeviationType
| zfcs_protocolEvasionType => collection (str(1), src.protocolLot);
| zfcs_protocolOK1Type
| zfcs_protocolOK2Type
| zfcs_protocolOKD1Type
| zfcs_protocolOKD2Type
| zfcs_protocolOKD3Type
| zfcs_protocolOKD4Type
| zfcs_protocolOKD5Type
| zfcs_protocolOKOU1Type
| zfcs_protocolOKOU2Type
| zfcs_protocolOKOU3Type
| zfcs_protocolOKDSingleAppType
| zfcs_protocolOKOUSingleAppType
| zfcs_protocolOKSingleAppType => from lot in src.protocolLots
select (str(lot.lotNumber), lot);
}
from ((lotNumber, lot) in lots,
app in typeOf match(src)
{
| zfcs_protocolEF1Type
| zfcs_protocolEF2Type
| zfcs_protocolEF3Type
| zfcs_protocolPOType
| zfcs_protocolZKType
| zfcs_protocolZKAfterProlongType
| zfcs_protocolZKBIType
| zfcs_protocolZPType
| zfcs_protocolZPExtractType
| zfcs_protocolZPFinalType
| zfcs_protocolOK1Type
| zfcs_protocolOK2Type
| zfcs_protocolOKD1Type
| zfcs_protocolOKD2Type
| zfcs_protocolOKD4Type
| zfcs_protocolOKD5Type
| zfcs_protocolOKOU1Type
| zfcs_protocolOKOU2Type
| zfcs_protocolOKOU3Type => lot.applications;
| zfcs_protocolEFSingleAppType
| zfcs_protocolEFSinglePartType
| zfcs_protocolDeviationType
| zfcs_protocolEvasionType
| zfcs_protocolOKDSingleAppType
| zfcs_protocolOKOUSingleAppType
| zfcs_protocolOKSingleAppType => collection lot.application;
| zfcs_protocolOKD3Type => lot.applications.application;
})
select entity <-
{
IdentityInfo <-
{
LotNumber = lotNumber;
OfferNumber = app.journalNumber;
TenderIdentity = src.purchaseNumber;
}
def appResult : OfferResultType = typeOf match(src)
{
| zfcs_protocolEF1Type
| zfcs_protocolEFSingleAppType
| zfcs_protocolEFSinglePartType => entity <-
{
def r = app.ItemsChoice.First();
def c1 = r.admitted;
def c2 = r.appRejectedReason;
}
| zfcs_protocolEF3Type => entity <-
{
def r = app.ItemsChoice.First();
def c1 = r.admitted;
def c3 = r.appRejectedReason;
def c2 = r.notConsidered;
}
| zfcs_protocolOK2Type
| zfcs_protocolOKD5Type
| zfcs_protocolOKOU3Type => entity <-
{
def x = app.unconsidered;
def r = app.admittedInfo.ItemsChoice.First();
def c1 = r.admitted;
def c2 = r.appRejectedReason;
def c3 = r.appRating;
def c4 = r.conditionsScoring;
def c5 = r.score;
}
| zfcs_protocolOKSingleAppType
| zfcs_protocolOKDSingleAppType
| zfcs_protocolOKOUSingleAppType => entity <-
{
def x = app.unconsidered;
def r = app.admittedInfo.ItemsChoice.First();
def c1 = r.admitted;
def c2 = r.appRejectedReason;
}
| zfcs_protocolOKD2Type
| zfcs_protocolOKOU2Type=> entity <-
{
def x = app.unconsidered;
IsRejected = not(app.admittedInfo);
Unconsidered = app.unconsidered;
}
| zfcs_protocolOKD3TypeProtocolLotApplicationsApplication => entity <-
{
IsRejected = not(app.admittedInfo);
}
| zfcs_protocolZKType
| zfcs_protocolZKAfterProlongType
| zfcs_infoProtocolZKBIType =>
def result = entity;
def item = app.admittedInfo.ItemsChoice.SingleOrDefault();
if(item != null)
choice(item)
{
when(item.appRejectedReason(r)) result <<-
{
RejectedReason <-
{
Reason = r.nsiRejectReason.reason;
ReasonInfo = r.explanation;
}
}
when(item.resultType(r)) result <<-
{
Result = nullable(mapResult(r));
}
}
else result;
| zfcs_protocolPOType =>
def result = entity;
def item = app.admittedInfo.ItemsChoice.SingleOrDefault();
if(item != null)
choice(item)
{
when(item.appRejectedReason(r)) result <<-
{
RejectedReason <-
{
Reason = r.nsiRejectReason.reason;
ReasonInfo = r.explanation;
}
}
// <xs:element name="included" type="xs:boolean" fixed="true">
// <xs:annotation>
// <xs:documentation>Включение участника в перечень поставщиков </xs:documentation>
// </xs:annotation>
//</xs:element>
when(item.included(r)) result <<-
{
def x = r;
}
}
else result;
| zfcs_protocolZPType
| zfcs_protocolZPFinalType => entity <-
{
AppRating = decimal'(app.appRating);
}
| zfcs_protocolZPExtractType => entity <-
{
def x = app.appRejectedReason;
}
| zfcs_protocolEvasionType
| zfcs_protocolDeviationType => entity <-
{
IsRejected = nullable(true);
AppRating = decimal'(app.appRating);
}
| _ => entity;
};
MainInfo <-
{
Currency = typeOf match(src)
{
| zfcs_protocolEF1Type
| zfcs_protocolEF2Type
| zfcs_protocolEF3Type
| zfcs_protocolEFSingleAppType
| zfcs_protocolEFSinglePartType => null;
| _ => lot.lotInfo?.currency?.code;
}
IsInconsistent = typeOf match(src)
{
| zfcs_protocolOK2Type
| zfcs_protocolOKSingleAppType
| zfcs_protocolOKOU3Type
| zfcs_protocolOKOUSingleAppType
| zfcs_protocolOKOU2Type
| zfcs_protocolOKD5Type
| zfcs_protocolOKDSingleAppType
| zfcs_protocolZKType
| zfcs_protocolZKAfterProlongType
| zfcs_infoProtocolZKBIType
| zfcs_protocolPOType
| zfcs_protocolZPType => nullable(app.correspondencies?.Any(x => x.compatible == false));
| _ => null
};
IsCustomerRefusal = typeOf match(src)
{
| zfcs_protocolEvasionType => nullable(true);
| _ => null;
}
IsRejected = appResult.IsRejected;
IsUnconsidered = appResult.Unconsidered;
OfferedPrice = typeOf match(src)
{
| zfcs_protocolOK2Type
| zfcs_protocolOKSingleAppType
| zfcs_protocolOKOU3Type
| zfcs_protocolOKOUSingleAppType
| zfcs_protocolOKD5Type
| zfcs_protocolOKDSingleAppType => decimal'(app.offerPrice);
| _ => null;
}
Rank = appResult.AppRating;
Result = appResult.Result;
SubmissionDate = typeOf match(src)
{
| zfcs_protocolEF2Type
| zfcs_protocolEF3Type => null;
| _ => date(app.appDate);
}
}
OptionalInfo <-
{
AuctionFirstOfferedPrice = typeOf match(src)
{
| zfcs_protocolEF2Type => decimal'(app.priceOffers.firstOffer.price);
| _ => null;
}
CustomerRefusalReason = typeOf match(src)
{
| zfcs_protocolEvasionType => entity <-
{
Reason = cancelReason(src.modification.reason);
ReasonInfo = src.modification.info;
}
| _ => null;
}
RejectedReason = appResult.RejectedReason;
}
Participants = typeOf match(src)
{
| zfcs_protocolEF3Type
| zfcs_protocolEFSingleAppType
| zfcs_protocolEFSinglePartType
| zfcs_protocolZKType
| zfcs_protocolZKAfterProlongType
| zfcs_infoProtocolZKBIType
| zfcs_protocolPOType
| zfcs_protocolZPType
| zfcs_protocolZPFinalType
| zfcs_protocolZPExtractType => collection offerParticipant(app.appParticipant)
| zfcs_protocolEvasionTypeProtocolLotApplication
| zfcs_protocolOK1TypeProtocolLotApplication
| zfcs_protocolOK2TypeProtocolLotApplication
| zfcs_protocolOKD1TypeProtocolLotApplication
| zfcs_protocolOKD2TypeProtocolLotApplication
| zfcs_protocolOKD4TypeProtocolLotApplication
| zfcs_protocolOKD5TypeProtocolLotApplication
| zfcs_protocolOKDSingleAppTypeProtocolLotApplication
| zfcs_protocolOKOU1TypeProtocolLotApplication
| zfcs_protocolOKOU2TypeProtocolLotApplication
| zfcs_protocolOKOU3TypeProtocolLotApplication
| zfcs_protocolOKOUSingleAppTypeProtocolLotApplication
| zfcs_protocolOKSingleAppTypeProtocolLotApplication
| zfcs_protocolOKD3TypeProtocolLotApplicationsApplication
| zfcs_protocolDeviationTypeProtocolLotApplication => from p in src.appParticipants
select offerParticipant(p)
| _ => null;
}
}
}
public OffersCancel(_ : array[OfferType], _ : zfcs_protocolCancelType) : array[OfferType]
{
array(0)
}
public OffersInvalidation(offers : array[OfferType], invalidation : zfcs_protocolEFInvalidationType) : array[OfferType]
{
from offer in offers
select offer <<-
{
MainInfo <-
{
IsRejected = true;
}
OptionalInfo <-
{
RejectedReason = entity when(invalidation.modification != null) <-
{
Reason = invalidation.modification.info;
ReasonInfo = invalidation.modification.addInfo;
}
}
}
}
#endregion
mapResult(r : zfcs_admissionResultsEnum) : OfferTypeMainInfoResult
{
| zfcs_admissionResultsEnum.LIKE_WIN_OFFER => OfferTypeMainInfoResult.LikeWinner;
| zfcs_admissionResultsEnum.PASS_OFFER
| zfcs_admissionResultsEnum.ADMITTED_OFFER => OfferTypeMainInfoResult.Bidder;
| zfcs_admissionResultsEnum.WIN_OFFER => OfferTypeMainInfoResult.Winner;
| zfcs_admissionResultsEnum.SECOND_OFFER => OfferTypeMainInfoResult.Second;
}
mapRaiting(r : zfcs_admissionResultsEnum) : decimal?
{
| zfcs_admissionResultsEnum.LIKE_WIN_OFFER => 2;
| zfcs_admissionResultsEnum.PASS_OFFER
| zfcs_admissionResultsEnum.ADMITTED_OFFER => null;
| zfcs_admissionResultsEnum.WIN_OFFER => 1;
| zfcs_admissionResultsEnum.SECOND_OFFER => 2;
}
offerParticipant([Null]src : zfcs_participantType) : OfferTypeParticipant
{
def part = participant(src);
entity <-
{
IdentityInfo = part.IdentityInfo;
Person = part.Person;
PersonContacts = part.PersonContacts;
Role = role(src.participantType);
}
}
role(_src : zfcs_participantTypeEnum) : OfferTypeParticipantRole
{
OfferTypeParticipantRole.Supplier;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment