FeeRuleSchemeServiceNewImpl.java 174 KB

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