FeeRuleSchemeServiceNewImpl.java 200 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546
  1. package com.ydtech.modules.fee.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.ydtech.constants.enums.dict.agreement.ProductsType;
  4. import com.ydtech.constants.enums.dict.insurance.EnergyType;
  5. import com.ydtech.constants.enums.dict.insurance.NatureOfVehicleUse;
  6. import com.ydtech.constants.enums.dict.insurance.VehicleType;
  7. import com.ydtech.exception.SystemException;
  8. import com.ydtech.modules.admin.model.SysUser;
  9. import com.ydtech.modules.admin.service.SysChannelGroupService;
  10. import com.ydtech.modules.admin.service.SysSwitchConfigService;
  11. import com.ydtech.modules.admin.service.SysUserAccountService;
  12. import com.ydtech.modules.admin.service.SysUserService;
  13. import com.ydtech.modules.esm.model.EsmRetail;
  14. import com.ydtech.modules.esm.model.EsmUserReferrer;
  15. import com.ydtech.modules.esm.service.EsmRetailService;
  16. import com.ydtech.modules.esm.service.EsmUserReferrerService;
  17. import com.ydtech.modules.fee.constants.CostAllocation;
  18. import com.ydtech.modules.fee.dto.po.InsFeeOrderConfig;
  19. import com.ydtech.modules.fee.dto.vo.ReCalcuLateProportion;
  20. import com.ydtech.modules.fee.dto.vo.RetailProportion;
  21. import com.ydtech.modules.fee.dto.vo.RuleAttrMappingVo;
  22. import com.ydtech.modules.fee.service.FeeRuleSchemeNewService;
  23. import com.ydtech.modules.fee.service.FeeRuleSchemeService;
  24. import com.ydtech.modules.fee.service.InsFeeOrderConfigService;
  25. import com.ydtech.modules.fee.service.InsFeeOrderNewHistoryService;
  26. import com.ydtech.modules.ins.model.vo.QuoteRespVo;
  27. import com.ydtech.modules.order.entity.InsAreaCompany;
  28. import com.ydtech.modules.order.entity.InsOrders;
  29. import com.ydtech.modules.order.entity.api.dajia.constants.TypeVehicleMapping;
  30. import com.ydtech.modules.order.entity.vo.ExternalOrderFeeVo;
  31. import com.ydtech.modules.order.entity.vo.FeeOrderNewVo;
  32. import com.ydtech.modules.order.entity.vo.QueryOrderFeeResultVo;
  33. import com.ydtech.modules.order.entity.vo.QueryOrderFeeVo;
  34. import com.ydtech.modules.order.service.InsOrdersService;
  35. import com.ydtech.modules.protocol.entity.po.PtlAgreement;
  36. import com.ydtech.modules.protocol.entity.po.PtlNewCarJudgeRules;
  37. import com.ydtech.modules.protocol.service.PtlAgreementService;
  38. import com.ydtech.modules.protocol.service.PtlNewCarJudgeRulesService;
  39. import com.ydtech.modules.protocols.entity.po.*;
  40. import com.ydtech.modules.protocols.entity.vo.AgreementProductCosts;
  41. import com.ydtech.modules.protocols.service.*;
  42. import com.ydtech.utils.idgen.IdGenerate;
  43. import org.slf4j.Logger;
  44. import org.slf4j.LoggerFactory;
  45. import org.springframework.beans.factory.annotation.Autowired;
  46. import org.springframework.stereotype.Service;
  47. import javax.annotation.Resource;
  48. import java.math.BigDecimal;
  49. import java.math.BigInteger;
  50. import java.math.RoundingMode;
  51. import java.text.DateFormat;
  52. import java.time.LocalDate;
  53. import java.time.LocalDateTime;
  54. import java.time.format.DateTimeFormatter;
  55. import java.util.*;
  56. import java.util.concurrent.atomic.AtomicBoolean;
  57. import java.util.stream.Collectors;
  58. /**
  59. * @author: tz
  60. * @description: 费用接口中相关功能的实现类
  61. * @create: 2024-3-1 11:45:33
  62. */
  63. @Service
  64. public class FeeRuleSchemeServiceNewImpl implements FeeRuleSchemeNewService {
  65. private static final Logger log = LoggerFactory.getLogger("fee");
  66. @Resource
  67. private InsOrdersService insOrdersService;
  68. @Resource
  69. private PtlAgreementProductCostsNewService ptlAgreementProductCostsNewService;
  70. @Resource
  71. private PtlAgreementUndwrtRulesAttrService ptlAgreementUndwrtRulesAttrService;
  72. @Resource
  73. private PtlAgreementProductCostsExportService ptlAgreementProductCostsExportService;
  74. @Resource
  75. private PtlAgreementProductCostsAttrLinkService ptlAgreementProductCostsAttrLinkService;
  76. @Resource
  77. private PtlAgreementUndwrtRulesNewService ptlAgreementUndwrtRulesNewService;
  78. @Resource
  79. private SysUserService sysUserService;
  80. @Resource
  81. private EsmRetailService esmRetailService;
  82. @Resource
  83. private InsFeeOrderNewService insFeeOrderNewService;
  84. @Autowired
  85. private EsmUserReferrerService esmUserReferrerService;
  86. @Autowired
  87. private SysUserAccountService sysUserAccountService;
  88. @Autowired
  89. private PtlNewCarJudgeRulesService ptlNewCarJudgeRulesService;
  90. @Autowired
  91. private PtlAgreementService ptlAgreementService;
  92. @Autowired
  93. private FeeRuleSchemeService feeRuleSchemeService;
  94. @Autowired
  95. private InsFeeOrderConfigService insFeeOrderConfigService;
  96. @Autowired
  97. private SysSwitchConfigService sysSwitchConfigService;
  98. @Autowired
  99. private InsFeeOrderNewHistoryService insFeeOrderNewHistoryService;
  100. @Autowired
  101. private SysChannelGroupService sysChannelGroupService;
  102. @Override
  103. public QueryOrderFeeVo queryFeeOrderInfo(String companyId) {
  104. return null;
  105. }
  106. @Override
  107. public List<QueryOrderFeeResultVo> convertOrderFeeVoData(QueryOrderFeeVo orderFeeVo) {
  108. return null;
  109. }
  110. @Override
  111. public void compareAndUpdateFeeOrderInfo(String insOrderNo, String jqCostsProportionStr, String syCostsProportionStr, String dealUser) {
  112. }
  113. /**
  114. * 校验费用因子
  115. */
  116. @Override
  117. public void verificationCostFactor(QuoteRespVo quoteRespVo, InsAreaCompany insAreaCompany, InsOrders insOrders, StringBuilder logs, boolean isInternalAgreement) {
  118. List<AgreementProductCosts> agreementProductCostsNoMatched =
  119. ptlAgreementProductCostsNewService.costsGetList(insAreaCompany.getAgreementId(), insAreaCompany.getProductid());
  120. List<AgreementProductCosts> agreementProductCosts = new ArrayList<>();
  121. //过滤费用因子 根据使用性质,能源种类,车辆种类过滤
  122. agreementProductCostsNoMatched.forEach(item->{
  123. AtomicBoolean matching = new AtomicBoolean(true);
  124. item.getCostsAttrLinks().forEach(attr->{
  125. //判断能源类型 燃油 新能源
  126. if(attr.getAttrCode().equals("NewEnergy")){
  127. //传入的能源类型
  128. String energyType = EnergyType.isNewEnergy(insOrders.getCarinfo().getString("energyType")) ? "1" : "0";
  129. if(!attr.getMin().equals(energyType)) {
  130. matching.set(false);
  131. }
  132. }
  133. //使用性质 营业 非营业
  134. if(attr.getAttrCode().equals("NatureOfUse")){
  135. String[] split = attr.getMin().split(",");
  136. boolean isPipei = false;
  137. for(int i=0;i<split.length;i++){
  138. if(split[i].equals(TypeVehicleMapping.getByCode(insOrders.getCarinfo().getString("vehicleUse")))){
  139. isPipei = true;
  140. }
  141. }
  142. if(!isPipei){
  143. matching.set(false);
  144. }
  145. }
  146. //车辆种类 客车 货车
  147. if(attr.getAttrCode().equals("CarType")){
  148. if(!attr.getMin().contains(VehicleType.getByCode(insOrders.getCarinfo().getString("cimodelclass")))){
  149. matching.set(false);
  150. }
  151. }
  152. });
  153. if(matching.get()){
  154. agreementProductCosts.add(item);
  155. }
  156. });
  157. // if(agreementProductCosts == null || agreementProductCosts.size() == 0){
  158. // throw new SystemException("协议费用因子为空");
  159. // }
  160. for (int i = 0; i < agreementProductCosts.size(); i++) {
  161. if (agreementProductCosts.get(i).getPriorityLevel() == null) {
  162. agreementProductCosts.get(i).setPriorityLevel(10);
  163. }
  164. }
  165. if (!agreementProductCosts.isEmpty()) {
  166. //按优先级进行排序
  167. Collections.sort(agreementProductCosts, Comparator.comparingInt(AgreementProductCosts::getPriorityLevel));
  168. //遍历费用因子
  169. String costsId = verificationCosts(agreementProductCosts, quoteRespVo, insAreaCompany, insOrders, logs);
  170. if (costsId != null) {
  171. calcCosts(costsId, insAreaCompany, isInternalAgreement);
  172. log.debug("费用因子校验通过,子订单id:" + insAreaCompany.getId() + ",费用id:" + costsId);
  173. }
  174. } else {
  175. logs.append("没有找到该协议的费用信息" + "\n");
  176. }
  177. }
  178. /**
  179. * 校验承保规则
  180. *
  181. * @param insAreaCompany
  182. * @param insOrders
  183. */
  184. @Override
  185. public void verificationRuleFactor(InsAreaCompany insAreaCompany, InsOrders insOrders) {
  186. List<PtlAgreementUndwrtRulesNew> ptlAgreementUndwrtRules =
  187. ptlAgreementUndwrtRulesNewService.rulesList(insAreaCompany.getAgreementId());
  188. verificationRules(ptlAgreementUndwrtRules, insAreaCompany, insOrders);
  189. }
  190. //BigDecimal取两位
  191. private BigDecimal twoPeople(BigDecimal number) {
  192. return number.setScale(2, BigDecimal.ROUND_DOWN);
  193. }
  194. /**
  195. * 重新计算分销和机构比例
  196. *
  197. * @param sumCostsProportion 总入口费用比例
  198. * @param deptProportion 机构管理总比例
  199. * @param retailProportion 默认分销总比例
  200. * @param retailLevel 分销级别
  201. * @return 如果不够减则 返回新的分销比例
  202. */
  203. public ReCalcuLateProportion recalculateProportion(BigDecimal sumCostsProportion,
  204. BigDecimal deptProportion,
  205. BigDecimal retailProportion,
  206. BigDecimal taxRadio,
  207. Integer retailLevel,
  208. PtlAgreementProductCostsExport ptlAgreementProductCostsExport,
  209. RetailProportion originalRetailProportion,
  210. String type,
  211. BigDecimal enterProportion) {
  212. ReCalcuLateProportion reCalcuLateProportion = new ReCalcuLateProportion();
  213. BigDecimal costsProportion = sumCostsProportion.divide(taxRadio, 2, BigDecimal.ROUND_DOWN);
  214. List<InsFeeOrderConfig> list = insFeeOrderConfigService.list();
  215. //总比例 / 比例 / 分销等级
  216. // 不够减扣除比例
  217. Map<String, BigDecimal> notEnoughReduce = list.stream().collect(Collectors.toMap(InsFeeOrderConfig::getKeyword, InsFeeOrderConfig::getVal));
  218. //分销配置的比例
  219. BigDecimal retailProportionConfig = notEnoughReduce.get(CostAllocation.CA_01.getCode());
  220. BigDecimal retailSettingProportion = new BigDecimal(retailProportionConfig.toString());
  221. // 机构配置的比例
  222. BigDecimal deptProportionConfig = notEnoughReduce.get(CostAllocation.CA_02.getCode());
  223. // 代课录单比例
  224. BigDecimal proxyProportionConfig = notEnoughReduce.get(CostAllocation.CA_03.getCode());
  225. BigDecimal deptSettingProportion = new BigDecimal(deptProportionConfig.toString());
  226. //机构比例均分
  227. BigDecimal jqAverageDept = twoPeople(twoPeople(costsProportion.multiply(deptSettingProportion)).divide(new BigDecimal(5)));
  228. //如果不够减的话
  229. if (deptProportion.add(retailProportion).add(enterProportion).compareTo(costsProportion) > 0) {
  230. //分销比例均分
  231. BigDecimal jqAverageRetail = new BigDecimal(0);
  232. if (retailLevel != 0) {
  233. jqAverageRetail = twoPeople(twoPeople(costsProportion.multiply(retailSettingProportion)).divide(new BigDecimal(retailLevel), 2, RoundingMode.DOWN));
  234. }
  235. if (enterProportion.compareTo(BigDecimal.ZERO) == 0) {
  236. reCalcuLateProportion.setProxyProportion(BigDecimal.ZERO);
  237. } else {
  238. // 代客比例
  239. BigDecimal proxyProportion = costsProportion.multiply(proxyProportionConfig);
  240. reCalcuLateProportion.setProxyProportion(twoPeople(proxyProportion));
  241. }
  242. if (retailLevel >= 3) {
  243. reCalcuLateProportion.setRetail_level_3_proportion(jqAverageRetail);
  244. }
  245. if (retailLevel >= 2) {
  246. reCalcuLateProportion.setRetail_level_2_proportion(jqAverageRetail);
  247. }
  248. if (retailLevel >= 1) {
  249. reCalcuLateProportion.setRetail_level_1_proportion(jqAverageRetail);
  250. }
  251. reCalcuLateProportion.setDept_level_1_proportion(jqAverageDept);
  252. reCalcuLateProportion.setDept_level_2_proportion(jqAverageDept);
  253. reCalcuLateProportion.setDept_level_3_proportion(jqAverageDept);
  254. reCalcuLateProportion.setDept_level_4_proportion(jqAverageDept);
  255. reCalcuLateProportion.setDept_level_5_proportion(jqAverageDept);
  256. } else {
  257. if (type.equals("jq")) {
  258. reCalcuLateProportion.setDept_level_1_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel1());
  259. reCalcuLateProportion.setDept_level_2_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel2());
  260. reCalcuLateProportion.setDept_level_3_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel3());
  261. reCalcuLateProportion.setDept_level_4_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel4());
  262. reCalcuLateProportion.setDept_level_5_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  263. reCalcuLateProportion.setRetail_level_1_proportion(originalRetailProportion.getJqRetailLevel1Proportion());
  264. reCalcuLateProportion.setRetail_level_2_proportion(originalRetailProportion.getJqRetailLevel2Proportion());
  265. reCalcuLateProportion.setRetail_level_3_proportion(originalRetailProportion.getJqRetailLevel3Proportion());
  266. } else if (type.equals("sy")) {
  267. reCalcuLateProportion.setDept_level_1_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel1());
  268. reCalcuLateProportion.setDept_level_2_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel2());
  269. reCalcuLateProportion.setDept_level_3_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel3());
  270. reCalcuLateProportion.setDept_level_4_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel4());
  271. reCalcuLateProportion.setDept_level_5_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  272. reCalcuLateProportion.setRetail_level_1_proportion(originalRetailProportion.getSyRetailLevel1Proportion());
  273. reCalcuLateProportion.setRetail_level_2_proportion(originalRetailProportion.getSyRetailLevel2Proportion());
  274. reCalcuLateProportion.setRetail_level_3_proportion(originalRetailProportion.getSyRetailLevel3Proportion());
  275. } else if (type.equals("no")) {
  276. reCalcuLateProportion.setDept_level_1_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel1());
  277. reCalcuLateProportion.setDept_level_2_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2());
  278. reCalcuLateProportion.setDept_level_3_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3());
  279. reCalcuLateProportion.setDept_level_4_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4());
  280. reCalcuLateProportion.setDept_level_5_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  281. reCalcuLateProportion.setRetail_level_1_proportion(originalRetailProportion.getNoRetailLevel1Proportion());
  282. reCalcuLateProportion.setRetail_level_2_proportion(originalRetailProportion.getNoRetailLevel2Proportion());
  283. reCalcuLateProportion.setRetail_level_3_proportion(originalRetailProportion.getNoRetailLevel3Proportion());
  284. }
  285. // 代课比例
  286. reCalcuLateProportion.setProxyProportion(enterProportion);
  287. }
  288. return reCalcuLateProportion;
  289. }
  290. /**
  291. * 计算费用
  292. *
  293. * @param costsId
  294. * @param insAreaCompany
  295. */
  296. @Override
  297. public void calcCosts(String costsId, InsAreaCompany insAreaCompany, boolean isInternalAgreement) {
  298. //获取协议信息
  299. PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
  300. InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
  301. SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
  302. BigDecimal taxRadio = new BigDecimal("1.00");
  303. //如果是外部订单则 不含税
  304. if (ptlAgreement.getWithTax().equals("否") && ptlAgreement.getIsExternal() == 0) {
  305. taxRadio = new BigDecimal("1.06");
  306. }
  307. //税比例 固定1.06
  308. //查找入口与出口费用比例
  309. //入口配置
  310. PtlAgreementProductCostsNew ptlAgreementProductCostsNew = ptlAgreementProductCostsNewService.getById(costsId);
  311. ptlAgreementProductCostsNew.blank();
  312. //出口配置
  313. PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
  314. ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>().eq(PtlAgreementProductCostsExport::getCostsId, costsId));
  315. InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  316. insFeeOrderNew.setId(IdGenerate.nextId());
  317. insFeeOrderNew.setCostsId(costsId);
  318. insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
  319. //存储部门id与用户id
  320. InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
  321. InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
  322. if (insFeeOrderNewByCompanyId != null) {
  323. insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
  324. }
  325. insFeeOrderNew.setDeptId(order.getDeptid());
  326. insFeeOrderNew.setUserId(order.getUserid());
  327. insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
  328. insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
  329. insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
  330. insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
  331. //不含税
  332. BigDecimal bigDecimal = new BigDecimal("1.06");
  333. insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
  334. insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
  335. insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
  336. //region 计算入口费用
  337. //交强入口信息
  338. FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(
  339. insFeeOrderNew.getJqPremium(),
  340. new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
  341. new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()),
  342. taxRadio);
  343. insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
  344. insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
  345. insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
  346. insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
  347. insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
  348. insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
  349. //商业入口信息
  350. FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
  351. new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()) ,
  352. new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
  353. insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
  354. insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
  355. insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
  356. insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
  357. insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
  358. insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
  359. //非车入口信息
  360. FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
  361. new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
  362. new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
  363. insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
  364. insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
  365. insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
  366. insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
  367. insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
  368. insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
  369. //endregion
  370. //region 重新计算管理费比例和分销比例
  371. List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
  372. new Object[]{sysUser.getDeptId()});
  373. Integer retailLevel = 0;
  374. //默认分销比例设置
  375. RetailProportion retailProportion = new RetailProportion();
  376. if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
  377. retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
  378. //赋值默认的分销比例
  379. retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
  380. }
  381. //获取交强机构管理费总比例
  382. BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
  383. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
  384. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
  385. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
  386. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  387. //获取商业机构管理费总比例
  388. BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
  389. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
  390. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
  391. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
  392. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  393. //获取非车机构管理费总比例
  394. BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
  395. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
  396. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
  397. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
  398. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  399. //获取交强分销总比例
  400. BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
  401. .add(retailProportion.getJqRetailLevel2Proportion())
  402. .add(retailProportion.getJqRetailLevel3Proportion());
  403. //获取商业分销总比例
  404. BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
  405. .add(retailProportion.getSyRetailLevel2Proportion())
  406. .add(retailProportion.getSyRetailLevel3Proportion());
  407. //获取非车分销总比例
  408. BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
  409. .add(retailProportion.getNoRetailLevel2Proportion())
  410. .add(retailProportion.getNoRetailLevel3Proportion());
  411. BigDecimal enterProportion = new BigDecimal(BigInteger.ZERO);
  412. // 待客录单订单比例 根据前端传值 判断是否使用待客录单比例
  413. if(!isInternalAgreement){
  414. enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus());
  415. }
  416. //重新计算比例 入口是否超出支付的比例
  417. ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
  418. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
  419. jqDeptProportion,
  420. jqRetailProportion,
  421. taxRadio,
  422. retailLevel,
  423. ptlAgreementProductCostsExport,
  424. retailProportion,
  425. "jq",
  426. enterProportion
  427. );
  428. ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
  429. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
  430. syDeptProportion,
  431. syRetailProportion,
  432. taxRadio,
  433. retailLevel,
  434. ptlAgreementProductCostsExport,
  435. retailProportion,
  436. "sy",
  437. enterProportion
  438. );
  439. ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
  440. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
  441. noDeptProportion,
  442. noRetailProportion,
  443. taxRadio,
  444. retailLevel,
  445. ptlAgreementProductCostsExport,
  446. retailProportion,
  447. "no",
  448. enterProportion
  449. );
  450. retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
  451. // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport);
  452. //endregion
  453. //region 计算分销费用
  454. //获取分销比例
  455. //分销总比例
  456. BigDecimal jqRetailRadio = new BigDecimal("0");
  457. BigDecimal syRetailRadio = new BigDecimal("0");
  458. BigDecimal noRetailRadio = new BigDecimal("0");
  459. FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
  460. FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
  461. FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
  462. if (esmRetailList != null && !esmRetailList.isEmpty()) {
  463. EsmRetail esmRetail = esmRetailList.get(0);
  464. //分销等级
  465. insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
  466. //用户分销人员id
  467. List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
  468. if (esmRetail != null) {
  469. if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
  470. insFeeOrderNew.setThirdDetailProportion(retailProportion.getJqRetailLevel3Proportion());
  471. retailFeeLevel3 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  472. insFeeOrderNew.getJqCostsProportion(),
  473. insFeeOrderNew.getSyPremium(),
  474. insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
  475. insFeeOrderNew.getNoPremium(),
  476. insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
  477. retailProportion.getJqRetailLevel3Proportion(),
  478. retailProportion.getSyRetailLevel3Proportion(),
  479. retailProportion.getNoRetailLevel3Proportion());
  480. insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums());
  481. if (parents != null && parents.size() > 2) {
  482. insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
  483. }
  484. } else {
  485. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  486. }
  487. if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
  488. insFeeOrderNew.setSecondDetailProportion(retailProportion.getJqRetailLevel2Proportion());
  489. retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  490. insFeeOrderNew.getJqCostsProportion(),
  491. insFeeOrderNew.getSyPremium(),
  492. insFeeOrderNew.getSyCostsProportion(),
  493. insFeeOrderNew.getNoPremium(),
  494. insFeeOrderNew.getNoCostsProportion(),
  495. retailProportion.getJqRetailLevel2Proportion(),
  496. retailProportion.getSyRetailLevel2Proportion(),
  497. retailProportion.getNoRetailLevel2Proportion());
  498. insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums());
  499. if (parents != null && parents.size() > 1) {
  500. insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
  501. }
  502. } else {
  503. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  504. }
  505. if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
  506. insFeeOrderNew.setFirstDetailProportion(retailProportion.getJqRetailLevel1Proportion());
  507. retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  508. insFeeOrderNew.getJqCostsProportion(),
  509. insFeeOrderNew.getSyPremium(),
  510. insFeeOrderNew.getSyCostsProportion(),
  511. insFeeOrderNew.getNoPremium(),
  512. insFeeOrderNew.getNoCostsProportion(),
  513. retailProportion.getJqRetailLevel1Proportion(),
  514. retailProportion.getSyRetailLevel1Proportion(),
  515. retailProportion.getNoRetailLevel1Proportion());
  516. insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums());
  517. if (parents != null && !parents.isEmpty()) {
  518. insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
  519. }
  520. } else {
  521. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  522. }
  523. } else {
  524. insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
  525. insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
  526. insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
  527. }
  528. } else {
  529. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  530. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  531. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  532. }
  533. jqRetailRadio = jqRetailRadio.add(retailFeeLevel1.getJqRetailProportion())
  534. .add(retailFeeLevel2.getJqRetailProportion())
  535. .add(retailFeeLevel3.getJqRetailProportion());
  536. syRetailRadio = syRetailRadio.add(retailFeeLevel1.getSyRetailProportion())
  537. .add(retailFeeLevel2.getSyRetailProportion())
  538. .add(retailFeeLevel3.getSyRetailProportion());
  539. noRetailRadio = noRetailRadio.add(retailFeeLevel1.getNoRetailProportion())
  540. .add(retailFeeLevel2.getNoRetailProportion())
  541. .add(retailFeeLevel3.getNoRetailProportion());
  542. insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3);
  543. //endregion
  544. //region 设置机构管理费
  545. //交强机构管理费
  546. BigDecimal jqDeptRadio =
  547. jqReCalcuLateProportion.getDept_level_1_proportion()
  548. .add(jqReCalcuLateProportion.getDept_level_2_proportion())
  549. .add(jqReCalcuLateProportion.getDept_level_3_proportion())
  550. .add(jqReCalcuLateProportion.getDept_level_4_proportion())
  551. .add(jqReCalcuLateProportion.getDept_level_5_proportion());
  552. FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
  553. insFeeOrderNew.getJqPremium(),
  554. jqReCalcuLateProportion.getDept_level_1_proportion(),
  555. jqReCalcuLateProportion.getDept_level_2_proportion(),
  556. jqReCalcuLateProportion.getDept_level_3_proportion(),
  557. jqReCalcuLateProportion.getDept_level_4_proportion(),
  558. jqReCalcuLateProportion.getDept_level_5_proportion());
  559. BigDecimal syDeptRadio =
  560. syReCalcuLateProportion.getDept_level_1_proportion()
  561. .add(syReCalcuLateProportion.getDept_level_2_proportion())
  562. .add(syReCalcuLateProportion.getDept_level_3_proportion())
  563. .add(syReCalcuLateProportion.getDept_level_4_proportion())
  564. .add(syReCalcuLateProportion.getDept_level_5_proportion());
  565. FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
  566. insFeeOrderNew.getSyPremium(),
  567. syReCalcuLateProportion.getDept_level_1_proportion(),
  568. syReCalcuLateProportion.getDept_level_2_proportion(),
  569. syReCalcuLateProportion.getDept_level_3_proportion(),
  570. syReCalcuLateProportion.getDept_level_4_proportion(),
  571. syReCalcuLateProportion.getDept_level_5_proportion());
  572. BigDecimal noDeptRadio =
  573. noReCalcuLateProportion.getDept_level_1_proportion()
  574. .add(noReCalcuLateProportion.getDept_level_2_proportion())
  575. .add(noReCalcuLateProportion.getDept_level_3_proportion())
  576. .add(noReCalcuLateProportion.getDept_level_4_proportion())
  577. .add(noReCalcuLateProportion.getDept_level_5_proportion());
  578. FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
  579. insFeeOrderNew.getNoPremium(),
  580. noReCalcuLateProportion.getDept_level_1_proportion(),
  581. noReCalcuLateProportion.getDept_level_2_proportion(),
  582. noReCalcuLateProportion.getDept_level_3_proportion(),
  583. noReCalcuLateProportion.getDept_level_4_proportion(),
  584. noReCalcuLateProportion.getDept_level_5_proportion());
  585. insFeeOrderNew.assignDept(jqDeptManagerFee, syDeptManagerFee, noDeptManagerFee);
  586. //endregion
  587. //region 出口费用
  588. //交强出口手续费比例
  589. FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(
  590. insFeeOrderNew.getJqPremium(),
  591. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
  592. insFeeOrderNew.getJqCostsProportion(),
  593. jqDeptRadio,
  594. jqRetailRadio,
  595. taxRadio,
  596. jqReCalcuLateProportion.getProxyProportion()
  597. );
  598. //商业出口手续费比例
  599. FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(
  600. insFeeOrderNew.getSyPremium(),
  601. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
  602. insFeeOrderNew.getSyCostsProportion(),
  603. syDeptRadio,
  604. syRetailRadio,
  605. taxRadio,
  606. syReCalcuLateProportion.getProxyProportion()
  607. );
  608. //非车出口手续费比例
  609. FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(
  610. insFeeOrderNew.getNoPremium(),
  611. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
  612. insFeeOrderNew.getNoCostsProportion(),
  613. noDeptRadio,
  614. noRetailRadio,
  615. taxRadio,
  616. noReCalcuLateProportion.getProxyProportion()
  617. );
  618. //出口手续费用
  619. insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
  620. insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
  621. insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
  622. //出口其他费用比例
  623. insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
  624. insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
  625. insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
  626. //出口其他费用
  627. insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
  628. insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
  629. insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
  630. //设置出口手续费比例
  631. insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
  632. insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
  633. insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
  634. // 外部费用
  635. insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion());
  636. insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums());
  637. insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion());
  638. insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums());
  639. insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion());
  640. insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums());
  641. //endregion
  642. //region 计算利润差值
  643. //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
  644. //分销交强费用
  645. //分开算 1 2 3 级
  646. BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  647. BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  648. BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  649. BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
  650. //分销商业费用
  651. BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  652. BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  653. BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  654. BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
  655. //分销非车费用
  656. BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  657. BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  658. BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  659. BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
  660. BigDecimal jqDifference = jqEntranceFee.getTotalAmount()
  661. .subtract(jqExportFee.getExternalPremiums())
  662. .subtract(
  663. (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
  664. .subtract(
  665. (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
  666. )
  667. .subtract(jqFenXiao)
  668. .setScale(5, BigDecimal.ROUND_HALF_DOWN);
  669. insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
  670. BigDecimal syDifference = syEntranceFee.getTotalAmount()
  671. .subtract(syExportFee.getExternalPremiums())
  672. .subtract(
  673. (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
  674. .subtract(
  675. (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
  676. )
  677. .subtract(syFenXiao)
  678. .setScale(5, BigDecimal.ROUND_HALF_DOWN);
  679. insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
  680. BigDecimal noDifference = noEntranceFee.getTotalAmount()
  681. .subtract(noExportFee.getExternalPremiums())
  682. .subtract(
  683. (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
  684. .subtract(
  685. (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
  686. )
  687. .subtract(noFenXiao)
  688. .setScale(5, BigDecimal.ROUND_HALF_DOWN);
  689. insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
  690. //endregion
  691. //region 比例逆推是否等于0
  692. if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, jqRetailRadio, taxRadio, insFeeOrderNew.getJqPremium()))
  693. throw new SystemException("交强比例异常");
  694. if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, syRetailRadio, taxRadio, insFeeOrderNew.getSyPremium()))
  695. throw new SystemException("商业比例异常");
  696. if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, noRetailRadio, taxRadio, insFeeOrderNew.getNoPremium()))
  697. throw new SystemException("非车比例异常");
  698. //endregion
  699. sysChannelGroupService.costCompute(insFeeOrderNew,ptlAgreement,ptlAgreementProductCostsNew,sysUser,insAreaCompany,insOrders);
  700. insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
  701. }
  702. /**
  703. * 计算费用测试方法 没有数据库保存操作 只带入值进行计算核对
  704. *
  705. * @param costsId
  706. * @param insAreaCompany
  707. */
  708. @Override
  709. public void calcCostsTest(String costsId, InsAreaCompany insAreaCompany) {
  710. // //获取协议信息
  711. // PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
  712. // BigDecimal taxRadio = new BigDecimal("1.00");
  713. // //如果是外部订单则 不含税
  714. // if (ptlAgreement.getWithTax().equals("否") && ptlAgreement.getIsExternal() == 0) {
  715. // taxRadio = new BigDecimal("1.06");
  716. // }
  717. // //税比例 固定1.06
  718. // //查找入口与出口费用比例
  719. // //入口配置
  720. // PtlAgreementProductCostsNew ptlAgreementProductCostsNew = ptlAgreementProductCostsNewService.getById(costsId);
  721. //
  722. // //出口配置
  723. // PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
  724. // ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>().eq(PtlAgreementProductCostsExport::getCostsId, costsId));
  725. // InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  726. // insFeeOrderNew.setId(IdGenerate.nextId());
  727. // insFeeOrderNew.setCostsId(costsId);
  728. // insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
  729. //
  730. // //存储部门id与用户id
  731. // InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
  732. // InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
  733. // if (insFeeOrderNewByCompanyId != null) {
  734. // insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
  735. // }
  736. // insFeeOrderNew.setDeptId(order.getDeptid());
  737. // insFeeOrderNew.setUserId(order.getUserid());
  738. // insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
  739. // insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
  740. // insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
  741. // insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
  742. // //不含税
  743. // BigDecimal bigDecimal = new BigDecimal("1.06");
  744. // insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
  745. // insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
  746. // insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
  747. //
  748. // //region 计算入口费用
  749. //
  750. // //交强入口信息
  751. // FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getJqPremium(),
  752. // new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
  753. // new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio);
  754. // insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
  755. // insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
  756. // insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
  757. // insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
  758. // insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
  759. // insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
  760. //
  761. // //商业入口信息
  762. // FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
  763. // new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()),
  764. // new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
  765. // insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
  766. // insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
  767. // insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
  768. // insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
  769. // insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
  770. // insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
  771. //
  772. // //非车入口信息
  773. // FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
  774. // new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
  775. // new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
  776. // insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
  777. // insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
  778. // insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
  779. // insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
  780. // insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
  781. // insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
  782. // //endregion
  783. //
  784. // //region 计算分销费用
  785. // InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
  786. // SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
  787. //
  788. // //获取分销比例
  789. // List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
  790. // new Object[]{sysUser.getDeptId()});
  791. //
  792. // //分销总比例
  793. // BigDecimal retailRadio = new BigDecimal("0");
  794. // if (esmRetailList != null && !esmRetailList.isEmpty()) {
  795. // EsmRetail esmRetail = esmRetailList.get(0);
  796. // //分销等级
  797. // insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
  798. // //用户分销人员id
  799. // List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
  800. //
  801. // if (esmRetail != null) {
  802. // BigDecimal sumPremium = insFeeOrderNew.getJqPremium().add(insFeeOrderNew.getSyPremium()).add(insFeeOrderNew.getNoPremium());
  803. // if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
  804. // insFeeOrderNew.setThirdDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate3())));
  805. // retailRadio = retailRadio.add(insFeeOrderNew.getThirdDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  806. // BigDecimal thirdDetailPremiums = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  807. // insFeeOrderNew.getJqCostsProportion().add(insFeeOrderNew.getJqOtherCostsProportion()),
  808. // insFeeOrderNew.getSyPremium(),
  809. // insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
  810. // insFeeOrderNew.getNoPremium(),
  811. // insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
  812. // insFeeOrderNew.getThirdDetailProportion());
  813. // insFeeOrderNew.setThirdDetailPremiums(thirdDetailPremiums);
  814. // if (parents != null && parents.size() > 2) {
  815. // insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
  816. // }
  817. // }else{
  818. // insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  819. // }
  820. // if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
  821. // insFeeOrderNew.setSecondDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate2())));
  822. // retailRadio = retailRadio.add(insFeeOrderNew.getSecondDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  823. // BigDecimal secondDetailPremiums = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  824. // insFeeOrderNew.getJqCostsProportion().add(insFeeOrderNew.getJqOtherCostsProportion()),
  825. // insFeeOrderNew.getSyPremium(),
  826. // insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
  827. // insFeeOrderNew.getNoPremium(),
  828. // insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
  829. // insFeeOrderNew.getSecondDetailProportion());
  830. // insFeeOrderNew.setSecondDetailPremiums(secondDetailPremiums);
  831. // if (parents != null && parents.size() > 1) {
  832. // insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
  833. // }
  834. // }else{
  835. // insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  836. // }
  837. // if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
  838. // insFeeOrderNew.setFirstDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate1())));
  839. // retailRadio = retailRadio.add(insFeeOrderNew.getFirstDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  840. // BigDecimal firstDetailPremiums = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  841. // insFeeOrderNew.getJqCostsProportion().add(insFeeOrderNew.getJqOtherCostsProportion()),
  842. // insFeeOrderNew.getSyPremium(),
  843. // insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
  844. // insFeeOrderNew.getNoPremium(),
  845. // insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
  846. // insFeeOrderNew.getFirstDetailProportion());
  847. // insFeeOrderNew.setFirstDetailPremiums(firstDetailPremiums);
  848. // if (parents != null && parents.size() > 0) {
  849. // insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
  850. // }
  851. // }else{
  852. // insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  853. // }
  854. // }else{
  855. // insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
  856. // insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
  857. // insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
  858. // }
  859. // }else{
  860. // insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  861. // insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  862. // insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  863. // }
  864. //
  865. //
  866. // //endregion
  867. //
  868. // //region 设置机构管理费
  869. //
  870. // //交强机构管理费
  871. // BigDecimal jqDeptRadio =
  872. // ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  873. // FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getJqPremium(),
  874. // ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(),
  875. // ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(),
  876. // ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  877. // insFeeOrderNew.setJqDeptProportionLevel1(jqDeptManagerFee.getDeptProportionLevelOne());
  878. // insFeeOrderNew.setJqDeptPremiumsLevel1(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelOne()));
  879. // insFeeOrderNew.setJqDeptProportionLevel2(jqDeptManagerFee.getDeptProportionLevelTwo());
  880. // insFeeOrderNew.setJqDeptPremiumsLevel2(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelTwo()));
  881. // insFeeOrderNew.setJqDeptProportionLevel3(jqDeptManagerFee.getDeptProportionLevelThree());
  882. // insFeeOrderNew.setJqDeptPremiumsLevel3(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelThree()));
  883. // insFeeOrderNew.setJqDeptProportionLevel4(jqDeptManagerFee.getDeptProportionLevelFoure());
  884. // insFeeOrderNew.setJqDeptPremiumsLevel4(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFoure()));
  885. // insFeeOrderNew.setJqDeptProportionLevel5(jqDeptManagerFee.getDeptProportionLevelFive());
  886. // insFeeOrderNew.setJqDeptPremiumsLevel5(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFive()));
  887. //
  888. // BigDecimal syDeptRadio =
  889. // ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  890. // FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getSyPremium(),
  891. // ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(),
  892. // ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(),
  893. // ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  894. // insFeeOrderNew.setSyDeptProportionLevel1(syDeptManagerFee.getDeptProportionLevelOne());
  895. // insFeeOrderNew.setSyDeptPremiumsLevel1(twoPeople(syDeptManagerFee.getDeptPremiumsLevelOne()));
  896. // insFeeOrderNew.setSyDeptProportionLevel2(syDeptManagerFee.getDeptProportionLevelTwo());
  897. // insFeeOrderNew.setSyDeptPremiumsLevel2(twoPeople(syDeptManagerFee.getDeptPremiumsLevelTwo()));
  898. // insFeeOrderNew.setSyDeptProportionLevel3(syDeptManagerFee.getDeptProportionLevelThree());
  899. // insFeeOrderNew.setSyDeptPremiumsLevel3(twoPeople(syDeptManagerFee.getDeptPremiumsLevelThree()));
  900. // insFeeOrderNew.setSyDeptProportionLevel4(syDeptManagerFee.getDeptProportionLevelFoure());
  901. // insFeeOrderNew.setSyDeptPremiumsLevel4(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFoure()));
  902. // insFeeOrderNew.setSyDeptProportionLevel5(syDeptManagerFee.getDeptProportionLevelFive());
  903. // insFeeOrderNew.setSyDeptPremiumsLevel5(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFive()));
  904. //
  905. // BigDecimal noDeptRadio =
  906. // ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  907. // FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getNoPremium(),
  908. // ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(),
  909. // ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(),
  910. // ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  911. // insFeeOrderNew.setNoDeptProportionLevel1(noDeptManagerFee.getDeptProportionLevelOne());
  912. // insFeeOrderNew.setNoDeptPremiumsLevel1(twoPeople(noDeptManagerFee.getDeptPremiumsLevelOne()));
  913. // insFeeOrderNew.setNoDeptProportionLevel2(noDeptManagerFee.getDeptProportionLevelTwo());
  914. // insFeeOrderNew.setNoDeptPremiumsLevel2(twoPeople(noDeptManagerFee.getDeptPremiumsLevelTwo()));
  915. // insFeeOrderNew.setNoDeptProportionLevel3(noDeptManagerFee.getDeptProportionLevelThree());
  916. // insFeeOrderNew.setNoDeptPremiumsLevel3(twoPeople(noDeptManagerFee.getDeptPremiumsLevelThree()));
  917. // insFeeOrderNew.setNoDeptProportionLevel4(noDeptManagerFee.getDeptProportionLevelFoure());
  918. // insFeeOrderNew.setNoDeptPremiumsLevel4(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFoure()));
  919. // insFeeOrderNew.setNoDeptProportionLevel5(noDeptManagerFee.getDeptProportionLevelFive());
  920. // insFeeOrderNew.setNoDeptPremiumsLevel5(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFive()));
  921. //
  922. // //endregion
  923. //
  924. // //region 出口费用
  925. //
  926. // //交强出口手续费比例
  927. // FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
  928. // insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, retailRadio, taxRadio);
  929. //
  930. // //商业出口手续费比例
  931. // FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
  932. // insFeeOrderNew.getSyCostsProportion(), syDeptRadio, retailRadio, taxRadio);
  933. //
  934. // //非车出口手续费比例
  935. // FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
  936. // insFeeOrderNew.getNoCostsProportion(), noDeptRadio, retailRadio, taxRadio);
  937. //
  938. // //出口手续费用
  939. // insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
  940. // insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
  941. // insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
  942. //
  943. // //出口其他费用比例
  944. // insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
  945. // insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
  946. // insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
  947. //
  948. // //出口其他费用
  949. // insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
  950. // insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
  951. // insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
  952. //
  953. // //设置出口手续费比例
  954. // insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
  955. // insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
  956. // insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
  957. //
  958. // //endregion
  959. //
  960. // //region 计算利润差值
  961. // //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
  962. //
  963. // //分销交强费用
  964. // //分开算 1 2 3 级
  965. // BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  966. // BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  967. // BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  968. // BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
  969. // //分销商业费用
  970. // BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  971. // BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  972. // BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  973. // BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
  974. // //分销非车费用
  975. // BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  976. // BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  977. // BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  978. // BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
  979. //
  980. //
  981. // BigDecimal jqDifference = jqEntranceFee.getTotalAmount().subtract(
  982. // (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
  983. // .subtract(
  984. // (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
  985. // )
  986. // .subtract(jqFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  987. // insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
  988. //
  989. // BigDecimal syDifference = syEntranceFee.getTotalAmount().subtract(
  990. // (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
  991. // .subtract(
  992. // (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
  993. // )
  994. // .subtract(syFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  995. // insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
  996. //
  997. //
  998. // BigDecimal noDifference = noEntranceFee.getTotalAmount().subtract(
  999. // (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
  1000. // .subtract(
  1001. // (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
  1002. // )
  1003. // .subtract(noFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  1004. //
  1005. // insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
  1006. //
  1007. // //endregion
  1008. //
  1009. // //region 比例逆推是否等于0
  1010. //
  1011. // if(!feeRuleSchemeService.calculateProportion(jqEntranceFee,jqDeptManagerFee,jqExportFee,retailRadio,taxRadio,insFeeOrderNew.getJqPremium()))
  1012. // throw new SystemException("交强比例异常");
  1013. //
  1014. // if(!feeRuleSchemeService.calculateProportion(syEntranceFee,syDeptManagerFee,syExportFee,retailRadio,taxRadio,insFeeOrderNew.getSyPremium()))
  1015. // throw new SystemException("商业比例异常");
  1016. //
  1017. // if(!feeRuleSchemeService.calculateProportion(noEntranceFee,noDeptManagerFee,noExportFee,retailRadio,taxRadio,insFeeOrderNew.getNoPremium()))
  1018. // throw new SystemException("非车比例异常");
  1019. //endregion
  1020. // insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
  1021. }
  1022. @Override
  1023. public void calcCostsExternal(PtlAgreementProductCostsNew ptlAgreementProductCostsNew, InsAreaCompany insAreaCompany) {
  1024. //获取协议信息
  1025. // 外部订单比例
  1026. ptlAgreementProductCostsNew.blank();
  1027. PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
  1028. InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
  1029. SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
  1030. BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus());
  1031. BigDecimal taxRadio = new BigDecimal("1.00");
  1032. //如果是外部订单则 不含税
  1033. if (ptlAgreement.getWithTax().equals("否")) {
  1034. taxRadio = new BigDecimal("1.06");
  1035. }
  1036. //税比例 固定1.06
  1037. //查找入口与出口费用比例
  1038. //出口配置
  1039. PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
  1040. ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>().eq(PtlAgreementProductCostsExport::getCostsId, ptlAgreementProductCostsNew.getId()));
  1041. InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  1042. insFeeOrderNew.setId(IdGenerate.nextId());
  1043. insFeeOrderNew.setCostsId(ptlAgreementProductCostsNew.getId());
  1044. insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
  1045. //存储部门id与用户id
  1046. InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
  1047. InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
  1048. if (insFeeOrderNewByCompanyId != null) {
  1049. insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
  1050. }
  1051. insFeeOrderNew.setDeptId(order.getDeptid());
  1052. insFeeOrderNew.setUserId(order.getUserid());
  1053. insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
  1054. insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
  1055. insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
  1056. insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
  1057. //不含税
  1058. BigDecimal bigDecimal = new BigDecimal("1.06");
  1059. insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
  1060. insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
  1061. insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
  1062. //region 计算入口费用
  1063. //交强入口信息
  1064. FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getJqPremium(),
  1065. new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
  1066. new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio);
  1067. insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
  1068. insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
  1069. insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
  1070. insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
  1071. insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
  1072. insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
  1073. //商业入口信息
  1074. FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
  1075. new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()),
  1076. new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
  1077. insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
  1078. insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
  1079. insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
  1080. insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
  1081. insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
  1082. insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
  1083. //非车入口信息
  1084. FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
  1085. new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
  1086. new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
  1087. insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
  1088. insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
  1089. insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
  1090. insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
  1091. insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
  1092. insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
  1093. //endregion
  1094. //region 重新计算管理费比例和分销比例
  1095. List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
  1096. new Object[]{sysUser.getDeptId()});
  1097. Integer retailLevel = 0;
  1098. //默认分销比例设置
  1099. RetailProportion retailProportion = new RetailProportion();
  1100. if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
  1101. retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
  1102. //赋值默认的分销比例
  1103. retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
  1104. }
  1105. //获取交强机构管理费总比例
  1106. BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
  1107. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
  1108. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
  1109. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
  1110. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1111. //获取商业机构管理费总比例
  1112. BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
  1113. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
  1114. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
  1115. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
  1116. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1117. //获取非车机构管理费总比例
  1118. BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
  1119. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
  1120. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
  1121. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
  1122. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1123. //获取交强分销总比例
  1124. BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
  1125. .add(retailProportion.getJqRetailLevel2Proportion())
  1126. .add(retailProportion.getJqRetailLevel3Proportion());
  1127. //获取商业分销总比例
  1128. BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
  1129. .add(retailProportion.getSyRetailLevel2Proportion())
  1130. .add(retailProportion.getSyRetailLevel3Proportion());
  1131. //获取非车分销总比例
  1132. BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
  1133. .add(retailProportion.getNoRetailLevel2Proportion())
  1134. .add(retailProportion.getNoRetailLevel3Proportion());
  1135. //重新计算比例 入口是否超出支付的比例
  1136. ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
  1137. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
  1138. jqDeptProportion,
  1139. jqRetailProportion,
  1140. taxRadio,
  1141. retailLevel,
  1142. ptlAgreementProductCostsExport,
  1143. retailProportion,
  1144. "jq",
  1145. enterProportion
  1146. );
  1147. ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
  1148. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
  1149. syDeptProportion,
  1150. syRetailProportion,
  1151. taxRadio,
  1152. retailLevel,
  1153. ptlAgreementProductCostsExport,
  1154. retailProportion,
  1155. "sy",
  1156. enterProportion
  1157. );
  1158. ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
  1159. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
  1160. noDeptProportion,
  1161. noRetailProportion,
  1162. taxRadio,
  1163. retailLevel,
  1164. ptlAgreementProductCostsExport,
  1165. retailProportion,
  1166. "no",
  1167. enterProportion
  1168. );
  1169. retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
  1170. // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport);
  1171. //endregion
  1172. //region 计算分销费用
  1173. //分销总比例
  1174. // BigDecimal jqRetailRadio = new BigDecimal("0");
  1175. // BigDecimal syRetailRadio = new BigDecimal("0");
  1176. // BigDecimal noRetailRadio = new BigDecimal("0");
  1177. FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
  1178. FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
  1179. FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
  1180. //分销总比例
  1181. BigDecimal retailRadio = new BigDecimal("0");
  1182. if (esmRetailList != null && !esmRetailList.isEmpty()) {
  1183. EsmRetail esmRetail = esmRetailList.get(0);
  1184. //分销等级
  1185. insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
  1186. //用户分销人员id
  1187. List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
  1188. if (esmRetail != null) {
  1189. BigDecimal sumPremium = insFeeOrderNew.getJqPremium().add(insFeeOrderNew.getSyPremium()).add(insFeeOrderNew.getNoPremium());
  1190. if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
  1191. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate3())));
  1192. retailRadio = retailRadio.add(insFeeOrderNew.getThirdDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  1193. retailFeeLevel3 = feeRuleSchemeService.calcRetail(
  1194. insFeeOrderNew.getJqPremium(),
  1195. insFeeOrderNew.getJqCostsProportion(),
  1196. insFeeOrderNew.getSyPremium(),
  1197. insFeeOrderNew.getSyCostsProportion(),
  1198. insFeeOrderNew.getNoPremium(),
  1199. insFeeOrderNew.getNoCostsProportion(),
  1200. retailProportion.getJqRetailLevel3Proportion(),
  1201. retailProportion.getSyRetailLevel3Proportion(),
  1202. retailProportion.getNoRetailLevel3Proportion());
  1203. insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums());
  1204. if (parents != null && parents.size() > 2) {
  1205. insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
  1206. }
  1207. } else {
  1208. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  1209. }
  1210. if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
  1211. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate2())));
  1212. retailRadio = retailRadio.add(insFeeOrderNew.getSecondDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  1213. retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  1214. insFeeOrderNew.getJqCostsProportion(),
  1215. insFeeOrderNew.getSyPremium(),
  1216. insFeeOrderNew.getSyCostsProportion(),
  1217. insFeeOrderNew.getNoPremium(),
  1218. insFeeOrderNew.getNoCostsProportion(),
  1219. retailProportion.getJqRetailLevel2Proportion(),
  1220. retailProportion.getSyRetailLevel2Proportion(),
  1221. retailProportion.getNoRetailLevel2Proportion());
  1222. insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums());
  1223. if (parents != null && parents.size() > 1) {
  1224. insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
  1225. }
  1226. } else {
  1227. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  1228. }
  1229. if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
  1230. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate1())));
  1231. retailRadio = retailRadio.add(insFeeOrderNew.getFirstDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  1232. retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  1233. insFeeOrderNew.getJqCostsProportion(),
  1234. insFeeOrderNew.getSyPremium(),
  1235. insFeeOrderNew.getSyCostsProportion(),
  1236. insFeeOrderNew.getNoPremium(),
  1237. insFeeOrderNew.getNoCostsProportion(),
  1238. retailProportion.getJqRetailLevel1Proportion(),
  1239. retailProportion.getSyRetailLevel1Proportion(),
  1240. retailProportion.getNoRetailLevel1Proportion());
  1241. insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums());
  1242. if (parents != null && !parents.isEmpty()) {
  1243. insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
  1244. }
  1245. } else {
  1246. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  1247. }
  1248. } else {
  1249. insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
  1250. insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
  1251. insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
  1252. }
  1253. } else {
  1254. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  1255. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  1256. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  1257. }
  1258. insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3);
  1259. //endregion
  1260. //region 设置机构管理费
  1261. //交强机构管理费
  1262. BigDecimal jqDeptRadio =
  1263. ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1264. FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getJqPremium(),
  1265. ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(),
  1266. ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(),
  1267. ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1268. insFeeOrderNew.setJqDeptProportionLevel1(jqDeptManagerFee.getDeptProportionLevelOne());
  1269. insFeeOrderNew.setJqDeptPremiumsLevel1(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelOne()));
  1270. insFeeOrderNew.setJqDeptProportionLevel2(jqDeptManagerFee.getDeptProportionLevelTwo());
  1271. insFeeOrderNew.setJqDeptPremiumsLevel2(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelTwo()));
  1272. insFeeOrderNew.setJqDeptProportionLevel3(jqDeptManagerFee.getDeptProportionLevelThree());
  1273. insFeeOrderNew.setJqDeptPremiumsLevel3(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelThree()));
  1274. insFeeOrderNew.setJqDeptProportionLevel4(jqDeptManagerFee.getDeptProportionLevelFoure());
  1275. insFeeOrderNew.setJqDeptPremiumsLevel4(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFoure()));
  1276. insFeeOrderNew.setJqDeptProportionLevel5(jqDeptManagerFee.getDeptProportionLevelFive());
  1277. insFeeOrderNew.setJqDeptPremiumsLevel5(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFive()));
  1278. BigDecimal syDeptRadio =
  1279. ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1280. FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getSyPremium(),
  1281. ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(),
  1282. ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(),
  1283. ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1284. insFeeOrderNew.setSyDeptProportionLevel1(syDeptManagerFee.getDeptProportionLevelOne());
  1285. insFeeOrderNew.setSyDeptPremiumsLevel1(twoPeople(syDeptManagerFee.getDeptPremiumsLevelOne()));
  1286. insFeeOrderNew.setSyDeptProportionLevel2(syDeptManagerFee.getDeptProportionLevelTwo());
  1287. insFeeOrderNew.setSyDeptPremiumsLevel2(twoPeople(syDeptManagerFee.getDeptPremiumsLevelTwo()));
  1288. insFeeOrderNew.setSyDeptProportionLevel3(syDeptManagerFee.getDeptProportionLevelThree());
  1289. insFeeOrderNew.setSyDeptPremiumsLevel3(twoPeople(syDeptManagerFee.getDeptPremiumsLevelThree()));
  1290. insFeeOrderNew.setSyDeptProportionLevel4(syDeptManagerFee.getDeptProportionLevelFoure());
  1291. insFeeOrderNew.setSyDeptPremiumsLevel4(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFoure()));
  1292. insFeeOrderNew.setSyDeptProportionLevel5(syDeptManagerFee.getDeptProportionLevelFive());
  1293. insFeeOrderNew.setSyDeptPremiumsLevel5(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFive()));
  1294. BigDecimal noDeptRadio =
  1295. ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1296. FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getNoPremium(),
  1297. ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(),
  1298. ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(),
  1299. ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1300. insFeeOrderNew.setNoDeptProportionLevel1(noDeptManagerFee.getDeptProportionLevelOne());
  1301. insFeeOrderNew.setNoDeptPremiumsLevel1(twoPeople(noDeptManagerFee.getDeptPremiumsLevelOne()));
  1302. insFeeOrderNew.setNoDeptProportionLevel2(noDeptManagerFee.getDeptProportionLevelTwo());
  1303. insFeeOrderNew.setNoDeptPremiumsLevel2(twoPeople(noDeptManagerFee.getDeptPremiumsLevelTwo()));
  1304. insFeeOrderNew.setNoDeptProportionLevel3(noDeptManagerFee.getDeptProportionLevelThree());
  1305. insFeeOrderNew.setNoDeptPremiumsLevel3(twoPeople(noDeptManagerFee.getDeptPremiumsLevelThree()));
  1306. insFeeOrderNew.setNoDeptProportionLevel4(noDeptManagerFee.getDeptProportionLevelFoure());
  1307. insFeeOrderNew.setNoDeptPremiumsLevel4(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFoure()));
  1308. insFeeOrderNew.setNoDeptProportionLevel5(noDeptManagerFee.getDeptProportionLevelFive());
  1309. insFeeOrderNew.setNoDeptPremiumsLevel5(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFive()));
  1310. //endregion
  1311. //region 出口费用
  1312. //交强出口手续费比例
  1313. FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
  1314. insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, retailRadio, taxRadio, jqReCalcuLateProportion.getProxyProportion());
  1315. //商业出口手续费比例
  1316. FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
  1317. insFeeOrderNew.getSyCostsProportion(), syDeptRadio, retailRadio, taxRadio, syReCalcuLateProportion.getProxyProportion());
  1318. //非车出口手续费比例
  1319. FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
  1320. insFeeOrderNew.getNoCostsProportion(), noDeptRadio, retailRadio, taxRadio, noReCalcuLateProportion.getProxyProportion());
  1321. //出口手续费用
  1322. insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
  1323. insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
  1324. insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
  1325. //出口其他费用比例
  1326. insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
  1327. insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
  1328. insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
  1329. //出口其他费用
  1330. insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
  1331. insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
  1332. insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
  1333. //设置出口手续费比例
  1334. insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
  1335. insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
  1336. insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
  1337. // 外部订单费用
  1338. insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion());
  1339. insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums());
  1340. insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion());
  1341. insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums());
  1342. insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion());
  1343. insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums());
  1344. //endregion
  1345. //region 计算利润差值
  1346. //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
  1347. //分销交强费用
  1348. //分开算 1 2 3 级
  1349. BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1350. BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1351. BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1352. BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
  1353. //分销商业费用
  1354. BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1355. BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1356. BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1357. BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
  1358. //分销非车费用
  1359. BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1360. BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1361. BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1362. BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
  1363. BigDecimal jqDifference = jqEntranceFee.getTotalAmount()
  1364. .subtract(jqExportFee.getExternalPremiums())
  1365. .subtract(
  1366. (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
  1367. .subtract(
  1368. (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
  1369. )
  1370. .subtract(jqFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  1371. insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
  1372. BigDecimal syDifference = syEntranceFee.getTotalAmount()
  1373. .subtract(syExportFee.getExternalPremiums())
  1374. .subtract(
  1375. (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
  1376. .subtract(
  1377. (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
  1378. )
  1379. .subtract(syFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  1380. insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
  1381. BigDecimal noDifference = noEntranceFee.getTotalAmount()
  1382. .subtract(noExportFee.getExternalPremiums())
  1383. .subtract(
  1384. (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
  1385. .subtract(
  1386. (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
  1387. )
  1388. .subtract(noFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  1389. insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
  1390. //endregion
  1391. //region 比例逆推是否等于0
  1392. if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, retailRadio, taxRadio, insFeeOrderNew.getJqPremium()))
  1393. throw new SystemException("交强比例异常");
  1394. if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, retailRadio, taxRadio, insFeeOrderNew.getSyPremium()))
  1395. throw new SystemException("商业比例异常");
  1396. if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, retailRadio, taxRadio, insFeeOrderNew.getNoPremium()))
  1397. throw new SystemException("非车比例异常");
  1398. //endregion
  1399. insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
  1400. }
  1401. @Override
  1402. public ExternalOrderFeeVo calcCostsExternalExportData(PtlAgreement ptlAgreement, PtlAgreementProductCostsNew ptlAgreementProductCostsNew, ExternalOrderFeeVo externalOrderFeeVo) {
  1403. //获取协议信息
  1404. // 外部订单比例
  1405. ptlAgreementProductCostsNew.blank();
  1406. SysUser sysUser = sysUserService.findByUserId(externalOrderFeeVo.getUserId());
  1407. BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(sysUser.getDeptId(), 3);
  1408. BigDecimal taxRadio = new BigDecimal("1.00");
  1409. //如果是外部订单则 不含税
  1410. if (ptlAgreement.getWithTax().equals("否")) {
  1411. taxRadio = new BigDecimal("1.06");
  1412. }
  1413. //税比例 固定1.06
  1414. //查找入口与出口费用比例
  1415. //出口配置
  1416. PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
  1417. ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>()
  1418. .eq(PtlAgreementProductCostsExport::getCostsId, ptlAgreementProductCostsNew.getId()));
  1419. //不含税
  1420. BigDecimal bigDecimal = new BigDecimal("1.06");
  1421. externalOrderFeeVo.setJqNoTaxPremium(externalOrderFeeVo.getJqPremium().divide(bigDecimal, 2));
  1422. externalOrderFeeVo.setSyNoTaxPremium(externalOrderFeeVo.getSyPremium().divide(bigDecimal, 2));
  1423. externalOrderFeeVo.setNoNoTaxPremium(externalOrderFeeVo.getNoPremium().divide(bigDecimal, 2));
  1424. //region 计算入口费用
  1425. //交强入口信息
  1426. FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(externalOrderFeeVo.getJqPremium(),
  1427. new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
  1428. externalOrderFeeVo.getJqRadio(), taxRadio);
  1429. //endregion
  1430. //region 重新计算管理费比例和分销比例
  1431. List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
  1432. new Object[]{sysUser.getDeptId()});
  1433. Integer retailLevel = 0;
  1434. //默认分销比例设置
  1435. RetailProportion retailProportion = new RetailProportion();
  1436. if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
  1437. retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
  1438. //赋值默认的分销比例
  1439. retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
  1440. }
  1441. //获取交强机构管理费总比例
  1442. BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
  1443. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
  1444. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
  1445. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
  1446. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1447. //获取商业机构管理费总比例
  1448. BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
  1449. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
  1450. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
  1451. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
  1452. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1453. //获取非车机构管理费总比例
  1454. BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
  1455. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
  1456. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
  1457. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
  1458. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1459. //获取交强分销总比例
  1460. BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
  1461. .add(retailProportion.getJqRetailLevel2Proportion())
  1462. .add(retailProportion.getJqRetailLevel3Proportion());
  1463. //获取商业分销总比例
  1464. BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
  1465. .add(retailProportion.getSyRetailLevel2Proportion())
  1466. .add(retailProportion.getSyRetailLevel3Proportion());
  1467. //获取非车分销总比例
  1468. BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
  1469. .add(retailProportion.getNoRetailLevel2Proportion())
  1470. .add(retailProportion.getNoRetailLevel3Proportion());
  1471. //重新计算比例 入口是否超出支付的比例
  1472. ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
  1473. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
  1474. jqDeptProportion,
  1475. jqRetailProportion,
  1476. taxRadio,
  1477. retailLevel,
  1478. ptlAgreementProductCostsExport,
  1479. retailProportion,
  1480. "jq",
  1481. enterProportion
  1482. );
  1483. ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
  1484. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
  1485. syDeptProportion,
  1486. syRetailProportion,
  1487. taxRadio,
  1488. retailLevel,
  1489. ptlAgreementProductCostsExport,
  1490. retailProportion,
  1491. "sy",
  1492. enterProportion
  1493. );
  1494. ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
  1495. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
  1496. noDeptProportion,
  1497. noRetailProportion,
  1498. taxRadio,
  1499. retailLevel,
  1500. ptlAgreementProductCostsExport,
  1501. retailProportion,
  1502. "no",
  1503. enterProportion
  1504. );
  1505. retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
  1506. // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport);
  1507. //endregion
  1508. //region 计算分销费用
  1509. //分销总比例
  1510. BigDecimal jqRetailRadio = new BigDecimal("0");
  1511. BigDecimal syRetailRadio = new BigDecimal("0");
  1512. BigDecimal noRetailRadio = new BigDecimal("0");
  1513. FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
  1514. FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
  1515. FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
  1516. //分销总比例
  1517. BigDecimal retailRadio = new BigDecimal("0");
  1518. if (esmRetailList != null && !esmRetailList.isEmpty()) {
  1519. EsmRetail esmRetail = esmRetailList.get(0);
  1520. if (esmRetail != null) {
  1521. BigDecimal sumPremium = externalOrderFeeVo.getJqPremium().add(externalOrderFeeVo.getSyPremium()).add(externalOrderFeeVo.getNoPremium());
  1522. if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
  1523. retailRadio = retailRadio.add(new BigDecimal(String.valueOf(esmRetail.getDisrate3()))).setScale(2, BigDecimal.ROUND_DOWN);
  1524. retailFeeLevel3 = feeRuleSchemeService.calcRetail(
  1525. externalOrderFeeVo.getJqPremium(),
  1526. externalOrderFeeVo.getJqRadio(),
  1527. externalOrderFeeVo.getSyPremium(),
  1528. externalOrderFeeVo.getSyRadio(),
  1529. externalOrderFeeVo.getNoPremium(),
  1530. externalOrderFeeVo.getNoRadio(),
  1531. retailProportion.getJqRetailLevel3Proportion(),
  1532. retailProportion.getSyRetailLevel3Proportion(),
  1533. retailProportion.getNoRetailLevel3Proportion());
  1534. //三级分销费用 retailFeeLevel3.getTotalRetailPremiums()
  1535. } else {
  1536. //三级分销费用为 空值0
  1537. }
  1538. if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
  1539. retailRadio = retailRadio.add(new BigDecimal(String.valueOf(esmRetail.getDisrate2()))).setScale(2, BigDecimal.ROUND_DOWN);
  1540. retailFeeLevel2 = feeRuleSchemeService.calcRetail(
  1541. externalOrderFeeVo.getJqPremium(),
  1542. externalOrderFeeVo.getJqRadio(),
  1543. externalOrderFeeVo.getSyPremium(),
  1544. externalOrderFeeVo.getSyRadio(),
  1545. externalOrderFeeVo.getNoPremium(),
  1546. externalOrderFeeVo.getNoRadio(),
  1547. retailProportion.getJqRetailLevel2Proportion(),
  1548. retailProportion.getSyRetailLevel2Proportion(),
  1549. retailProportion.getNoRetailLevel2Proportion());
  1550. //二级分销费用 retailFeeLevel2.getTotalRetailPremiums()
  1551. } else {
  1552. // 空的
  1553. }
  1554. if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
  1555. retailRadio = retailRadio.add(new BigDecimal(String.valueOf(esmRetail.getDisrate1()))).setScale(2, BigDecimal.ROUND_DOWN);
  1556. retailFeeLevel1 = feeRuleSchemeService.calcRetail(
  1557. externalOrderFeeVo.getJqPremium(),
  1558. externalOrderFeeVo.getJqRadio(),
  1559. externalOrderFeeVo.getSyPremium(),
  1560. externalOrderFeeVo.getSyRadio(),
  1561. externalOrderFeeVo.getNoPremium(),
  1562. externalOrderFeeVo.getNoRadio(),
  1563. retailProportion.getJqRetailLevel1Proportion(),
  1564. retailProportion.getSyRetailLevel1Proportion(),
  1565. retailProportion.getNoRetailLevel1Proportion());
  1566. //一级 retailFeeLevel1.getTotalRetailPremiums()
  1567. } else {
  1568. // 空的
  1569. }
  1570. } else {
  1571. //null
  1572. }
  1573. } else {
  1574. // null
  1575. }
  1576. //endregion
  1577. //region 设置机构管理费
  1578. //交强机构管理费
  1579. BigDecimal jqDeptRadio =
  1580. ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1581. FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(externalOrderFeeVo.getJqPremium(),
  1582. ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(),
  1583. ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(),
  1584. ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1585. BigDecimal syDeptRadio =
  1586. ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1587. FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(externalOrderFeeVo.getSyPremium(),
  1588. ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(),
  1589. ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(),
  1590. ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1591. BigDecimal noDeptRadio =
  1592. ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1593. FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(externalOrderFeeVo.getNoPremium(),
  1594. ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(),
  1595. ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(),
  1596. ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1597. //endregion
  1598. //region 出口费用
  1599. //交强出口手续费比例
  1600. FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(
  1601. externalOrderFeeVo.getJqPremium(),
  1602. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
  1603. externalOrderFeeVo.getJqRadio(),
  1604. jqDeptRadio,
  1605. retailRadio,
  1606. taxRadio,
  1607. jqReCalcuLateProportion.getProxyProportion());
  1608. //商业出口手续费比例
  1609. FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(
  1610. externalOrderFeeVo.getSyPremium(),
  1611. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
  1612. externalOrderFeeVo.getSyRadio(),
  1613. syDeptRadio,
  1614. retailRadio,
  1615. taxRadio,
  1616. syReCalcuLateProportion.getProxyProportion());
  1617. //非车出口手续费比例
  1618. FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(
  1619. externalOrderFeeVo.getNoPremium(),
  1620. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
  1621. externalOrderFeeVo.getNoRadio(),
  1622. noDeptRadio,
  1623. retailRadio,
  1624. taxRadio,
  1625. noReCalcuLateProportion.getProxyProportion());
  1626. externalOrderFeeVo.setJqExportPremium(jqExportFee.getTotalAmount());
  1627. externalOrderFeeVo.setJqExportRadio(jqExportFee.getTotalProportion());
  1628. externalOrderFeeVo.setSyExportPremium(syExportFee.getTotalAmount());
  1629. externalOrderFeeVo.setSyExportRadio(syExportFee.getTotalProportion());
  1630. externalOrderFeeVo.setNoExportPremium(noExportFee.getTotalAmount());
  1631. externalOrderFeeVo.setNoExportRadio(noExportFee.getTotalProportion());
  1632. //endregion
  1633. return externalOrderFeeVo;
  1634. }
  1635. @Override
  1636. public void calcCostsExternalTest(PtlAgreementProductCostsNew ptlAgreementProductCostsNew, InsAreaCompany insAreaCompany) {
  1637. //获取协议信息
  1638. // 外部订单比例
  1639. PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
  1640. InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
  1641. SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
  1642. BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus());
  1643. BigDecimal taxRadio = new BigDecimal("1.00");
  1644. //如果是外部订单则 不含税
  1645. if (ptlAgreement.getWithTax().equals("否")) {
  1646. taxRadio = new BigDecimal("1.06");
  1647. }
  1648. //税比例 固定1.06
  1649. //查找入口与出口费用比例
  1650. //出口配置
  1651. PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
  1652. ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>().eq(PtlAgreementProductCostsExport::getCostsId, ptlAgreementProductCostsNew.getId()));
  1653. InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  1654. insFeeOrderNew.setId(IdGenerate.nextId());
  1655. insFeeOrderNew.setCostsId(ptlAgreementProductCostsNew.getId());
  1656. insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
  1657. //存储部门id与用户id
  1658. InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
  1659. InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
  1660. if (insFeeOrderNewByCompanyId != null) {
  1661. insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
  1662. }
  1663. insFeeOrderNew.setDeptId(order.getDeptid());
  1664. insFeeOrderNew.setUserId(order.getUserid());
  1665. insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
  1666. insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
  1667. insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
  1668. insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
  1669. //不含税
  1670. BigDecimal bigDecimal = new BigDecimal("1.06");
  1671. insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
  1672. insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
  1673. insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
  1674. //region 计算入口费用
  1675. //交强入口信息
  1676. FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getJqPremium(),
  1677. new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
  1678. new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio);
  1679. insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
  1680. insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
  1681. insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
  1682. insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
  1683. insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
  1684. insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
  1685. //商业入口信息
  1686. FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
  1687. new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()),
  1688. new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
  1689. insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
  1690. insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
  1691. insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
  1692. insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
  1693. insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
  1694. insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
  1695. //非车入口信息
  1696. FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
  1697. new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
  1698. new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
  1699. insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
  1700. insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
  1701. insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
  1702. insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
  1703. insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
  1704. insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
  1705. //endregion
  1706. //region 重新计算管理费比例和分销比例
  1707. List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
  1708. new Object[]{sysUser.getDeptId()});
  1709. Integer retailLevel = 0;
  1710. //默认分销比例设置
  1711. RetailProportion retailProportion = new RetailProportion();
  1712. if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
  1713. retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
  1714. //赋值默认的分销比例
  1715. retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
  1716. }
  1717. //获取交强机构管理费总比例
  1718. BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
  1719. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
  1720. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
  1721. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
  1722. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1723. //获取商业机构管理费总比例
  1724. BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
  1725. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
  1726. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
  1727. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
  1728. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1729. //获取非车机构管理费总比例
  1730. BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
  1731. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
  1732. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
  1733. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
  1734. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1735. //获取交强分销总比例
  1736. BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
  1737. .add(retailProportion.getJqRetailLevel2Proportion())
  1738. .add(retailProportion.getJqRetailLevel3Proportion());
  1739. //获取商业分销总比例
  1740. BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
  1741. .add(retailProportion.getSyRetailLevel2Proportion())
  1742. .add(retailProportion.getSyRetailLevel3Proportion());
  1743. //获取非车分销总比例
  1744. BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
  1745. .add(retailProportion.getNoRetailLevel2Proportion())
  1746. .add(retailProportion.getNoRetailLevel3Proportion());
  1747. //重新计算比例 入口是否超出支付的比例
  1748. ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
  1749. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
  1750. jqDeptProportion,
  1751. jqRetailProportion,
  1752. taxRadio,
  1753. retailLevel,
  1754. ptlAgreementProductCostsExport,
  1755. retailProportion,
  1756. "jq",
  1757. enterProportion
  1758. );
  1759. ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
  1760. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
  1761. syDeptProportion,
  1762. syRetailProportion,
  1763. taxRadio,
  1764. retailLevel,
  1765. ptlAgreementProductCostsExport,
  1766. retailProportion,
  1767. "sy",
  1768. enterProportion
  1769. );
  1770. ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
  1771. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
  1772. noDeptProportion,
  1773. noRetailProportion,
  1774. taxRadio,
  1775. retailLevel,
  1776. ptlAgreementProductCostsExport,
  1777. retailProportion,
  1778. "no",
  1779. enterProportion
  1780. );
  1781. retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
  1782. // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport);
  1783. //endregion
  1784. //region 计算分销费用
  1785. //分销总比例
  1786. BigDecimal jqRetailRadio = new BigDecimal("0");
  1787. BigDecimal syRetailRadio = new BigDecimal("0");
  1788. BigDecimal noRetailRadio = new BigDecimal("0");
  1789. FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
  1790. FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
  1791. FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
  1792. //分销总比例
  1793. BigDecimal retailRadio = new BigDecimal("0");
  1794. if (esmRetailList != null && !esmRetailList.isEmpty()) {
  1795. EsmRetail esmRetail = esmRetailList.get(0);
  1796. //分销等级
  1797. insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
  1798. //用户分销人员id
  1799. List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
  1800. if (esmRetail != null) {
  1801. BigDecimal sumPremium = insFeeOrderNew.getJqPremium().add(insFeeOrderNew.getSyPremium()).add(insFeeOrderNew.getNoPremium());
  1802. if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
  1803. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate3())));
  1804. retailRadio = retailRadio.add(insFeeOrderNew.getThirdDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  1805. retailFeeLevel3 = feeRuleSchemeService.calcRetail(
  1806. insFeeOrderNew.getJqPremium(),
  1807. insFeeOrderNew.getJqCostsProportion(),
  1808. insFeeOrderNew.getSyPremium(),
  1809. insFeeOrderNew.getSyCostsProportion(),
  1810. insFeeOrderNew.getNoPremium(),
  1811. insFeeOrderNew.getNoCostsProportion(),
  1812. retailProportion.getJqRetailLevel3Proportion(),
  1813. retailProportion.getSyRetailLevel3Proportion(),
  1814. retailProportion.getNoRetailLevel3Proportion());
  1815. insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums());
  1816. if (parents != null && parents.size() > 2) {
  1817. insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
  1818. }
  1819. } else {
  1820. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  1821. }
  1822. if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
  1823. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate2())));
  1824. retailRadio = retailRadio.add(insFeeOrderNew.getSecondDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  1825. retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  1826. insFeeOrderNew.getJqCostsProportion(),
  1827. insFeeOrderNew.getSyPremium(),
  1828. insFeeOrderNew.getSyCostsProportion(),
  1829. insFeeOrderNew.getNoPremium(),
  1830. insFeeOrderNew.getNoCostsProportion(),
  1831. retailProportion.getJqRetailLevel2Proportion(),
  1832. retailProportion.getSyRetailLevel2Proportion(),
  1833. retailProportion.getNoRetailLevel2Proportion());
  1834. insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums());
  1835. if (parents != null && parents.size() > 1) {
  1836. insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
  1837. }
  1838. } else {
  1839. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  1840. }
  1841. if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
  1842. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate1())));
  1843. retailRadio = retailRadio.add(insFeeOrderNew.getFirstDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  1844. retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  1845. insFeeOrderNew.getJqCostsProportion(),
  1846. insFeeOrderNew.getSyPremium(),
  1847. insFeeOrderNew.getSyCostsProportion(),
  1848. insFeeOrderNew.getNoPremium(),
  1849. insFeeOrderNew.getNoCostsProportion(),
  1850. retailProportion.getJqRetailLevel1Proportion(),
  1851. retailProportion.getSyRetailLevel1Proportion(),
  1852. retailProportion.getNoRetailLevel1Proportion());
  1853. insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums());
  1854. if (parents != null && !parents.isEmpty()) {
  1855. insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
  1856. }
  1857. } else {
  1858. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  1859. }
  1860. } else {
  1861. insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
  1862. insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
  1863. insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
  1864. }
  1865. } else {
  1866. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  1867. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  1868. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  1869. }
  1870. insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3);
  1871. //endregion
  1872. //region 设置机构管理费
  1873. //交强机构管理费
  1874. BigDecimal jqDeptRadio =
  1875. ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1876. FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getJqPremium(),
  1877. ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(),
  1878. ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(),
  1879. ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1880. insFeeOrderNew.setJqDeptProportionLevel1(jqDeptManagerFee.getDeptProportionLevelOne());
  1881. insFeeOrderNew.setJqDeptPremiumsLevel1(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelOne()));
  1882. insFeeOrderNew.setJqDeptProportionLevel2(jqDeptManagerFee.getDeptProportionLevelTwo());
  1883. insFeeOrderNew.setJqDeptPremiumsLevel2(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelTwo()));
  1884. insFeeOrderNew.setJqDeptProportionLevel3(jqDeptManagerFee.getDeptProportionLevelThree());
  1885. insFeeOrderNew.setJqDeptPremiumsLevel3(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelThree()));
  1886. insFeeOrderNew.setJqDeptProportionLevel4(jqDeptManagerFee.getDeptProportionLevelFoure());
  1887. insFeeOrderNew.setJqDeptPremiumsLevel4(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFoure()));
  1888. insFeeOrderNew.setJqDeptProportionLevel5(jqDeptManagerFee.getDeptProportionLevelFive());
  1889. insFeeOrderNew.setJqDeptPremiumsLevel5(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFive()));
  1890. BigDecimal syDeptRadio =
  1891. ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1892. FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getSyPremium(),
  1893. ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(),
  1894. ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(),
  1895. ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1896. insFeeOrderNew.setSyDeptProportionLevel1(syDeptManagerFee.getDeptProportionLevelOne());
  1897. insFeeOrderNew.setSyDeptPremiumsLevel1(twoPeople(syDeptManagerFee.getDeptPremiumsLevelOne()));
  1898. insFeeOrderNew.setSyDeptProportionLevel2(syDeptManagerFee.getDeptProportionLevelTwo());
  1899. insFeeOrderNew.setSyDeptPremiumsLevel2(twoPeople(syDeptManagerFee.getDeptPremiumsLevelTwo()));
  1900. insFeeOrderNew.setSyDeptProportionLevel3(syDeptManagerFee.getDeptProportionLevelThree());
  1901. insFeeOrderNew.setSyDeptPremiumsLevel3(twoPeople(syDeptManagerFee.getDeptPremiumsLevelThree()));
  1902. insFeeOrderNew.setSyDeptProportionLevel4(syDeptManagerFee.getDeptProportionLevelFoure());
  1903. insFeeOrderNew.setSyDeptPremiumsLevel4(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFoure()));
  1904. insFeeOrderNew.setSyDeptProportionLevel5(syDeptManagerFee.getDeptProportionLevelFive());
  1905. insFeeOrderNew.setSyDeptPremiumsLevel5(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFive()));
  1906. BigDecimal noDeptRadio =
  1907. ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1908. FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getNoPremium(),
  1909. ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(),
  1910. ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(),
  1911. ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1912. insFeeOrderNew.setNoDeptProportionLevel1(noDeptManagerFee.getDeptProportionLevelOne());
  1913. insFeeOrderNew.setNoDeptPremiumsLevel1(twoPeople(noDeptManagerFee.getDeptPremiumsLevelOne()));
  1914. insFeeOrderNew.setNoDeptProportionLevel2(noDeptManagerFee.getDeptProportionLevelTwo());
  1915. insFeeOrderNew.setNoDeptPremiumsLevel2(twoPeople(noDeptManagerFee.getDeptPremiumsLevelTwo()));
  1916. insFeeOrderNew.setNoDeptProportionLevel3(noDeptManagerFee.getDeptProportionLevelThree());
  1917. insFeeOrderNew.setNoDeptPremiumsLevel3(twoPeople(noDeptManagerFee.getDeptPremiumsLevelThree()));
  1918. insFeeOrderNew.setNoDeptProportionLevel4(noDeptManagerFee.getDeptProportionLevelFoure());
  1919. insFeeOrderNew.setNoDeptPremiumsLevel4(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFoure()));
  1920. insFeeOrderNew.setNoDeptProportionLevel5(noDeptManagerFee.getDeptProportionLevelFive());
  1921. insFeeOrderNew.setNoDeptPremiumsLevel5(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFive()));
  1922. //endregion
  1923. //region 出口费用
  1924. //交强出口手续费比例
  1925. FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
  1926. insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, retailRadio, taxRadio, jqReCalcuLateProportion.getProxyProportion());
  1927. //商业出口手续费比例
  1928. FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
  1929. insFeeOrderNew.getSyCostsProportion(), syDeptRadio, retailRadio, taxRadio, syReCalcuLateProportion.getProxyProportion());
  1930. //非车出口手续费比例
  1931. FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
  1932. insFeeOrderNew.getNoCostsProportion(), noDeptRadio, retailRadio, taxRadio, noReCalcuLateProportion.getProxyProportion());
  1933. //出口手续费用
  1934. insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
  1935. insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
  1936. insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
  1937. //出口其他费用比例
  1938. insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
  1939. insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
  1940. insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
  1941. //出口其他费用
  1942. insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
  1943. insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
  1944. insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
  1945. //设置出口手续费比例
  1946. insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
  1947. insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
  1948. insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
  1949. // 外部订单费用
  1950. insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion());
  1951. insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums());
  1952. insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion());
  1953. insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums());
  1954. insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion());
  1955. insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums());
  1956. //endregion
  1957. //region 计算利润差值
  1958. //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
  1959. //分销交强费用
  1960. //分开算 1 2 3 级
  1961. BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1962. BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1963. BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1964. BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
  1965. //分销商业费用
  1966. BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1967. BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1968. BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1969. BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
  1970. //分销非车费用
  1971. BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1972. BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1973. BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1974. BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
  1975. BigDecimal jqDifference = jqEntranceFee.getTotalAmount()
  1976. .subtract(jqExportFee.getExternalPremiums())
  1977. .subtract(
  1978. (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
  1979. .subtract(
  1980. (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
  1981. )
  1982. .subtract(jqFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  1983. insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
  1984. BigDecimal syDifference = syEntranceFee.getTotalAmount()
  1985. .subtract(syExportFee.getExternalPremiums())
  1986. .subtract(
  1987. (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
  1988. .subtract(
  1989. (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
  1990. )
  1991. .subtract(syFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  1992. insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
  1993. BigDecimal noDifference = noEntranceFee.getTotalAmount()
  1994. .subtract(noExportFee.getExternalPremiums())
  1995. .subtract(
  1996. (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
  1997. .subtract(
  1998. (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
  1999. )
  2000. .subtract(noFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  2001. insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
  2002. //endregion
  2003. //region 比例逆推是否等于0
  2004. if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, retailRadio, taxRadio, insFeeOrderNew.getJqPremium()))
  2005. throw new SystemException("交强比例异常");
  2006. if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, retailRadio, taxRadio, insFeeOrderNew.getSyPremium()))
  2007. throw new SystemException("商业比例异常");
  2008. if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, retailRadio, taxRadio, insFeeOrderNew.getNoPremium()))
  2009. throw new SystemException("非车比例异常");
  2010. //endregion
  2011. insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
  2012. }
  2013. @Override
  2014. public void calcCostsExternalTelemarketing(PtlAgreementProductCostsExport ptlAgreementProductCostsExport, InsAreaCompany insAreaCompany) {
  2015. //获取协议信息
  2016. PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
  2017. InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
  2018. SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
  2019. //入口配置
  2020. PtlAgreementProductCostsNew ptlAgreementProductCostsNew = ptlAgreementProductCostsNewService.getById(ptlAgreementProductCostsExport.getCostsId());
  2021. ptlAgreementProductCostsNew.blank();
  2022. BigDecimal taxRadio = new BigDecimal("1.00");
  2023. //如果是外部订单则 不含税
  2024. if (ptlAgreement.getWithTax().equals("否") && ptlAgreement.getIsExternal() == 0) {
  2025. taxRadio = new BigDecimal("1.06");
  2026. }
  2027. InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  2028. insFeeOrderNew.setId(IdGenerate.nextId());
  2029. insFeeOrderNew.setCostsId(ptlAgreementProductCostsNew.getId());
  2030. insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
  2031. //存储部门id与用户id
  2032. InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
  2033. InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
  2034. if (insFeeOrderNewByCompanyId != null) {
  2035. insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
  2036. }
  2037. insFeeOrderNew.setDeptId(order.getDeptid());
  2038. insFeeOrderNew.setUserId(order.getUserid());
  2039. insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
  2040. insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
  2041. insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
  2042. insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
  2043. //不含税
  2044. BigDecimal bigDecimal = new BigDecimal("1.06");
  2045. insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
  2046. insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
  2047. insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
  2048. //region 计算入口费用
  2049. //交强入口信息
  2050. FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(
  2051. insFeeOrderNew.getJqPremium(),
  2052. new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
  2053. new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()),
  2054. taxRadio);
  2055. insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
  2056. insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
  2057. insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
  2058. insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
  2059. insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
  2060. insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
  2061. //商业入口信息
  2062. FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
  2063. new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()),
  2064. new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
  2065. insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
  2066. insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
  2067. insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
  2068. insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
  2069. insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
  2070. insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
  2071. //非车入口信息
  2072. FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
  2073. new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
  2074. new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
  2075. insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
  2076. insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
  2077. insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
  2078. insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
  2079. insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
  2080. insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
  2081. //endregion
  2082. //region 重新计算管理费比例和分销比例
  2083. List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
  2084. new Object[]{sysUser.getDeptId()});
  2085. Integer retailLevel = 0;
  2086. //默认分销比例设置
  2087. RetailProportion retailProportion = new RetailProportion();
  2088. if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
  2089. retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
  2090. //赋值默认的分销比例
  2091. retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
  2092. }
  2093. //获取交强机构管理费总比例
  2094. BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
  2095. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
  2096. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
  2097. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
  2098. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  2099. //获取商业机构管理费总比例
  2100. BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
  2101. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
  2102. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
  2103. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
  2104. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  2105. //获取非车机构管理费总比例
  2106. BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
  2107. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
  2108. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
  2109. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
  2110. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  2111. //获取交强分销总比例
  2112. BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
  2113. .add(retailProportion.getJqRetailLevel2Proportion())
  2114. .add(retailProportion.getJqRetailLevel3Proportion());
  2115. //获取商业分销总比例
  2116. BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
  2117. .add(retailProportion.getSyRetailLevel2Proportion())
  2118. .add(retailProportion.getSyRetailLevel3Proportion());
  2119. //获取非车分销总比例
  2120. BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
  2121. .add(retailProportion.getNoRetailLevel2Proportion())
  2122. .add(retailProportion.getNoRetailLevel3Proportion());
  2123. // 外部订单比例
  2124. BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus());
  2125. //重新计算比例 入口是否超出支付的比例
  2126. ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
  2127. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
  2128. jqDeptProportion,
  2129. jqRetailProportion,
  2130. taxRadio,
  2131. retailLevel,
  2132. ptlAgreementProductCostsExport,
  2133. retailProportion,
  2134. "jq",
  2135. enterProportion
  2136. );
  2137. ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
  2138. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
  2139. syDeptProportion,
  2140. syRetailProportion,
  2141. taxRadio,
  2142. retailLevel,
  2143. ptlAgreementProductCostsExport,
  2144. retailProportion,
  2145. "sy",
  2146. enterProportion
  2147. );
  2148. ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
  2149. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
  2150. noDeptProportion,
  2151. noRetailProportion,
  2152. taxRadio,
  2153. retailLevel,
  2154. ptlAgreementProductCostsExport,
  2155. retailProportion,
  2156. "no",
  2157. enterProportion
  2158. );
  2159. retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
  2160. //endregion
  2161. //region 计算分销费用
  2162. //获取分销比例
  2163. //分销总比例
  2164. BigDecimal jqRetailRadio = new BigDecimal("0");
  2165. BigDecimal syRetailRadio = new BigDecimal("0");
  2166. BigDecimal noRetailRadio = new BigDecimal("0");
  2167. FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
  2168. FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
  2169. FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
  2170. if (esmRetailList != null && !esmRetailList.isEmpty()) {
  2171. EsmRetail esmRetail = esmRetailList.get(0);
  2172. //分销等级
  2173. insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
  2174. //用户分销人员id
  2175. List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
  2176. if (esmRetail != null) {
  2177. if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
  2178. insFeeOrderNew.setThirdDetailProportion(retailProportion.getJqRetailLevel3Proportion());
  2179. retailFeeLevel3 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  2180. insFeeOrderNew.getJqCostsProportion(),
  2181. insFeeOrderNew.getSyPremium(),
  2182. insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
  2183. insFeeOrderNew.getNoPremium(),
  2184. insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
  2185. retailProportion.getJqRetailLevel3Proportion(),
  2186. retailProportion.getSyRetailLevel3Proportion(),
  2187. retailProportion.getNoRetailLevel3Proportion());
  2188. insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums());
  2189. if (parents != null && parents.size() > 2) {
  2190. insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
  2191. }
  2192. } else {
  2193. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  2194. }
  2195. if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
  2196. insFeeOrderNew.setSecondDetailProportion(retailProportion.getJqRetailLevel2Proportion());
  2197. retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  2198. insFeeOrderNew.getJqCostsProportion(),
  2199. insFeeOrderNew.getSyPremium(),
  2200. insFeeOrderNew.getSyCostsProportion(),
  2201. insFeeOrderNew.getNoPremium(),
  2202. insFeeOrderNew.getNoCostsProportion(),
  2203. retailProportion.getJqRetailLevel2Proportion(),
  2204. retailProportion.getSyRetailLevel2Proportion(),
  2205. retailProportion.getNoRetailLevel2Proportion());
  2206. insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums());
  2207. if (parents != null && parents.size() > 1) {
  2208. insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
  2209. }
  2210. } else {
  2211. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  2212. }
  2213. if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
  2214. insFeeOrderNew.setFirstDetailProportion(retailProportion.getJqRetailLevel1Proportion());
  2215. retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  2216. insFeeOrderNew.getJqCostsProportion(),
  2217. insFeeOrderNew.getSyPremium(),
  2218. insFeeOrderNew.getSyCostsProportion(),
  2219. insFeeOrderNew.getNoPremium(),
  2220. insFeeOrderNew.getNoCostsProportion(),
  2221. retailProportion.getJqRetailLevel1Proportion(),
  2222. retailProportion.getSyRetailLevel1Proportion(),
  2223. retailProportion.getNoRetailLevel1Proportion());
  2224. insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums());
  2225. if (parents != null && !parents.isEmpty()) {
  2226. insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
  2227. }
  2228. } else {
  2229. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  2230. }
  2231. } else {
  2232. insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
  2233. insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
  2234. insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
  2235. }
  2236. } else {
  2237. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  2238. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  2239. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  2240. }
  2241. jqRetailRadio = jqRetailRadio.add(retailFeeLevel1.getJqRetailProportion())
  2242. .add(retailFeeLevel2.getJqRetailProportion())
  2243. .add(retailFeeLevel3.getJqRetailProportion());
  2244. syRetailRadio = syRetailRadio.add(retailFeeLevel1.getSyRetailProportion())
  2245. .add(retailFeeLevel2.getSyRetailProportion())
  2246. .add(retailFeeLevel3.getSyRetailProportion());
  2247. noRetailRadio = noRetailRadio.add(retailFeeLevel1.getNoRetailProportion())
  2248. .add(retailFeeLevel2.getNoRetailProportion())
  2249. .add(retailFeeLevel3.getNoRetailProportion());
  2250. insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3);
  2251. //endregion
  2252. //region 设置机构管理费
  2253. //交强机构管理费
  2254. BigDecimal jqDeptRadio =
  2255. jqReCalcuLateProportion.getDept_level_1_proportion()
  2256. .add(jqReCalcuLateProportion.getDept_level_2_proportion())
  2257. .add(jqReCalcuLateProportion.getDept_level_3_proportion())
  2258. .add(jqReCalcuLateProportion.getDept_level_4_proportion())
  2259. .add(jqReCalcuLateProportion.getDept_level_5_proportion());
  2260. FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
  2261. insFeeOrderNew.getJqPremium(),
  2262. jqReCalcuLateProportion.getDept_level_1_proportion(),
  2263. jqReCalcuLateProportion.getDept_level_2_proportion(),
  2264. jqReCalcuLateProportion.getDept_level_3_proportion(),
  2265. jqReCalcuLateProportion.getDept_level_4_proportion(),
  2266. jqReCalcuLateProportion.getDept_level_5_proportion());
  2267. BigDecimal syDeptRadio =
  2268. syReCalcuLateProportion.getDept_level_1_proportion()
  2269. .add(syReCalcuLateProportion.getDept_level_2_proportion())
  2270. .add(syReCalcuLateProportion.getDept_level_3_proportion())
  2271. .add(syReCalcuLateProportion.getDept_level_4_proportion())
  2272. .add(syReCalcuLateProportion.getDept_level_5_proportion());
  2273. FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
  2274. insFeeOrderNew.getSyPremium(),
  2275. syReCalcuLateProportion.getDept_level_1_proportion(),
  2276. syReCalcuLateProportion.getDept_level_2_proportion(),
  2277. syReCalcuLateProportion.getDept_level_3_proportion(),
  2278. syReCalcuLateProportion.getDept_level_4_proportion(),
  2279. syReCalcuLateProportion.getDept_level_5_proportion());
  2280. BigDecimal noDeptRadio =
  2281. noReCalcuLateProportion.getDept_level_1_proportion()
  2282. .add(noReCalcuLateProportion.getDept_level_2_proportion())
  2283. .add(noReCalcuLateProportion.getDept_level_3_proportion())
  2284. .add(noReCalcuLateProportion.getDept_level_4_proportion())
  2285. .add(noReCalcuLateProportion.getDept_level_5_proportion());
  2286. FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
  2287. insFeeOrderNew.getNoPremium(),
  2288. noReCalcuLateProportion.getDept_level_1_proportion(),
  2289. noReCalcuLateProportion.getDept_level_2_proportion(),
  2290. noReCalcuLateProportion.getDept_level_3_proportion(),
  2291. noReCalcuLateProportion.getDept_level_4_proportion(),
  2292. noReCalcuLateProportion.getDept_level_5_proportion());
  2293. insFeeOrderNew.assignDept(jqDeptManagerFee, syDeptManagerFee, noDeptManagerFee);
  2294. //endregion
  2295. //region 出口费用
  2296. //交强出口手续费比例
  2297. FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(
  2298. insFeeOrderNew.getJqPremium(),
  2299. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
  2300. insFeeOrderNew.getJqCostsProportion(),
  2301. jqDeptRadio,
  2302. jqRetailRadio,
  2303. taxRadio,
  2304. jqReCalcuLateProportion.getProxyProportion()
  2305. );
  2306. //商业出口手续费比例
  2307. FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(
  2308. insFeeOrderNew.getSyPremium(),
  2309. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
  2310. insFeeOrderNew.getSyCostsProportion(),
  2311. syDeptRadio,
  2312. syRetailRadio,
  2313. taxRadio,
  2314. syReCalcuLateProportion.getProxyProportion()
  2315. );
  2316. //非车出口手续费比例
  2317. FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(
  2318. insFeeOrderNew.getNoPremium(),
  2319. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
  2320. insFeeOrderNew.getNoCostsProportion(),
  2321. noDeptRadio,
  2322. noRetailRadio,
  2323. taxRadio,
  2324. noReCalcuLateProportion.getProxyProportion()
  2325. );
  2326. //出口手续费用
  2327. insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
  2328. insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
  2329. insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
  2330. //出口其他费用比例
  2331. insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
  2332. insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
  2333. insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
  2334. //出口其他费用
  2335. insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
  2336. insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
  2337. insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
  2338. //设置出口手续费比例
  2339. insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
  2340. insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
  2341. insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
  2342. // 外部费用
  2343. insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion());
  2344. insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums());
  2345. insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion());
  2346. insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums());
  2347. insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion());
  2348. insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums());
  2349. //endregion
  2350. //region 计算利润差值
  2351. //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
  2352. //分销交强费用
  2353. //分开算 1 2 3 级
  2354. BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2355. BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2356. BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2357. BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
  2358. //分销商业费用
  2359. BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2360. BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2361. BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2362. BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
  2363. //分销非车费用
  2364. BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2365. BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2366. BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2367. BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
  2368. BigDecimal jqDifference = jqEntranceFee.getTotalAmount()
  2369. .subtract(jqExportFee.getExternalPremiums())
  2370. .subtract(
  2371. (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
  2372. .subtract(
  2373. (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
  2374. )
  2375. .subtract(jqFenXiao)
  2376. .setScale(5, BigDecimal.ROUND_HALF_DOWN);
  2377. insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
  2378. BigDecimal syDifference = syEntranceFee.getTotalAmount()
  2379. .subtract(syExportFee.getExternalPremiums())
  2380. .subtract(
  2381. (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
  2382. .subtract(
  2383. (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
  2384. )
  2385. .subtract(syFenXiao)
  2386. .setScale(5, BigDecimal.ROUND_HALF_DOWN);
  2387. insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
  2388. BigDecimal noDifference = noEntranceFee.getTotalAmount()
  2389. .subtract(noExportFee.getExternalPremiums())
  2390. .subtract(
  2391. (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
  2392. .subtract(
  2393. (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
  2394. )
  2395. .subtract(noFenXiao)
  2396. .setScale(5, BigDecimal.ROUND_HALF_DOWN);
  2397. insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
  2398. //endregion
  2399. //region 比例逆推是否等于0
  2400. if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, jqRetailRadio, taxRadio, insFeeOrderNew.getJqPremium()))
  2401. throw new SystemException("交强比例异常");
  2402. if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, syRetailRadio, taxRadio, insFeeOrderNew.getSyPremium()))
  2403. throw new SystemException("商业比例异常");
  2404. if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, noRetailRadio, taxRadio, insFeeOrderNew.getNoPremium()))
  2405. throw new SystemException("非车比例异常");
  2406. //endregion
  2407. insFeeOrderNewHistoryService.saveInsFeeOrderNewHistory(insFeeOrderNew);
  2408. insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
  2409. }
  2410. /**
  2411. * 判断是否包含非车险
  2412. *
  2413. * @param insAreaCompany
  2414. * @return
  2415. */
  2416. private boolean isContainNonCar(InsAreaCompany insAreaCompany) {
  2417. if (insAreaCompany.getCrossInsurance() != null && insAreaCompany.getJypremium().equals(BigDecimal.ZERO)) {
  2418. return false;
  2419. }
  2420. return true;
  2421. }
  2422. /**
  2423. * 匹配费用因子
  2424. *
  2425. * @param agreementProductCosts
  2426. * @param insAreaCompany
  2427. * @param insOrders
  2428. * @return
  2429. */
  2430. private String verificationCosts(List<AgreementProductCosts> agreementProductCosts, QuoteRespVo quoteRespVo, InsAreaCompany insAreaCompany,
  2431. InsOrders insOrders, StringBuilder logs) {
  2432. //匹配费用因子
  2433. //获取所有费用属性
  2434. List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList = ptlAgreementUndwrtRulesAttrService.getUndwrtRulesAttrList();
  2435. //获取新旧车信息
  2436. PtlNewCarJudgeRules carJudgeRule = getCarJudgeRule(insAreaCompany.getCompanyId(), insOrders.getCarinfo().getString("cimodelclass"));
  2437. //获取所有费用属性关联
  2438. List<RuleAttrMappingVo> ruleAttrMappingVoList = RuleAttrMappingVo.getRuleAttrMappingVoList(quoteRespVo, insAreaCompany, insOrders,
  2439. undwrtRulesAttrList, carJudgeRule);
  2440. for (int i = 0; i < agreementProductCosts.size(); i++) {
  2441. //判断是否匹配
  2442. log.debug("费用因子匹配开始:" + agreementProductCosts.get(i).getId());
  2443. log.debug("车牌号:" + insOrders.getLicenseno());
  2444. log.debug("费用因子备注:" + agreementProductCosts.get(i).getCostsDescription());
  2445. logs.append("费用id:" + agreementProductCosts.get(i).getId() + "\n");
  2446. logs.append("费用因子描述:" + agreementProductCosts.get(i).getCostsDescription() + "\n");
  2447. if (judgements(agreementProductCosts.get(i).getCostsAttrLinks(), undwrtRulesAttrList, ruleAttrMappingVoList, logs)) {
  2448. //返回 费用id 如果需要匹配非车的情况 将返回值返回list 后赛选
  2449. return agreementProductCosts.get(i).getId();
  2450. }
  2451. log.debug("当前费用因子匹配结束\n");
  2452. }
  2453. return null;
  2454. // throw new SystemException("费用因子匹配失败");
  2455. }
  2456. private boolean verificationRules(List<PtlAgreementUndwrtRulesNew> ptlAgreementUndwrtRulesNews, InsAreaCompany insAreaCompany,
  2457. InsOrders insOrders) {
  2458. StringBuilder logs = new StringBuilder();
  2459. //匹配承保规则
  2460. //获取所有承保规则属性
  2461. List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList = ptlAgreementUndwrtRulesAttrService.getUndwrtRulesAttrList();
  2462. //获取所有费用属性关联
  2463. List<RuleAttrMappingVo> ruleAttrMappingVoList = RuleAttrMappingVo.getRuleAttrMappingVoList(null,insAreaCompany, insOrders,
  2464. undwrtRulesAttrList, getCarJudgeRule(insAreaCompany.getCompanyId(),insOrders.getCarinfo().getString("cimodelclass")));
  2465. for (int i = 0; i < ptlAgreementUndwrtRulesNews.size(); i++) {
  2466. logs.append("触发承保规则:" + ptlAgreementUndwrtRulesNews.get(i).getRuleDescription() + "\n");
  2467. //判断是否匹配
  2468. if (!judgementsRules(ptlAgreementUndwrtRulesNews.get(i).getRulesAttrList(), undwrtRulesAttrList, ruleAttrMappingVoList, logs,insOrders)) {
  2469. throw new SystemException(logs.toString());
  2470. }else{
  2471. //如果没有出现异常则清空匹配消息
  2472. logs.delete(0,logs.length());
  2473. }
  2474. }
  2475. return true;
  2476. }
  2477. /**
  2478. * 费用因子的对比
  2479. *
  2480. * @param ptlAgreementProductCostsAttrLinks 费用因子范围规则
  2481. * @param rulesAttrs 费用因子属性
  2482. * @param ruleAttrMappingVoList 表单提交的值
  2483. * @return
  2484. */
  2485. private boolean judgements(List<PtlAgreementProductCostsAttrLink> ptlAgreementProductCostsAttrLinks,
  2486. List<PtlAgreementUndwrtRulesAttr> rulesAttrs, List<RuleAttrMappingVo> ruleAttrMappingVoList,
  2487. StringBuilder logs) {
  2488. boolean useFlag = true;
  2489. for (PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink : ptlAgreementProductCostsAttrLinks) {
  2490. //查找规则中的 传值属性
  2491. RuleAttrMappingVo ruleAttrMappingVo = ruleAttrMappingVoList.stream()
  2492. .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
  2493. .findFirst()
  2494. .orElse(null);
  2495. //如果查找不到 传值属性 直接费用对比失败
  2496. if (ruleAttrMappingVo == null) {
  2497. log.debug("传入的值找不到该属性:" + ptlAgreementProductCostsAttrLink.getAttrCode());
  2498. log.debug("规则匹配失败:" + ptlAgreementProductCostsAttrLink.getAttrCode());
  2499. List<PtlAgreementUndwrtRulesAttr> collect = rulesAttrs.stream()
  2500. .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
  2501. .collect(Collectors.toList());
  2502. if (!collect.isEmpty()) {
  2503. logs.append("规则匹配失败:" + collect.get(0).getAttrName() + "\n");
  2504. }
  2505. return false;
  2506. }
  2507. //查找 费用因子规则
  2508. PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr = rulesAttrs.stream()
  2509. .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
  2510. .findFirst()
  2511. .get();
  2512. if(!Objects.isNull(ruleAttrMappingVo.getValue())) {
  2513. useFlag = attrEqual(ptlAgreementProductCostsAttrLink, ptlAgreementUndwrtRulesAttr, ruleAttrMappingVo.getValue());
  2514. }else{
  2515. useFlag = false;
  2516. }
  2517. if (!useFlag) {
  2518. log.debug("检验的值:" + ptlAgreementProductCostsAttrLink.getMin());
  2519. log.debug("传入的值:" + ruleAttrMappingVo.getValue());
  2520. log.debug("规则匹配失败:" + ptlAgreementProductCostsAttrLink.getAttrCode());
  2521. List<PtlAgreementUndwrtRulesAttr> collect = rulesAttrs.stream()
  2522. .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
  2523. .collect(Collectors.toList());
  2524. if (ptlAgreementProductCostsAttrLink.getMin() != null) {
  2525. logs.append("检验的值:" + ptlAgreementProductCostsAttrLink.getMin() + "\n");
  2526. } else {
  2527. logs.append("检验的值:" + ptlAgreementProductCostsAttrLink.getMax() + "\n");
  2528. }
  2529. logs.append("传入的值:" + ruleAttrMappingVo.getValue() + "\n");
  2530. if (!collect.isEmpty()) {
  2531. logs.append("<span style=\"color:red;\">规则匹配失败:" + collect.get(0).getAttrName() + "</span>\n");
  2532. }
  2533. return false;
  2534. }
  2535. }
  2536. return useFlag;
  2537. }
  2538. /**
  2539. * 承保规则因子的对比
  2540. *
  2541. * @param ptlAgreementUndwrtRulesAttrLinks
  2542. * @param rulesAttrs
  2543. * @param ruleAttrMappingVoList
  2544. * @return
  2545. */
  2546. private boolean judgementsRules(List<PtlAgreementUndwrtRulesAttrLink> ptlAgreementUndwrtRulesAttrLinks,
  2547. List<PtlAgreementUndwrtRulesAttr> rulesAttrs, List<RuleAttrMappingVo> ruleAttrMappingVoList,
  2548. StringBuilder logs,InsOrders insOrders) {
  2549. boolean useFlag = true;
  2550. for (int i = 0; i < ptlAgreementUndwrtRulesAttrLinks.size(); i++) {
  2551. int finalI = i;
  2552. //查找规则中的 传值属性
  2553. RuleAttrMappingVo ruleAttrMappingVo = ruleAttrMappingVoList.stream().filter(x ->
  2554. x.getAttrCode().equals(ptlAgreementUndwrtRulesAttrLinks.get(finalI).getAttrCode())).findFirst().orElse(null);
  2555. //如果查找不到 传值属性 直接费用对比失败
  2556. if (ruleAttrMappingVo == null) {
  2557. return true;
  2558. }
  2559. //查找 费用因子规则
  2560. PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr =
  2561. rulesAttrs.stream().filter(x -> x.getAttrCode().equals(ptlAgreementUndwrtRulesAttrLinks.get(finalI).getAttrCode())).findFirst().get();
  2562. //如果是多选 对value进行转换
  2563. if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
  2564. PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal =
  2565. ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x ->
  2566. x.getName().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null);
  2567. ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getName());
  2568. }
  2569. //如果是单选 并且是 性别的话 转换为code
  2570. if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
  2571. if ("CarOwnersSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) || "ApplicantSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) ||
  2572. "InsuredSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode())) {
  2573. PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal =
  2574. ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x ->
  2575. x.getCode().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null);
  2576. ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getCode());
  2577. }
  2578. }
  2579. if(!Objects.isNull(ruleAttrMappingVo.getValue())) {
  2580. useFlag = attrEqual(ptlAgreementUndwrtRulesAttrLinks.get(i), ptlAgreementUndwrtRulesAttr, ruleAttrMappingVo.getValue(),insOrders);
  2581. }else{
  2582. useFlag = false;
  2583. }
  2584. if (useFlag) {
  2585. return true;
  2586. } else {
  2587. logs.append("规则匹配失败:" + ptlAgreementUndwrtRulesAttrLinks.get(i).getAttrCode() + "\n");
  2588. if (ptlAgreementUndwrtRulesAttrLinks.get(i).getMin() != null) {
  2589. logs.append("校验的值:" + ptlAgreementUndwrtRulesAttrLinks.get(i).getMin() + "\n");
  2590. } else {
  2591. logs.append("校验的值:" + ptlAgreementUndwrtRulesAttrLinks.get(i).getMax() + "\n");
  2592. }
  2593. logs.append("传入的值:" + ruleAttrMappingVo.getValue() + "\n");
  2594. }
  2595. }
  2596. return useFlag;
  2597. }
  2598. /**
  2599. * 费用因子的对比 强制非车险
  2600. *
  2601. * @param ptlAgreementProductCostsAttrLinks 费用因子范围规则
  2602. * @param rulesAttrs 费用因子属性
  2603. * @param ruleAttrMappingVoList 表单提交的值
  2604. * @return
  2605. */
  2606. private boolean judgementsIsNoCar(List<PtlAgreementProductCostsAttrLink> ptlAgreementProductCostsAttrLinks,
  2607. List<PtlAgreementUndwrtRulesAttr> rulesAttrs, List<RuleAttrMappingVo> ruleAttrMappingVoList) {
  2608. boolean useFlag = true;
  2609. for (int i = 0; i < ptlAgreementProductCostsAttrLinks.size(); i++) {
  2610. int finalI = i;
  2611. //查找规则中的 传值属性
  2612. RuleAttrMappingVo ruleAttrMappingVo =
  2613. ruleAttrMappingVoList.stream().filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLinks.get(finalI).getAttrCode())).findFirst().orElse(null);
  2614. //如果是强制非车险
  2615. if (ptlAgreementProductCostsAttrLinks.get(i).getAttrCode().equals("IsNonMotorInsurance"))
  2616. continue;
  2617. //如果查找不到 传值属性 直接费用对比失败
  2618. if (ruleAttrMappingVo == null)
  2619. return false;
  2620. //查找 费用因子规则
  2621. PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr =
  2622. rulesAttrs.stream().filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLinks.get(finalI).getAttrCode())).findFirst().get();
  2623. //如果是多选 对value进行转换
  2624. if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
  2625. PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal =
  2626. ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x ->
  2627. x.getCode().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null);
  2628. ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getName());
  2629. }
  2630. //如果是单选 并且是 性别的话 转换为code
  2631. if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
  2632. if ("CarOwnersSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) || "ApplicantSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) ||
  2633. "InsuredSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode())) {
  2634. PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal =
  2635. ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x ->
  2636. x.getName().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null);
  2637. ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getCode());
  2638. }
  2639. }
  2640. useFlag = attrEqual(ptlAgreementProductCostsAttrLinks.get(i), ptlAgreementUndwrtRulesAttr, ruleAttrMappingVo.getValue());
  2641. if (!useFlag) {
  2642. System.out.printf("规则匹配失败:" + ptlAgreementProductCostsAttrLinks.get(i).getAttrCode());
  2643. return false;
  2644. }
  2645. }
  2646. return useFlag;
  2647. }
  2648. /**
  2649. * 属性比较 返回 是否匹配
  2650. *
  2651. * @param ptlAgreementProductCostsAttrLink
  2652. * @param ptlAgreementUndwrtRulesAttr
  2653. * @param value
  2654. * @return
  2655. */
  2656. private boolean attrEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink,
  2657. PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, String value) {
  2658. if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
  2659. return checkBoxEqual(ptlAgreementProductCostsAttrLink, value);
  2660. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("inputNumber")) {
  2661. return inputNumberEqual(ptlAgreementProductCostsAttrLink, value);
  2662. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("input")) {
  2663. //截取身份证号码
  2664. if (ptlAgreementProductCostsAttrLink.getAttrCode().equals("CarOwnersIDNumber") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("ApplicantIDNumber") ||
  2665. ptlAgreementProductCostsAttrLink.getAttrCode().equals("InsuredIDNumber")) {
  2666. value = value.substring(0, ptlAgreementProductCostsAttrLink.getMin().length());
  2667. }
  2668. return inputTextEqual(ptlAgreementProductCostsAttrLink, value);
  2669. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("select")) {
  2670. //截取车牌
  2671. if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("LicenseNo")) {
  2672. value = value.substring(0, 2);
  2673. }
  2674. return selectEqual(ptlAgreementProductCostsAttrLink, value);
  2675. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
  2676. return radioEqual(ptlAgreementProductCostsAttrLink, value);
  2677. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("datetime")){ // 时间
  2678. return dateTimeEqual(ptlAgreementProductCostsAttrLink, value);
  2679. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("date")){
  2680. return dateEqual(ptlAgreementProductCostsAttrLink, value);
  2681. }
  2682. return false;
  2683. }
  2684. private boolean attrEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink,
  2685. PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, String value,InsOrders insOrders) {
  2686. if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
  2687. return checkBoxEqual(ptlAgreementUndwrtRulesAttrLink, value);
  2688. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("inputNumber")) {
  2689. //如果是空字符串 则返回false
  2690. // if(value.equals("")){
  2691. // return false;
  2692. // }
  2693. return inputNumberEqual(ptlAgreementUndwrtRulesAttrLink, value);
  2694. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("input")) {
  2695. //截取身份证号码
  2696. if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("CarOwnersIDNumber") || ptlAgreementUndwrtRulesAttr.getAttrCode().equals("ApplicantIDNumber") ||
  2697. ptlAgreementUndwrtRulesAttr.getAttrCode().equals("InsuredIDNumber")) {
  2698. value = value.substring(0, ptlAgreementUndwrtRulesAttrLink.getMin().length());
  2699. }
  2700. return inputTextEqual(ptlAgreementUndwrtRulesAttrLink, value);
  2701. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("select")) {
  2702. //截取车牌
  2703. if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("LicenseNo")) {
  2704. value = value.substring(0, 2);
  2705. }
  2706. return selectEqual(ptlAgreementUndwrtRulesAttrLink, value);
  2707. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
  2708. return radioEqual(ptlAgreementUndwrtRulesAttrLink, value);
  2709. } else if(ptlAgreementUndwrtRulesAttr.getAttrType().equals("datetime")){
  2710. return dateTimeEqual(ptlAgreementUndwrtRulesAttrLink, value, insOrders);
  2711. } else if(ptlAgreementUndwrtRulesAttr.getAttrType().equals("date")){
  2712. return dateEqual(ptlAgreementUndwrtRulesAttrLink,value);
  2713. }
  2714. return false;
  2715. }
  2716. /**
  2717. * 属性为多选判断
  2718. *
  2719. * @param ptlAgreementProductCostsAttrLink
  2720. * @param value
  2721. * @return
  2722. */
  2723. private boolean checkBoxEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
  2724. String[] split = ptlAgreementProductCostsAttrLink.getMin().split(",");
  2725. for (String sp : split) {
  2726. if (sp.equals(value)) {
  2727. return true;
  2728. }
  2729. }
  2730. return false;
  2731. }
  2732. private boolean checkBoxEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
  2733. if (!ptlAgreementUndwrtRulesAttrLink.getMin().equals(value)) {
  2734. return true;
  2735. }
  2736. return false;
  2737. }
  2738. /**
  2739. * 属性为数值型判断
  2740. *
  2741. * @param ptlAgreementProductCostsAttrLink
  2742. * @param value
  2743. * @return
  2744. */
  2745. private boolean inputNumberEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
  2746. double v = Double.parseDouble(value);
  2747. //统一处理数值
  2748. if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2749. if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMin()) <= v &&
  2750. Double.parseDouble(ptlAgreementProductCostsAttrLink.getMax()) >= v) {
  2751. return true;
  2752. }
  2753. } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2754. if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMin()) > v) {
  2755. return true;
  2756. }
  2757. } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2758. if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMin()) >= v) {
  2759. return true;
  2760. }
  2761. } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2762. if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMax()) < v) {
  2763. return true;
  2764. }
  2765. } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2766. if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMax()) <= v) {
  2767. return true;
  2768. }
  2769. }
  2770. return false;
  2771. }
  2772. private boolean inputNumberEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
  2773. double v = Double.parseDouble(value);
  2774. //统一处理数值
  2775. if ("1".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  2776. if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMin()) <= v &&
  2777. Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMax()) >= v) {
  2778. return false;
  2779. }
  2780. } else if ("2".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  2781. if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMin()) > v) {
  2782. return false;
  2783. }
  2784. } else if ("3".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  2785. if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMin()) >= v) {
  2786. return false;
  2787. }
  2788. } else if ("4".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  2789. if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMax()) < v) {
  2790. return false;
  2791. }
  2792. } else if ("5".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  2793. if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMax()) <= v) {
  2794. return false;
  2795. }
  2796. }
  2797. return true;
  2798. }
  2799. /**
  2800. * 属性为输入框判断
  2801. *
  2802. * @param ptlAgreementProductCostsAttrLink
  2803. * @param value
  2804. * @return
  2805. */
  2806. private boolean inputTextEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
  2807. //将值进行分割
  2808. String[] split = ptlAgreementProductCostsAttrLink.getMin().split(",");
  2809. AtomicBoolean returnBool = new AtomicBoolean(false);
  2810. List<String> equalsMap = new ArrayList<>();
  2811. //字符型评分
  2812. equalsMap.add("CharacterBasedRating");
  2813. //交强字符型评分
  2814. equalsMap.add("JqCharacterBasedRating");
  2815. //商业字符型评分
  2816. equalsMap.add("SyCharacterBasedRating");
  2817. //equest 等于判断
  2818. if(equalsMap.contains(ptlAgreementProductCostsAttrLink.getAttrCode())){
  2819. boolean b = Arrays.stream(split).anyMatch(value::equals);
  2820. returnBool.set(b);
  2821. }else if((ptlAgreementProductCostsAttrLink.getAttrCode().equals("BrandandModel") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("CarOwnerName")
  2822. || ptlAgreementProductCostsAttrLink.getAttrCode().equals("CarOwnersAddress") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("ApplicantAddress")
  2823. || ptlAgreementProductCostsAttrLink.getAttrCode().equals("InsuredAddress"))
  2824. && ptlAgreementProductCostsAttrLink.getOperator().equals("2")){
  2825. //处理品牌型号 不包含的情况
  2826. boolean anyMatch = Arrays.stream(split)
  2827. .anyMatch(value::contains);
  2828. returnBool.set(!anyMatch);
  2829. }else {
  2830. boolean anyMatch = Arrays.stream(split)
  2831. .anyMatch(value::contains);
  2832. returnBool.set(anyMatch);
  2833. }
  2834. return returnBool.get();
  2835. }
  2836. private boolean inputTextEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
  2837. //将值进行分割
  2838. String[] split = ptlAgreementUndwrtRulesAttrLink.getMin().split(",");
  2839. AtomicBoolean returnBool = new AtomicBoolean(false);
  2840. List<String> equalsMap = new ArrayList<>();
  2841. //字符型评分
  2842. equalsMap.add("CharacterBasedRating");
  2843. //交强字符型评分
  2844. equalsMap.add("JqCharacterBasedRating");
  2845. //商业字符型评分
  2846. equalsMap.add("SyCharacterBasedRating");
  2847. //equest 等于判断
  2848. if(equalsMap.contains(ptlAgreementUndwrtRulesAttrLink.getAttrCode())){
  2849. boolean b = Arrays.stream(split).anyMatch(value::equals);
  2850. returnBool.set(b);
  2851. }else if((ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("BrandandModel") || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("CarOwnerName")
  2852. || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("CarOwnersAddress") || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("ApplicantAddress")
  2853. || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("InsuredAddress"))
  2854. && ptlAgreementUndwrtRulesAttrLink.getOperator().equals("2")){
  2855. //处理品牌型号 不包含的情况
  2856. boolean anyMatch = Arrays.stream(split)
  2857. .anyMatch(value::contains);
  2858. returnBool.set(!anyMatch);
  2859. }else {
  2860. boolean anyMatch = Arrays.stream(split)
  2861. .anyMatch(value::contains);
  2862. returnBool.set(anyMatch);
  2863. }
  2864. return !returnBool.get();
  2865. }
  2866. /**
  2867. * 属性为下拉框判断
  2868. *
  2869. * @param ptlAgreementProductCostsAttrLink
  2870. * @param value
  2871. * @return
  2872. */
  2873. private boolean selectEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
  2874. // 包含情况
  2875. if (ptlAgreementProductCostsAttrLink.getMin() != null && ptlAgreementProductCostsAttrLink.getMin().contains(value) && ptlAgreementProductCostsAttrLink.getOperator().equals("0")) {
  2876. return true;
  2877. }
  2878. // 不包含的情况
  2879. if (ptlAgreementProductCostsAttrLink.getMin()!= null && !ptlAgreementProductCostsAttrLink.getMin().contains(value) && ptlAgreementProductCostsAttrLink.getOperator().equals("1")) {
  2880. return true;
  2881. }
  2882. return false;
  2883. }
  2884. /**
  2885. * 属性为选择框判断
  2886. *
  2887. * @param ptlAgreementUndwrtRulesAttrLink
  2888. * @param value
  2889. * @return
  2890. */
  2891. private boolean selectEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
  2892. if (ptlAgreementUndwrtRulesAttrLink.getMin() == null) {
  2893. return false;
  2894. }
  2895. if (!ptlAgreementUndwrtRulesAttrLink.getMin().contains(value)) {
  2896. return true;
  2897. }
  2898. return false;
  2899. }
  2900. /**
  2901. * 属性为单选框判断
  2902. *
  2903. * @param ptlAgreementProductCostsAttrLink
  2904. * @param value
  2905. * @return
  2906. */
  2907. private boolean radioEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
  2908. //新能源判断
  2909. if ("NewEnergy".equals(ptlAgreementProductCostsAttrLink.getAttrCode())) {
  2910. // 是否是新能源车
  2911. boolean newEnergy = EnergyType.isNewEnergy(value);
  2912. if (newEnergy && ptlAgreementProductCostsAttrLink.getMin().equals("1")) {
  2913. return true;
  2914. } else if (!newEnergy && ptlAgreementProductCostsAttrLink.getMin().equals("0")) {
  2915. return true;
  2916. }
  2917. } else if (ptlAgreementProductCostsAttrLink.getMin().contains(value)) {
  2918. return true;
  2919. }
  2920. return false;
  2921. }
  2922. private boolean radioEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
  2923. //新能源判断
  2924. if ("NewEnergy".equals(ptlAgreementUndwrtRulesAttrLink.getAttrCode())) {
  2925. // 是否是新能源车
  2926. boolean newEnergy = EnergyType.isNewEnergy(value);
  2927. if (newEnergy && ptlAgreementUndwrtRulesAttrLink.getMin().equals("1")) {
  2928. return false;
  2929. } else if (!newEnergy && ptlAgreementUndwrtRulesAttrLink.getMin().equals("0")) {
  2930. return false;
  2931. }
  2932. } else if (ptlAgreementUndwrtRulesAttrLink.getMin().contains(value)) {
  2933. return false;
  2934. }
  2935. return true;
  2936. }
  2937. public boolean dateTimeEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value){
  2938. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  2939. if(Objects.isNull(value) || value.equals("")){
  2940. return false;
  2941. }
  2942. LocalDateTime v = LocalDateTime.parse(value,formatter);
  2943. LocalDateTime min = null,max = null;
  2944. if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMin())){
  2945. min = LocalDateTime.parse(ptlAgreementProductCostsAttrLink.getMin(),formatter);
  2946. }
  2947. if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMax())){
  2948. max = LocalDateTime.parse(ptlAgreementProductCostsAttrLink.getMax(),formatter);
  2949. }
  2950. //统一处理数值
  2951. if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2952. if (v.isAfter(min) && v.isBefore(max)) {
  2953. return true;
  2954. }
  2955. } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2956. if (v.isBefore(min)) {
  2957. return true;
  2958. }
  2959. } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2960. if (v.isBefore(min) || v.isEqual(min)) {
  2961. return true;
  2962. }
  2963. } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2964. if (v.isAfter(max)) {
  2965. return true;
  2966. }
  2967. } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2968. if (v.isAfter(max) || v.isEqual(max)) {
  2969. return true;
  2970. }
  2971. }
  2972. return false;
  2973. }
  2974. public boolean dateEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value){
  2975. // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  2976. if(Objects.isNull(value) || value.equals("")){
  2977. return false;
  2978. }
  2979. LocalDateTime v = LocalDate.parse(value).atStartOfDay();
  2980. LocalDateTime min = null,max = null;
  2981. if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMin())){
  2982. min = LocalDate.parse(ptlAgreementProductCostsAttrLink.getMin()).atStartOfDay();
  2983. }
  2984. if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMax())){
  2985. max = LocalDate.parse(ptlAgreementProductCostsAttrLink.getMax()).atStartOfDay();
  2986. }
  2987. //统一处理数值
  2988. if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2989. if (v.isAfter(min) && v.isBefore(max)) {
  2990. return true;
  2991. }
  2992. } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2993. if (v.isBefore(min)) {
  2994. return true;
  2995. }
  2996. } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2997. if (v.isBefore(min) || v.isEqual(min)) {
  2998. return true;
  2999. }
  3000. } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  3001. if (v.isAfter(max)) {
  3002. return true;
  3003. }
  3004. } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  3005. if (v.isAfter(max) || v.isEqual(max)) {
  3006. return true;
  3007. }
  3008. }
  3009. return false;
  3010. }
  3011. public boolean dateTimeEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value, InsOrders insOrders){
  3012. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  3013. //判断险种 的起保时间
  3014. if(ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("SyStartTime") || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("JqStartTime"))
  3015. {
  3016. if(insOrders.getProductid().equals(ProductsType.PT_0330.getCode()) && ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("SyStartTime")){
  3017. return true;
  3018. }
  3019. if(insOrders.getProductid().equals(ProductsType.PT_034001.getCode()) && ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("JqStartTime")){
  3020. return true;
  3021. }
  3022. }
  3023. if(!Objects.isNull(value) && !value.isEmpty()) {
  3024. LocalDateTime v = LocalDateTime.parse(value, formatter);
  3025. LocalDateTime min = null, max = null;
  3026. if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMin())) {
  3027. min = LocalDateTime.parse(ptlAgreementUndwrtRulesAttrLink.getMin(), formatter);
  3028. }
  3029. if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMax())) {
  3030. max = LocalDateTime.parse(ptlAgreementUndwrtRulesAttrLink.getMax(), formatter);
  3031. }
  3032. //统一处理数值
  3033. if ("1".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3034. if (!v.isAfter(min) && v.isBefore(max)) {
  3035. return true;
  3036. }
  3037. } else if ("2".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3038. if (!v.isBefore(min)) {
  3039. return true;
  3040. }
  3041. } else if ("3".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3042. if (!v.isBefore(min)) {
  3043. return true;
  3044. }
  3045. } else if ("4".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3046. if (!v.isAfter(max)) {
  3047. return true;
  3048. }
  3049. } else if ("5".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3050. if (!v.isAfter(max)) {
  3051. return true;
  3052. }
  3053. }
  3054. }
  3055. return false;
  3056. }
  3057. public boolean dateEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value){
  3058. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  3059. if(!Objects.isNull(value) && !value.isEmpty()) {
  3060. LocalDateTime v = LocalDate.parse(value).atStartOfDay();
  3061. LocalDateTime min = null, max = null;
  3062. if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMin())) {
  3063. min = LocalDate.parse(ptlAgreementUndwrtRulesAttrLink.getMin()).atStartOfDay();
  3064. }
  3065. if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMax())) {
  3066. max = LocalDate.parse(ptlAgreementUndwrtRulesAttrLink.getMax()).atStartOfDay();
  3067. }
  3068. //统一处理数值
  3069. if ("1".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3070. if (!v.isAfter(min) && v.isBefore(max)) {
  3071. return true;
  3072. }
  3073. } else if ("2".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3074. if (!v.isBefore(min)) {
  3075. return true;
  3076. }
  3077. } else if ("3".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3078. if (!v.isBefore(min)) {
  3079. return true;
  3080. }
  3081. } else if ("4".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3082. if (!v.isAfter(max)) {
  3083. return true;
  3084. }
  3085. } else if ("5".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3086. if (!v.isAfter(max)) {
  3087. return true;
  3088. }
  3089. }
  3090. }
  3091. return false;
  3092. }
  3093. /**
  3094. * 获取车辆新旧车信息
  3095. *
  3096. * @param companyId
  3097. * @return
  3098. */
  3099. private PtlNewCarJudgeRules getCarJudgeRule(String companyId, String vehicleType) {
  3100. //获取车辆新旧车信息
  3101. List<PtlNewCarJudgeRules> list =
  3102. ptlNewCarJudgeRulesService.list(new LambdaQueryWrapper<PtlNewCarJudgeRules>()
  3103. .eq(PtlNewCarJudgeRules::getCompanyId,companyId)
  3104. .eq(PtlNewCarJudgeRules::getVehicleType,vehicleType));
  3105. if (list.size() > 0) {
  3106. return list.get(0);
  3107. }
  3108. return null;
  3109. }
  3110. }