FeeRuleSchemeServiceNewImpl.java 193 KB

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