package Ġio . must el id ae . ot ter . ne ot rop ical . api . domain . cancel Ċ Ċ import Ġio . must el id ae . ot ter . ne ot rop ical . api . common . Error Ċ import Ġio . must el id ae . ot ter . ne ot rop ical . api . common . ErrorCode Ċ import Ġio . must el id ae . ot ter . ne ot rop ical . api . config . Policy Exception Ċ import Ġio . must el id ae . ot ter . ne ot rop ical . api . domain . booking . Booking Finder Ċ import Ġio . must el id ae . ot ter . ne ot rop ical . api . domain . booking . reps it ory . Booking Repository Ċ import Ġio . must el id ae . ot ter . ne ot rop ical . api . domain . order . Order Sheet Finder Ċ import Ġio . must el id ae . ot ter . ne ot rop ical . api . domain . payment . Pay Way Handler Ċ import Ġio . must el id ae . ot ter . ne ot rop ical . api . domain . vertical . Vertical Handler Ċ import Ġorg . bson . types . ObjectId Ċ import Ġorg . springframework . stereotype . Service Ċ import Ġorg . springframework . transaction . annotation . Transactional Ċ Ċ @ Suppress (" D uplicated Code ") Ċ @ Service Ċ @ Transactional Ċ class ĠItem Cancel Interaction ( ĊĠĠĠ Ġprivate Ġval Ġbooking Finder : ĠBook ing Finder , ĊĠĠĠ Ġprivate Ġval Ġbooking Repository : ĠBook ing Repository , ĊĠĠĠ Ġprivate Ġval Ġvertical Handler : ĠVertical Handler , ĊĠĠĠ Ġprivate Ġval Ġpay Way Handler : ĠPay Way Handler , ĊĠĠĠ Ġprivate Ġval Ġorder Sheet Finder : ĠOrder Sheet Finder , Ċ ) Ġ{ ĊĊĠĠĠ Ġfun Ġcancel ( booking Id : ĠLong , Ġitems : ĠList < Long >, Ġcause : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbooking Ġ= Ġbooking Finder . findOne With Item ( booking Id ) ĊĠĠĠĠĠĠĠ Ġval ĠuserId Ġ= Ġbooking . userId ĊĠĠĠĠĠĠĠ Ġval ĠorderId Ġ= ĠObjectId ( booking . orderId ) ĊĠĠĠĠĠĠĠ Ġval Ġvertical Client Ġ= Ġvertical Handler . getClient ( booking . product Code ) ĊĠĠĠĠĠĠĠ Ġval Ġorder Sheet Ġ= Ġorder Sheet Finder . findOne OrThrow ( orderId ) ĊĠĠĠĠĠĠĠ Ġval Ġvertical Booking Ġ= Ġvertical Handler . get Booking ( order Sheet , ĠlistOf ( booking )) ĊĊĠĠĠĠĠĠĠ Ġval Ġcall Of Item Ġ= Ġvertical Client . ask Item Call Off ( userId , Ġbooking Id , Ġitems ) ĊĠĠĠĠĠĠĠ Ġif Ġ( call Of Item . is Possible . not ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠPolicy Exception ( Error ( ErrorCode . PL 0 3 , Ġcall Of Item . imp ossible Reason Ġ?: Ġ" Cancellation Ġis Ġnot Ġpossible .")) ĊĊĠĠĠĠĠĠĠ Ġvertical Booking . cancel By Item ( booking Id , Ġitems , Ġcause ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpartial Cancel Amount Ġ= Ġbooking . items ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġitems . contains ( it . id !! ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. sum Of Ġ{ Ġit . getTotal Price () Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġcancel Fee Ġ= Ġcall Of Item . cancel Fee ĊĠĠĠĠĠĠĠ Ġval Ġpay Way Ġ= Ġpay Way Handler . get Pay Way ( booking . payment !! ) ĊĊĠĠĠĠĠĠĠ Ġif Ġ( cancel Fee Ġ!= Ġ 0 L ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpay Way . cancel Partial With Pen alty ( cause , Ġpartial Cancel Amount , Ġcancel Fee ) ĊĠĠĠĠĠĠĠ Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpay Way . cancel Partial ( cause , Ġpartial Cancel Amount ) ĊĊĠĠĠĠĠĠĠ Ġbooking Repository . save ( booking ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġcancel With Out Call Off ( booking Id : ĠLong , Ġitems : ĠList < Long >, Ġcause : ĠString , Ġcancel Fee : ĠLong ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbooking Ġ= Ġbooking Finder . findOne With Item ( booking Id ) ĊĠĠĠĠĠĠĠ Ġval ĠorderId Ġ= ĠObjectId ( booking . orderId ) ĊĊĠĠĠĠĠĠĠ Ġval Ġorder Sheet Ġ= Ġorder Sheet Finder . findOne OrThrow ( orderId ) ĊĠĠĠĠĠĠĠ Ġval Ġvertical Booking Ġ= Ġvertical Handler . get Booking ( order Sheet , ĠlistOf ( booking )) ĊĊĠĠĠĠĠĠĠ Ġvertical Booking . cancel By Item ( booking Id , Ġitems , Ġcause ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpartial Cancel Amount Ġ= Ġbooking . items ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġitems . contains ( it . id !! ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. sum Of Ġ{ Ġit . getTotal Price () Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġpay Way Ġ= Ġpay Way Handler . get Pay Way ( booking . payment !! ) ĊĊĠĠĠĠĠĠĠ Ġif Ġ( cancel Fee Ġ!= Ġ 0 L ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpay Way . cancel Partial With Pen alty ( cause , Ġpartial Cancel Amount , Ġcancel Fee ) ĊĠĠĠĠĠĠĠ Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpay Way . cancel Partial ( cause , Ġpartial Cancel Amount ) ĊĊĠĠĠĠĠĠĠ Ġbooking Repository . save ( booking ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġforce Cancel Without Vertical Sh aking ( booking Id : ĠLong , Ġitems : ĠList < Long >, Ġcause : ĠString , Ġcancel Fee : ĠLong ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbooking Ġ= Ġbooking Finder . findOne With Item ( booking Id ) ĊĠĠĠĠĠĠĠ Ġval ĠorderId Ġ= ĠObjectId ( booking . orderId ) ĊĊĠĠĠĠĠĠĠ Ġval Ġorder Sheet Ġ= Ġorder Sheet Finder . findOne OrThrow ( orderId ) ĊĠĠĠĠĠĠĠ Ġval Ġvertical Booking Ġ= Ġvertical Handler . get Booking Use DoNot ing Vertical Client ( order Sheet , ĠlistOf ( booking )) ĊĠĠĠĠĠĠĠ Ġvertical Booking . cancel By Item ( booking Id , Ġitems , Ġcause ) ĊĊĠĠĠĠĠĠĠ Ġval Ġpartial Cancel Amount Ġ= Ġbooking . items ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġitems . contains ( it . id !! ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. sum Of Ġ{ Ġit . getTotal Price () Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġpay Way Ġ= Ġpay Way Handler . get Pay Way ( booking . payment !! ) ĊĠĠĠĠĠĠĠ Ġif Ġ( cancel Fee Ġ!= Ġ 0 L ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpay Way . cancel Partial With Pen alty ( cause , Ġpartial Cancel Amount , Ġcancel Fee ) ĊĠĠĠĠĠĠĠ Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpay Way . cancel Partial ( cause , Ġpartial Cancel Amount ) ĊĊĠĠĠĠĠĠĠ Ġbooking Repository . save ( booking ) ĊĠĠĠ Ġ} Ċ } Ċ