InsPlyIncomeServiceImpl.java 181 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177
  1. package com.ydtech.modules.fnc.service.impl;
  2. import cn.afterturn.easypoi.excel.entity.ExportParams;
  3. import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  9. import com.github.pagehelper.PageHelper;
  10. import com.github.pagehelper.PageInfo;
  11. import com.ydtech.constants.InsuranceEnum;
  12. import com.ydtech.constants.enums.dict.agreement.ProductsType;
  13. import com.ydtech.core.page.HttpResult;
  14. import com.ydtech.exception.SystemException;
  15. import com.ydtech.modules.base.controller.BaseController;
  16. import com.ydtech.modules.esm.model.EsmInsCompany;
  17. import com.ydtech.modules.esm.service.EsmInsCompanyService;
  18. import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
  19. import com.ydtech.modules.fnc.dto.PlatformSettlementRecordDto;
  20. import com.ydtech.modules.fnc.entity.*;
  21. import com.ydtech.modules.fnc.service.*;
  22. import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
  23. import com.ydtech.modules.fnc.vo.SettlementDocumentaryFeesVo;
  24. import com.ydtech.modules.ins.model.vo.res.*;
  25. import com.ydtech.modules.inv.model.dto.*;
  26. import com.ydtech.modules.inv.utils.EasyExcelUtils;
  27. import com.ydtech.modules.order.entity.BasePageResult;
  28. import com.ydtech.modules.order.entity.InsOrders;
  29. import com.ydtech.modules.order.entity.api.dajia.response.NVHLODR1001Response;
  30. import com.ydtech.modules.order.entity.api.zhongmei.response.SubmitResponse;
  31. import com.ydtech.modules.order.entity.crawler.response.CrawlerVerifyPaymentResponse;
  32. import com.ydtech.modules.order.entity.dto.DrivingInsuranceDto;
  33. import com.ydtech.modules.order.service.InsAreaCompanyService;
  34. import com.ydtech.modules.order.service.InsOrdersService;
  35. import com.ydtech.modules.protocol.entity.constants.PtlApiType;
  36. import com.ydtech.modules.protocol.entity.po.PtlAgreement;
  37. import com.ydtech.modules.protocol.entity.vo.PtlAgreementQueryVo;
  38. import com.ydtech.modules.protocol.service.PtlAgreementService;
  39. import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
  40. import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
  41. import com.ydtech.utils.BigDecimalUtils;
  42. import com.ydtech.utils.SnowFlakeUtil;
  43. import com.ydtech.utils.StringOperations;
  44. import com.ydtech.utils.excel.ExcelEasypoiUtils;
  45. import com.ydtech.utils.excel.ExcelStyleUtil;
  46. import lombok.extern.slf4j.Slf4j;
  47. import org.apache.commons.lang3.ObjectUtils;
  48. import org.apache.commons.lang3.StringUtils;
  49. import org.apache.ibatis.annotations.Param;
  50. import org.springframework.beans.BeanUtils;
  51. import org.springframework.beans.factory.annotation.Autowired;
  52. import org.springframework.beans.factory.annotation.Value;
  53. import org.springframework.context.annotation.Lazy;
  54. import org.springframework.stereotype.Service;
  55. import org.springframework.transaction.annotation.Transactional;
  56. import org.springframework.util.CollectionUtils;
  57. import org.springframework.web.multipart.MultipartFile;
  58. import javax.servlet.http.HttpServletRequest;
  59. import javax.servlet.http.HttpServletResponse;
  60. import java.io.IOException;
  61. import java.math.BigDecimal;
  62. import java.math.RoundingMode;
  63. import java.nio.file.Files;
  64. import java.nio.file.Path;
  65. import java.nio.file.Paths;
  66. import java.text.SimpleDateFormat;
  67. import java.time.LocalDate;
  68. import java.time.LocalDateTime;
  69. import java.time.LocalTime;
  70. import java.time.YearMonth;
  71. import java.time.format.DateTimeFormatter;
  72. import java.util.*;
  73. /**
  74. * <p>
  75. * 保司结算手续费 服务实现类
  76. * </p>
  77. *
  78. * @author gws
  79. * @since 2024-01-05
  80. */
  81. @Slf4j
  82. @Service
  83. public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, InsPlyIncome> implements InsPlyIncomeService {
  84. @Autowired
  85. @Lazy
  86. private InsOrdersService insOrdersService;
  87. @Autowired
  88. private InsAreaCompanyService insAreaCompanyService;
  89. @Autowired
  90. private InsFeeOrderNewService insFeeOrderNewService;
  91. @Autowired
  92. private SettlementDocumentaryFeesService settlementDocumentaryFeesService;
  93. @Autowired
  94. private SettlementDocumentaryLogService settlementDocumentaryLogService;
  95. @Autowired
  96. private PtlAgreementService ptlAgreementService;
  97. @Autowired
  98. private EsmInsCompanyService EsmInsCompanyService;
  99. @Autowired
  100. private ImportAsyncService importAsyncService;
  101. @Autowired
  102. private IncomeTaskRelationshipService incomeTaskRelationshipService;
  103. @Autowired
  104. private SettlementDocumentaryFeesSumService settlementDocumentaryFeesSumService;
  105. @Autowired
  106. private InsPlyIncomeLogService insPlyIncomeLogService;
  107. @Value("${upload.file.path}")
  108. private String uploadPath;
  109. @Value("${upload.file.url}")
  110. private String uploadUrl;
  111. public HttpResult<BasePageResult<InsPlyIncome>> queryplyIncome(InsPlyIncomeVo insPlyIncomeVo) {
  112. try {
  113. Page<InsOrders> page = new Page<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  114. PageInfo<List<InsPlyIncome>> pageHelper = null;
  115. PageHelper.startPage(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  116. List<InsPlyIncome> list = this.baseMapper.selectByCondition(insPlyIncomeVo);
  117. pageHelper = new PageInfo(list);
  118. BasePageResult<InsPlyIncome> pageResult = new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(),
  119. insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  120. return HttpResult.ok(pageResult);
  121. } catch (Exception e) {
  122. e.printStackTrace();
  123. return HttpResult.error("查询异常");
  124. }
  125. }
  126. @Override
  127. public void saveBalanceNew(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  128. if (ObjectUtils.isEmpty(order) || ObjectUtils.isEmpty(insFeeOrderNew) || ObjectUtils.isEmpty(insAreaCompany)) {
  129. return;
  130. }
  131. String agreeType = this.judgeAgreeType(insAreaCompany.getAgreementId());
  132. if (StringUtils.isNotEmpty(agreeType)) {
  133. // 判断协议类型 平台 保险
  134. if ("1".equals(agreeType)) {
  135. this.savePinTai(order, insFeeOrderNew, insAreaCompany); //手续费不分非车不非车 跟单也不分
  136. } else { // 保险 逻辑: 手续费生成一条 跟单费生成一条 非车手续费一条 非车跟单费一条
  137. if (((insFeeOrderNew.getJqSuperviseCostsPremiums() != null && insFeeOrderNew.getJqSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0)) || (insFeeOrderNew.getSySuperviseCostsPremiums() != null && insFeeOrderNew.getSySuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0)) { //手续费
  138. this.saveInsuranceProcedures(order, insFeeOrderNew, insAreaCompany);
  139. }
  140. if (insFeeOrderNew.getJqOtherCostsPremiums() != null && insFeeOrderNew.getJqOtherCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { //跟单费
  141. this.saveOtherAmount(order, insFeeOrderNew, insAreaCompany);
  142. }
  143. if (insFeeOrderNew.getNoSuperviseCostsPremiums() != null && insFeeOrderNew.getNoSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { // 非车手续费
  144. this.saveNoSupervise(order, insFeeOrderNew, insAreaCompany);
  145. }
  146. if (insFeeOrderNew.getNoOtherCostsPremiums() != null && insFeeOrderNew.getNoOtherCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { // 非车跟单费
  147. this.saveNoOtherAmount(order, insFeeOrderNew, insAreaCompany);
  148. }
  149. }
  150. }
  151. }
  152. private void saveNoOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  153. InsPlyIncome insPlyIncome = new InsPlyIncome();
  154. insPlyIncome.setOrderno(insFeeOrderNew.getInsOrderNo()); // 子订单号
  155. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  156. if (StringUtils.isNotEmpty(noPolicyno)) {
  157. insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
  158. }
  159. insPlyIncome.setOtherFeevalue(insFeeOrderNew.getNoOtherCostsPremiums()); //非车跟单费
  160. insPlyIncome.setOtherFeerate(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费用比例
  161. this.saveRiskCode(order.getProductid(), insPlyIncome);
  162. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  163. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  164. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  165. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  166. insPlyIncome.setLicenseno(order.getLicenseno());
  167. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  168. insPlyIncome.setNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  169. insPlyIncome.setCreateTime(LocalDateTime.now());
  170. insPlyIncome.setDocumentaryFeesStatus("0");
  171. insPlyIncome.setInsuredName(order.getInsuredname());
  172. insPlyIncome.setHandlingFeesStatus("0");
  173. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  174. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium());
  175. insPlyIncome.setIsNotCar("1");
  176. insPlyIncome.setIsNotDocumentary("1");
  177. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  178. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  179. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  180. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  181. insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoOtherCostsPremiums());
  182. insPlyIncome.setNoOtherCostsPremium(insFeeOrderNew.getNoOtherCostsPremiums());
  183. insPlyIncome.setNoOtherCostsProportion(insFeeOrderNew.getNoOtherCostsProportion());
  184. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  185. this.getDeptId(insPlyIncome);
  186. baseMapper.insert(insPlyIncome);
  187. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  188. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  189. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  190. insPlyIncomeLog.setId(null);
  191. insPlyIncomeLog.setOperationStatus("1");
  192. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  193. }
  194. private void saveNoSupervise(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  195. InsPlyIncome insPlyIncome = new InsPlyIncome();
  196. insPlyIncome.setOrderno(insFeeOrderNew.getInsOrderNo()); // 子订单号
  197. insPlyIncome.setCommissionFeevalue(insFeeOrderNew.getNoSuperviseCostsPremiums());// 非车手续费
  198. insPlyIncome.setCommissionFeerate(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费比例
  199. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  200. if (StringUtils.isNotEmpty(noPolicyno)) {
  201. insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
  202. }
  203. // insPlyIncome.setDeptId(insFeeOrderNew.getDeptId());
  204. this.saveRiskCode(order.getProductid(), insPlyIncome);
  205. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  206. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  207. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  208. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  209. insPlyIncome.setLicenseno(order.getLicenseno());
  210. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  211. insPlyIncome.setCreateTime(LocalDateTime.now());
  212. insPlyIncome.setDocumentaryFeesStatus("0");
  213. insPlyIncome.setHandlingFeesStatus("0");
  214. insPlyIncome.setIsNotCar("1");
  215. insPlyIncome.setIsNotDocumentary("0");
  216. insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoSuperviseCostsPremiums());
  217. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  218. insPlyIncome.setInsuredName(order.getInsuredname());
  219. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium()); //非车保费
  220. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium()); //非车不含税保费
  221. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  222. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  223. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  224. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  225. insPlyIncome.setNoSuperviseCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums());
  226. insPlyIncome.setNoSuperviseCostsProportion(insFeeOrderNew.getNoSuperviseCostsProportion());
  227. this.getDeptId(insPlyIncome);
  228. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  229. baseMapper.insert(insPlyIncome);
  230. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  231. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  232. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  233. insPlyIncomeLog.setId(null);
  234. insPlyIncomeLog.setOperationStatus("1");
  235. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  236. }
  237. private void saveRiskCode(String productid, InsPlyIncome insPlyIncome) {
  238. if (ProductsType.PT_0330.getCode().equals(productid)) {
  239. insPlyIncome.setRiskcode(ProductsType.PT_0330.getDesc());
  240. }
  241. if (ProductsType.PT_034001.getCode().equals(productid)) {
  242. insPlyIncome.setRiskcode(ProductsType.PT_034001.getDesc());
  243. }
  244. if (ProductsType.PT_034002.getCode().equals(productid)) {
  245. insPlyIncome.setRiskcode(ProductsType.PT_034002.getDesc());
  246. }
  247. if (ProductsType.PT_0330034002.getCode().equals(productid)) {
  248. insPlyIncome.setRiskcode(ProductsType.PT_0330034002.getDesc());
  249. }
  250. if (ProductsType.PT_0330034001.getCode().equals(productid)) {
  251. insPlyIncome.setRiskcode(ProductsType.PT_0330034001.getDesc());
  252. }
  253. }
  254. private void saveOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  255. BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),
  256. null);
  257. BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(),
  258. insFeeOrderNew.getJqOtherCostsProportion(), null);
  259. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null);
  260. //交强不含税保费
  261. BigDecimal allPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);// 总保费
  262. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(), insAreaCompany.getJqpolicyno(),
  263. insAreaCompany.getSypolicyno(), null, null, null, null, order.getProductid(), insAreaCompany.getPayDate(),
  264. insAreaCompany.getSigningTime(), insAreaCompany.getCompanyId(), null, insFeeOrderNew.getAgreementId(), order.getLicenseno(),
  265. insAreaCompany.getTaxamount(),
  266. allNoTaxPremium, null, otherProportion, null, otherAmount, otherAmount, null, null, LocalDateTime.now(), null, null, null, "0"
  267. , "0", "0", "1");
  268. this.saveRiskCode(order.getProductid(), insPlyIncome);
  269. insPlyIncome.setTaxPremium(allPremium);
  270. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  271. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  272. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  273. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  274. insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
  275. insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
  276. insPlyIncome.setSyOtherCostsPremium(insFeeOrderNew.getSyOtherCostsPremiums());
  277. insPlyIncome.setJqOtherCostsPremium(insFeeOrderNew.getJqOtherCostsPremiums());
  278. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  279. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  280. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  281. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  282. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  283. insPlyIncome.setInsuredName(order.getInsuredname());
  284. this.getDeptId(insPlyIncome);
  285. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  286. baseMapper.insert(insPlyIncome);
  287. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  288. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  289. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  290. insPlyIncomeLog.setId(null);
  291. insPlyIncomeLog.setOperationStatus("1");
  292. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  293. }
  294. private void saveInsuranceProcedures(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  295. // 保险手续费
  296. BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(),
  297. insFeeOrderNew.getSySuperviseCostsPremiums(), null);
  298. BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(),
  299. insFeeOrderNew.getSySuperviseCostsProportion(), null);
  300. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null);
  301. //不含税保费
  302. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(), insAreaCompany.getJqpolicyno(),
  303. insAreaCompany.getSypolicyno(), null, null, null, null, order.getProductid(), insAreaCompany.getPayDate(),
  304. insAreaCompany.getSigningTime(), insAreaCompany.getCompanyId(), null, insFeeOrderNew.getAgreementId(), order.getLicenseno(),
  305. insAreaCompany.getTaxamount()
  306. , allNoTaxPremium, handlingProportion, null, handlingAmount, null, handlingAmount, null, null, LocalDateTime.now(), null,
  307. null, null, "0", "0", "0", "0");
  308. BigDecimal allTaxPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);
  309. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  310. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  311. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  312. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  313. insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion());
  314. insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums());
  315. insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion());
  316. insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums());
  317. this.saveRiskCode(order.getProductid(), insPlyIncome);
  318. insPlyIncome.setTaxPremium(allTaxPremium);
  319. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  320. insPlyIncome.setInsuredName(order.getInsuredname());
  321. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  322. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  323. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  324. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  325. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  326. this.getDeptId(insPlyIncome);
  327. baseMapper.insert(insPlyIncome);
  328. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  329. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  330. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  331. insPlyIncomeLog.setId(null);
  332. insPlyIncomeLog.setOperationStatus("1");
  333. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  334. }
  335. private String setNoPolicyno(com.ydtech.modules.fnc.entity.InsAreaCompany insAreaCompany) {
  336. if (insAreaCompany.getJypremium() == null || insAreaCompany.getJypremium().compareTo(BigDecimal.ZERO) == 0) { // 非车跟单费
  337. return null;
  338. }
  339. String crossInsurance = insAreaCompany.getCrossInsurance();
  340. if (StringUtils.isEmpty(crossInsurance)) {
  341. return null;
  342. }
  343. JSONArray objects = JSON.parseArray(crossInsurance);
  344. if (objects.isEmpty()) {
  345. return null;
  346. }
  347. if (ObjectUtils.isEmpty(insAreaCompany.getApiType()) || PtlApiType.PTL_API_2.getCode() == insAreaCompany.getApiType()) {
  348. List<CrawlerVerifyPaymentResponse.DrivingInsurancesDTO> drivingInsurancesDTOS = objects.toJavaList(CrawlerVerifyPaymentResponse.DrivingInsurancesDTO.class);
  349. return drivingInsurancesDTOS.get(0).getApplication();
  350. }
  351. // 永诚
  352. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.AICS.getCode())){
  353. List<DrivingInsuranceDto> javaList = objects.toJavaList(DrivingInsuranceDto.class);
  354. return javaList.get(0).getPolicyNumber();
  355. }
  356. // 大家
  357. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.DJPC.getCode())){
  358. List<NVHLODR1001Response.policyInfosDTO> javaList = objects.toJavaList(NVHLODR1001Response.policyInfosDTO.class);
  359. return javaList.get(0).getPlyNo();
  360. }
  361. // 国任
  362. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.XDCX.getCode())){
  363. List<DrivingInsuranceDto> javaList = objects.toJavaList(DrivingInsuranceDto.class);
  364. return javaList.get(0).getPolicyNumber();
  365. }
  366. // 中煤
  367. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.ZMBX.getCode())){
  368. List<SubmitResponse.AccidentNo> javaList = objects.toJavaList(SubmitResponse.AccidentNo.class);
  369. return javaList.get(0).getRideProposalNo();
  370. }
  371. // 紫金
  372. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.ZKIC.getCode())){
  373. List<DrivingInsuranceDto> javaList = objects.toJavaList(DrivingInsuranceDto.class);
  374. return javaList.get(0).getPolicyNumber();
  375. }
  376. return null;
  377. }
  378. private void savePinTai(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  379. BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(),
  380. insFeeOrderNew.getSySuperviseCostsPremiums(), insFeeOrderNew.getNoSuperviseCostsPremiums()); //手续费
  381. BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(),
  382. insFeeOrderNew.getSySuperviseCostsProportion(), insFeeOrderNew.getNoSuperviseCostsProportion());//手续费比例
  383. BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),
  384. insFeeOrderNew.getNoOtherCostsPremiums());//跟单费
  385. BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(),
  386. insFeeOrderNew.getJqOtherCostsProportion(), insFeeOrderNew.getNoOtherCostsProportion()); //跟单费比例
  387. // 不含税保费
  388. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(),
  389. insFeeOrderNew.getNoNoTaxPremium());
  390. BigDecimal allAmount = this.calculateTotal(otherAmount, handlingAmount, null);
  391. BigDecimal jqReceivableProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(),
  392. insFeeOrderNew.getJqOtherCostsProportion(), null);// 交强应收 比例
  393. BigDecimal syReceivableProportion = this.calculateTotal(insFeeOrderNew.getSySuperviseCostsProportion(),
  394. insFeeOrderNew.getSyOtherCostsProportion(), null);//商业应收比例
  395. BigDecimal noReceivableProportion = this.calculateTotal(insFeeOrderNew.getNoSuperviseCostsProportion(),
  396. insFeeOrderNew.getNoOtherCostsProportion(), null);
  397. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  398. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(), insAreaCompany.getJqpolicyno(),
  399. insAreaCompany.getSypolicyno(),
  400. noPolicyno, null, null, null, order.getProductid(), insAreaCompany.getPayDate(), insAreaCompany.getSigningTime(),
  401. insAreaCompany.getCompanyId(),
  402. null, insFeeOrderNew.getAgreementId(), order.getLicenseno(), insAreaCompany.getTaxamount(), allNoTaxPremium,
  403. handlingProportion,
  404. otherProportion, handlingAmount, otherAmount, allAmount, null, null, LocalDateTime.now(), null, null, null, "0", "0", "0", "0");
  405. insPlyIncome.setJqReceivableProportion(jqReceivableProportion);
  406. insPlyIncome.setSyReceivableProportion(syReceivableProportion);
  407. insPlyIncome.setNoReceivableProportion(noReceivableProportion);
  408. // 应收金额 = 商业手续费+商业跟单 + 交强手续费 +交强跟单费 + 非车手续费 + 非车跟单费 = allAmount
  409. insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums()); // 交强手续费
  410. insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums()); // 商业手续费
  411. insPlyIncome.setNoSuperviseCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums()); // 非车手续费
  412. insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion()); //交强手续费 比例
  413. insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion()); // 商业手续费 比例
  414. insPlyIncome.setNoSuperviseCostsProportion(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费 比例
  415. insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
  416. insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
  417. insPlyIncome.setNoOtherCostsProportion(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费比例
  418. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  419. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  420. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium());
  421. insPlyIncome.setReceivableAmount(allAmount);
  422. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  423. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  424. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  425. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  426. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  427. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  428. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  429. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  430. this.getDeptId(insPlyIncome);
  431. this.saveRiskCode(order.getProductid(), insPlyIncome);
  432. insPlyIncome.setInsuredName(order.getInsuredname());
  433. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  434. baseMapper.insert(insPlyIncome);
  435. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  436. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  437. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  438. insPlyIncomeLog.setId(null);
  439. insPlyIncomeLog.setOperationStatus("1");
  440. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  441. }
  442. private void getDeptId(InsPlyIncome insPlyIncome) {
  443. PtlAgreement ptlAgreement = ptlAgreementService.getById(insPlyIncome.getAgreementId());
  444. String deptId = ptlAgreement.getDeptId();
  445. insPlyIncome.setDeptId(deptId);
  446. }
  447. private void saveByCompanyId(InsFeeOrderNew insFeeOrderNew, String companyId, InsPlyIncome insPlyIncome) {
  448. PtlAgreement ptlAgreementQueryVo = this.ptlAgreementService.getByAgreementIdNew(insFeeOrderNew.getAgreementId());
  449. if (ObjectUtils.isNotEmpty(ptlAgreementQueryVo)) {
  450. if (StringUtils.isNotEmpty(ptlAgreementQueryVo.getPartnerCompaniesId())) {
  451. // 合作公司id
  452. String partnerCompaniesId = ptlAgreementQueryVo.getPartnerCompaniesId();
  453. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  454. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  455. String name = esmInsCompany.getNamesimple(); //合作名称
  456. insPlyIncome.setPartnerCompaniesName(name);
  457. insPlyIncome.setPartnerCompaniesId(ptlAgreementQueryVo.getPartnerCompaniesId());
  458. }
  459. if (StringUtils.isNotEmpty(ptlAgreementQueryVo.getInsuranceCompanyId())) {
  460. String insuranceCompanyId = ptlAgreementQueryVo.getInsuranceCompanyId();
  461. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(insuranceCompanyId);
  462. String name = esmInsCompany.getNamesimple(); //保险公司名称 简称
  463. insPlyIncome.setCompanyName(name);
  464. }
  465. }
  466. }
  467. private BigDecimal calculateTotal(BigDecimal value1, BigDecimal value2, BigDecimal value3) {
  468. BigDecimal total = BigDecimal.ZERO;
  469. if (value1 != null) {
  470. total = total.add(value1);
  471. }
  472. if (value2 != null) {
  473. total = total.add(value2);
  474. }
  475. if (value3 != null) {
  476. total = total.add(value3);
  477. }
  478. return total;
  479. }
  480. private String judgeAgreeType(Long agreementId) {
  481. if (agreementId == null) {
  482. return null;
  483. }
  484. HttpResult<PtlAgreementQueryVo> byAgreementId = ptlAgreementService.getByAgreementId(agreementId.toString());
  485. if (byAgreementId != null && ObjectUtils.isNotEmpty(byAgreementId.getData())) {
  486. PtlAgreement agreement = byAgreementId.getData().getAgreement();
  487. String agreementType = agreement.getAgreementType();
  488. if (StringUtils.isNotEmpty(agreementType)) {
  489. return agreementType;
  490. }
  491. }
  492. return null;
  493. }
  494. public HttpResult<BasePageResult<InsPlyIncome>> queryNew(InsPlyIncomeVo insPlyIncomeVo) {
  495. try {
  496. HashMap<String, Object> params = new HashMap<>();
  497. PageInfo<List<InsPlyIncome>> pageHelper = null;
  498. PageHelper.startPage(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  499. params.put("pageNum", insPlyIncomeVo.getPageNum());
  500. params.put("pageSize", insPlyIncomeVo.getPageSize());
  501. params = this.saveParams(insPlyIncomeVo, params);
  502. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIds())) {
  503. params.put("ids", insPlyIncomeVo.getIds().split(","));
  504. }
  505. if (StringUtils.isNotEmpty(insPlyIncomeVo.getId())) {
  506. SettlementDocumentaryFeesEntity settlementDocumentaryFeesEntity =
  507. settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
  508. // 通过任务id查询 明细
  509. String taskId = settlementDocumentaryFeesEntity.getTaskId();
  510. List<String> incomeIds = incomeTaskRelationshipService.getByTaskId(taskId);
  511. if (!CollectionUtils.isEmpty(incomeIds)) {
  512. params.put("incomeIds", incomeIds);
  513. params.remove("handlingFeesStatus");
  514. params.remove("id");
  515. }
  516. }
  517. List<InsPlyIncome> list = this.baseMapper.queryNew(params);
  518. pageHelper = new PageInfo(list);
  519. BasePageResult<InsPlyIncome> pageResult = new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(),
  520. insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  521. return HttpResult.ok(pageResult);
  522. } catch (Exception e) {
  523. e.printStackTrace();
  524. return HttpResult.error("查询异常");
  525. }
  526. }
  527. @Override
  528. public HashMap<String, Object> totalAmount(List<String> selectIds) {
  529. HashMap<String, Object> params = new HashMap<>();
  530. params.put("selectIds", selectIds);
  531. HashMap<String, Object> resultMap = baseMapper.totalAmount(params);
  532. return resultMap;
  533. }
  534. @Override
  535. @Transactional
  536. public HttpResult<Object> batchPinBalance(InsPlyIncomeVo insPlyIncomeVo) {
  537. LocalDateTime now = LocalDateTime.now();
  538. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())) {
  539. List<String> selectIds = insPlyIncomeVo.getSelectIds();
  540. for (String id : selectIds) {
  541. InsPlyIncome insPlyIncome = new InsPlyIncome();
  542. insPlyIncome.setHandlingFeesStatus("1");
  543. insPlyIncome.setSettlementTime(now);
  544. insPlyIncome.setSettlementUserId(BaseController.getUser().getId());
  545. insPlyIncome.setId(id);
  546. baseMapper.updateById(insPlyIncome);
  547. }
  548. }
  549. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  550. settlementDocumentaryLogEntity.setIds(insPlyIncomeVo.getIds());
  551. // settlementDocumentaryLogEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  552. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); //跟单费金额
  553. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); //手续费金额
  554. settlementDocumentaryLogEntity.setCreateTime(new Date());
  555. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  556. return HttpResult.ok();
  557. }
  558. @Override
  559. public List<InsPlyIncome> totalPinAmount(InsPlyIncomeVo insPlyIncomeVo) {
  560. HashMap<String, Object> params = new HashMap<>();
  561. params = this.saveParams(insPlyIncomeVo, params);
  562. List<InsPlyIncome> result = baseMapper.totalPinAmount(params);
  563. return result;
  564. }
  565. private HashMap<String, Object> saveParams(InsPlyIncomeVo insPlyIncomeVo, HashMap<String, Object> params) {
  566. if (ObjectUtils.isNotEmpty(insPlyIncomeVo.getId())) {
  567. params.put("id", insPlyIncomeVo.getId());
  568. }
  569. if (ObjectUtils.isNotEmpty(insPlyIncomeVo.getStartDate())) {
  570. params.put("startDate", insPlyIncomeVo.getStartDate().toString());
  571. }
  572. if (ObjectUtils.isNotEmpty(insPlyIncomeVo.getEndDate())) {
  573. params.put("endDate", insPlyIncomeVo.getEndDate().toString());
  574. }
  575. if (StringUtils.isNotEmpty(insPlyIncomeVo.getOrderno())) {
  576. params.put("orderno", insPlyIncomeVo.getOrderno());
  577. }
  578. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())) {
  579. params.put("isOther", insPlyIncomeVo.getIsNotDocumentary());
  580. }
  581. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())) {
  582. params.put("isNotCar", insPlyIncomeVo.getIsNotCar());
  583. }
  584. if (StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType())) {
  585. params.put("agreementType", insPlyIncomeVo.getAgreementType());
  586. }
  587. if (StringUtils.isNotEmpty(insPlyIncomeVo.getLicenseno())) {
  588. params.put("licenseno", insPlyIncomeVo.getLicenseno());
  589. }
  590. if (StringUtils.isNotEmpty(insPlyIncomeVo.getUserId())) {
  591. params.put("userId", insPlyIncomeVo.getUserId());
  592. }
  593. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())) {
  594. params.put("companyId", insPlyIncomeVo.getCompanyId());
  595. }
  596. if (StringUtils.isNotEmpty(insPlyIncomeVo.getRiskcode())) {
  597. params.put("riskcode", insPlyIncomeVo.getRiskcode());
  598. }
  599. if (StringUtils.isNotEmpty(insPlyIncomeVo.getPolicyno())) {
  600. params.put("policyno", insPlyIncomeVo.getPolicyno());
  601. }
  602. if (StringUtils.isNotEmpty(insPlyIncomeVo.getSyPolicyno())) {
  603. params.put("syPolicyno", insPlyIncomeVo.getSyPolicyno());
  604. }
  605. if (StringUtils.isNotEmpty(insPlyIncomeVo.getNoPolicyno())) {
  606. params.put("noPolicyno", insPlyIncomeVo.getNoPolicyno());
  607. }
  608. if (insPlyIncomeVo.getCreateTime() != null) {
  609. params.put("createTime", insPlyIncomeVo.getCreateTime().toString());
  610. }
  611. if (insPlyIncomeVo.getSettlementTime() != null) {
  612. params.put("settlementTime", insPlyIncomeVo.getSettlementTime().toString());
  613. }
  614. if (StringUtils.isNotEmpty(insPlyIncomeVo.getHandlingFeesStatus())) {
  615. params.put("handlingFeesStatus", insPlyIncomeVo.getHandlingFeesStatus());
  616. }
  617. if (StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesId())) {
  618. params.put("partnerCompaniesId", insPlyIncomeVo.getPartnerCompaniesId());
  619. }
  620. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  621. params.put("year", insPlyIncomeVo.getYear());
  622. }
  623. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  624. params.put("month", insPlyIncomeVo.getMonth());
  625. }
  626. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDay())) {
  627. params.put("day", insPlyIncomeVo.getDay());
  628. }
  629. if (StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateEnd())) {
  630. params.put("signDateEnd", insPlyIncomeVo.getSignDateEnd());
  631. }
  632. if (StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateStart())) {
  633. params.put("signDateStart", insPlyIncomeVo.getSignDateStart());
  634. }
  635. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyName())) {
  636. params.put("companyName", insPlyIncomeVo.getCompanyName());
  637. }
  638. if (StringUtils.isNotEmpty(insPlyIncomeVo.getInsuredName())) {
  639. params.put("insuredName", insPlyIncomeVo.getInsuredName());
  640. }
  641. if (StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesName())) {
  642. params.put("partnerCompaniesName", insPlyIncomeVo.getPartnerCompaniesName());
  643. }
  644. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDockingPerson())) {
  645. params.put("dockingPerson", insPlyIncomeVo.getDockingPerson());
  646. }
  647. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYeartsStart()) && StringUtils.isNotEmpty(insPlyIncomeVo.getYeartsEnd())) {
  648. params.put("yeartsStart", insPlyIncomeVo.getYeartsStart());
  649. params.put("yeartsEnd", insPlyIncomeVo.getYeartsEnd());
  650. }
  651. if (insPlyIncomeVo.getJqStartDate() != null) {
  652. params.put("jqStartDate", insPlyIncomeVo.getJqStartDate());
  653. }
  654. if (insPlyIncomeVo.getJqStartDate() != null) {
  655. params.put("jqEndDate", insPlyIncomeVo.getJqEndDate());
  656. }
  657. if (insPlyIncomeVo.getSyStartDate() != null) {
  658. params.put("syStartDate", insPlyIncomeVo.getSyStartDate());
  659. }
  660. if (insPlyIncomeVo.getSyEndDate() != null) {
  661. params.put("syEndDate", insPlyIncomeVo.getSyEndDate());
  662. }
  663. if (StringUtils.isNotEmpty(insPlyIncomeVo.getProvinceId())) {
  664. params.put("provinceId", insPlyIncomeVo.getProvinceId());
  665. }
  666. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCityId())) {
  667. params.put("cityId", insPlyIncomeVo.getCityId());
  668. }
  669. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCountyId())) {
  670. params.put("countyId", insPlyIncomeVo.getCountyId());
  671. }
  672. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDeptId())) {
  673. params.put("deptId", insPlyIncomeVo.getDeptId());
  674. }
  675. if (StringUtils.isNotEmpty(insPlyIncomeVo.getAllPartnerCompaniesId())) {
  676. params.put("allPartnerCompaniesId", insPlyIncomeVo.getAllPartnerCompaniesId().substring(0, 5));
  677. }
  678. if (StringUtils.isNotEmpty(insPlyIncomeVo.getProvincePartnerCompaniesId())) {
  679. params.put("provincePartnerCompaniesId", insPlyIncomeVo.getProvincePartnerCompaniesId());
  680. }
  681. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())) {
  682. params.put("selectIds", insPlyIncomeVo.getSelectIds());
  683. }
  684. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getPartnerCompaniesIdList())) {
  685. params.put("partnerCompaniesIdList", insPlyIncomeVo.getPartnerCompaniesIdList());
  686. }
  687. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCreateTimeQuery())){
  688. params.put("createTimeQuery", insPlyIncomeVo.getCreateTimeQuery());
  689. }
  690. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSettlementDate())){
  691. params.put("settlementDate", insPlyIncomeVo.getSettlementDate());
  692. }
  693. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsExternal())){
  694. params.put("isExternal", insPlyIncomeVo.getIsExternal());
  695. }
  696. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCreateTimeEnd())){
  697. params.put("createTimeEnd", insPlyIncomeVo.getCreateTimeEnd());
  698. }
  699. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCreateTimeStart())){
  700. params.put("createTimeStart", insPlyIncomeVo.getCreateTimeStart());
  701. }
  702. return params;
  703. }
  704. @Override
  705. public HttpResult<BasePageResult<InsPlyIncome>> nonSettlementQuery(InsPlyIncomeVo insPlyIncomeVo) {
  706. try {
  707. HashMap<String, Object> params = new HashMap<>();
  708. PageInfo<List<InsPlyIncome>> pageHelper = null;
  709. PageHelper.startPage(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  710. params.put("pageNum", insPlyIncomeVo.getPageNum());
  711. params.put("pageSize", insPlyIncomeVo.getPageSize());
  712. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())) {
  713. params.put("isNotCar", insPlyIncomeVo.getIsNotCar());
  714. }
  715. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())) {
  716. params.put("isOther", insPlyIncomeVo.getIsNotDocumentary());
  717. }
  718. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  719. params.put("year", insPlyIncomeVo.getYear());
  720. }
  721. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  722. params.put("month", insPlyIncomeVo.getMonth());
  723. }
  724. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())) {
  725. params.put("documentaryFeesStatus", insPlyIncomeVo.getDocumentaryFeesStatus());
  726. }
  727. List<InsPlyIncome> list = this.baseMapper.NonSettlementQuery(params);
  728. pageHelper = new PageInfo(list);
  729. BasePageResult<InsPlyIncome> pageResult = new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(),
  730. insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  731. return HttpResult.ok(pageResult);
  732. } catch (Exception e) {
  733. e.printStackTrace();
  734. return HttpResult.error("查询异常");
  735. }
  736. }
  737. @Override
  738. public HttpResult<List<InsPlyIncome>> nonSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  739. try {
  740. String ids = insPlyIncomeVo.getIds();
  741. ArrayList<InsPlyIncome> resultList = new ArrayList<>();
  742. if (ObjectUtils.isNotEmpty(ids)) {
  743. String[] split = ids.split(",");
  744. for (int i = 0; i < split.length; i++) {
  745. String id = split[i];
  746. resultList.add(this.baseMapper.getById(id));
  747. }
  748. }
  749. return HttpResult.ok(resultList);
  750. } catch (Exception e) {
  751. e.printStackTrace();
  752. return HttpResult.error("查询异常");
  753. }
  754. }
  755. /**
  756. * @param multipartFile
  757. * @return totalAmount 总金额
  758. * totalHandingAmount 总手续费金额
  759. * totalOtherAmount 总跟单费金额
  760. * resultHashMap 返回 ids 已经上面的金额
  761. * resultNoSelect 未匹配的车牌号
  762. */
  763. @Override
  764. public HashMap<String, Object> importData(MultipartFile multipartFile) {
  765. BigDecimal totalAmount = BigDecimal.ZERO;
  766. BigDecimal totalHandingAmount = BigDecimal.ZERO;
  767. BigDecimal totalOtherAmount = BigDecimal.ZERO;
  768. HashMap<String, Object> resultHashMap = new HashMap<>();
  769. HashSet<String> partnerCompaniesIdSet = new HashSet<>();
  770. List<String> ids = new ArrayList<>();
  771. LocalDateTime now = LocalDateTime.now();
  772. ArrayList<HashMap<String, Object>> resultNoSelect = new ArrayList<>();
  773. try {
  774. List<InsPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsPlyIncomeExcelDto.class, 0, 1, 1);
  775. for (InsPlyIncomeExcelDto excelItem : dtoList) {
  776. String reason ="";
  777. HashMap<String, Object> objectObjectHashMap = new HashMap<>();
  778. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  779. objectObjectHashMap.put("licenseno", excelItem.getLicenseno());//车牌号
  780. }
  781. if (StringUtils.isNotEmpty(excelItem.getPolicyno())) {
  782. objectObjectHashMap.put("policyno", excelItem.getPolicyno()); //交强保单号
  783. }
  784. if (StringUtils.isNotEmpty(excelItem.getSyPolicyno())) {
  785. objectObjectHashMap.put("syPolicyno", excelItem.getSyPolicyno());//商业保单号
  786. }
  787. if (StringUtils.isNotEmpty(excelItem.getNoPolicyno())) {
  788. objectObjectHashMap.put("noPolicyno", excelItem.getNoPolicyno()); //非车保单号
  789. }
  790. objectObjectHashMap.put("agreementType","1");
  791. InsPlyIncome insPlyIncome = baseMapper.findByLicenseno(objectObjectHashMap);
  792. if (ObjectUtils.isNotEmpty(insPlyIncome)) {
  793. // 如果能查询出来则 修改结算 变成已结算
  794. if(excelItem.getJqReceivableProportion()!=null && excelItem.getJqReceivableProportion().compareTo(BigDecimal.ZERO) !=0 ){
  795. objectObjectHashMap.put("jqReceivableProportion", excelItem.getJqReceivableProportion()); //非车保单号
  796. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(objectObjectHashMap);
  797. if(insPlyIncomes.isEmpty()){
  798. reason="交强应收比例错误!";
  799. }
  800. }
  801. if(excelItem.getSyReceivableProportion()!=null && excelItem.getSyReceivableProportion().compareTo(BigDecimal.ZERO) !=0 ){
  802. objectObjectHashMap.put("syReceivableProportion", excelItem.getSyReceivableProportion()); //非车保单号
  803. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(objectObjectHashMap);
  804. if(insPlyIncomes.isEmpty() && StringUtils.isEmpty(reason)){
  805. reason="商业应收比例错误!";
  806. }
  807. }
  808. if(excelItem.getNoReceivableProportion()!=null && excelItem.getNoReceivableProportion().compareTo(BigDecimal.ZERO) !=0 ){
  809. objectObjectHashMap.put("noReceivableProportion", excelItem.getNoReceivableProportion()); //非车保单号
  810. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(objectObjectHashMap);
  811. if(insPlyIncomes.isEmpty() && StringUtils.isEmpty(reason)){
  812. reason="非车应收比例错误!";
  813. }
  814. }
  815. //判断是否是相同保司机构
  816. partnerCompaniesIdSet.add(insPlyIncome.getPartnerCompaniesId());
  817. if(StringUtils.isNotEmpty(reason)){
  818. objectObjectHashMap.put("reason",reason);
  819. resultNoSelect.add(objectObjectHashMap); // 添加未匹配的车牌号
  820. }else {
  821. ids.add(insPlyIncome.getId());
  822. if (insPlyIncome.getAllFeeValue() != null && insPlyIncome.getAllFeeValue().compareTo(BigDecimal.ZERO) != 0) {
  823. totalAmount = totalAmount.add(insPlyIncome.getAllFeeValue()); //总金额
  824. }
  825. if (insPlyIncome.getCommissionFeevalue() != null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO) != 0) {
  826. totalHandingAmount = totalHandingAmount.add(insPlyIncome.getCommissionFeevalue()); //总手续费
  827. }
  828. if (insPlyIncome.getOtherFeevalue() != null && insPlyIncome.getOtherFeevalue().compareTo(BigDecimal.ZERO) != 0) {
  829. totalOtherAmount = totalOtherAmount.add(insPlyIncome.getOtherFeevalue()); //总跟单费
  830. }
  831. }
  832. } else {
  833. objectObjectHashMap.put("reason","未查询车辆");
  834. resultNoSelect.add(objectObjectHashMap); // 添加未匹配的车牌号
  835. }
  836. }
  837. if(partnerCompaniesIdSet.size()>1){
  838. throw new SystemException("表里有不同保司机构");
  839. }
  840. resultHashMap.put("totalAmount", totalAmount);
  841. resultHashMap.put("totalHandingAmount", totalHandingAmount);
  842. resultHashMap.put("totalOtherAmount", totalOtherAmount);
  843. resultHashMap.put("resultList", resultNoSelect);
  844. resultHashMap.put("settIdList",ids);
  845. return resultHashMap;
  846. } catch (IOException e) {
  847. throw new SystemException("导入失败!");
  848. }
  849. }
  850. /**
  851. * @param multipartFile
  852. * @return resultList 包含总金额 还有 未匹配表中的数据
  853. */
  854. @Override
  855. public HashMap<String, Object> bxImportData(MultipartFile multipartFile, String isNotCar) {
  856. BigDecimal totalAmount = BigDecimal.ZERO;
  857. HashMap<String, Object> params = new HashMap<>();
  858. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  859. HashMap<String, Object> resultMap = new HashMap<>();
  860. StringBuffer strBuilder = new StringBuffer();
  861. boolean open = true;
  862. String ids = "";
  863. try {
  864. List<InsBxPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxPlyIncomeExcelDto.class, 0, 1, 1);
  865. Integer i = 0;
  866. if (!CollectionUtils.isEmpty(dtoList)) {
  867. for (InsBxPlyIncomeExcelDto excelItem : dtoList) {
  868. String reason = "";
  869. i = i + 1;
  870. params.clear();
  871. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  872. String licenseno = excelItem.getLicenseno();//车牌号
  873. params.put("licenseno", licenseno);
  874. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  875. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  876. reason = "该数据车牌号有问题";
  877. }
  878. }
  879. if (StringUtils.isNotEmpty(excelItem.getPolicyno())) {
  880. String policyno = excelItem.getPolicyno(); //交强保单号
  881. params.put("policyno", policyno);
  882. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  883. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  884. reason = "该数据交强保单号有问题";
  885. }
  886. }
  887. if (StringUtils.isNotEmpty(excelItem.getSyPolicyno())) {
  888. String syPolicyno = excelItem.getSyPolicyno(); //商业保单号
  889. params.put("syPolicyno", syPolicyno);
  890. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  891. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  892. reason = "该数据商业保单号有问题";
  893. }
  894. }
  895. if (excelItem.getJqSuperviseCostsProportion() != null && excelItem.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  896. params.put("jqSuperviseCostsProportion", excelItem.getJqSuperviseCostsProportion());
  897. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  898. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  899. reason = "该数据交强手续费比例有问题";
  900. }
  901. }
  902. if (excelItem.getSySuperviseCostsProportion() != null && excelItem.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  903. params.put("sySuperviseCostsProportion", excelItem.getSySuperviseCostsProportion());
  904. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  905. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  906. reason = "该数据商业手续费比例有问题";
  907. }
  908. }
  909. // 只查手续费
  910. params.put("isOther", "0");
  911. params.put("isNotCar", isNotCar);
  912. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  913. if (ObjectUtils.isNotEmpty(insPlyIncome) && open) {
  914. open = false;
  915. resultMap.put("companyId", insPlyIncome.getCompanyId()); // 保险公司id
  916. resultMap.put("partnerCompaniesId", insPlyIncome.getPartnerCompaniesId()); //合作公司id
  917. resultMap.put("agreementId", insPlyIncome.getAgreementId()); //协议id
  918. }
  919. if (ObjectUtils.isNotEmpty(insPlyIncome)) { // 比配上汇总金额 未匹配则返回到数据当中
  920. strBuilder.append(insPlyIncome.getId()).append(",");
  921. if (insPlyIncome.getCommissionFeevalue() != null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO) != 0) {
  922. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  923. }
  924. } else {
  925. HashMap<String, Object> noMatching = new HashMap<>();
  926. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  927. noMatching.put("licenseno", excelItem.getLicenseno());
  928. }
  929. if (StringUtils.isNotEmpty(excelItem.getPolicyno())) {
  930. noMatching.put("policyno", excelItem.getPolicyno());
  931. }
  932. if (StringUtils.isNotEmpty(excelItem.getSyPolicyno())) {
  933. noMatching.put("syPolicyno", excelItem.getSyPolicyno());
  934. }
  935. resultList.add(noMatching);
  936. }
  937. resultMap.put("reason", reason);
  938. }
  939. }
  940. if (strBuilder.length() > 0) {
  941. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  942. }
  943. resultMap.put("ids", ids);
  944. resultMap.put("totalAmount", totalAmount);
  945. resultMap.put("resultList", resultList);
  946. return resultMap;
  947. } catch (IOException e) {
  948. throw new SystemException("导入失败!");
  949. }
  950. }
  951. @Override
  952. public HashMap<String, Object> bxImportNoData(MultipartFile multipartFile, String isNotCar) {
  953. BigDecimal totalAmount = BigDecimal.ZERO;
  954. HashMap<String, Object> params = new HashMap<>();
  955. HashMap<String, Object> resultMap = new HashMap<>();
  956. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  957. StringBuffer strBuilder = new StringBuffer();
  958. String ids = "";
  959. try {
  960. Integer i = 0;
  961. List<InsBxNoPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxNoPlyIncomeExcelDto.class, 0, 1, 1);
  962. if (!CollectionUtils.isEmpty(dtoList)) {
  963. for (InsBxNoPlyIncomeExcelDto excelItem : dtoList) {
  964. String reason = "";
  965. i = i + 1;
  966. params.clear();
  967. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  968. String licenseno = excelItem.getLicenseno();//车牌号
  969. params.put("licenseno", licenseno);
  970. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  971. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  972. reason = "该数据车牌号有问题";
  973. }
  974. }
  975. if (StringUtils.isNotEmpty(excelItem.getNoPolicyno())) {
  976. String policyno = excelItem.getNoPolicyno(); //非车保单号
  977. params.put("NoPolicyno", policyno);
  978. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  979. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  980. reason = "该数据非车保单号有问题";
  981. }
  982. }
  983. if (excelItem.getNoSuperviseCostsProportion() != null && excelItem.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  984. params.put("noSuperviseCostsProportion", excelItem.getNoSuperviseCostsProportion());
  985. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  986. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  987. reason = "该数据非车手续费比例有问题";
  988. }
  989. }
  990. // 只查手续费
  991. params.put("isOther", "0");
  992. params.put("isNotCar", isNotCar);
  993. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  994. if (i == dtoList.size() && ObjectUtils.isNotEmpty(insPlyIncome)) {
  995. resultMap.put("companyId", insPlyIncome.getCompanyId()); // 保险公司id
  996. resultMap.put("partnerCompaniesId", insPlyIncome.getPartnerCompaniesId()); //合作公司id
  997. resultMap.put("agreementId", insPlyIncome.getAgreementId()); //协议id
  998. }
  999. if (ObjectUtils.isNotEmpty(insPlyIncome)) { // 比配上汇总金额 未匹配则返回到数据当中
  1000. strBuilder.append(insPlyIncome.getId()).append(",");
  1001. if (insPlyIncome.getCommissionFeevalue() != null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO) != 0) {
  1002. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  1003. }
  1004. } else {
  1005. HashMap<String, Object> noMatching = new HashMap<>();
  1006. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  1007. noMatching.put("licenseno", excelItem.getLicenseno());
  1008. }
  1009. if (StringUtils.isNotEmpty(excelItem.getNoPolicyno())) {
  1010. noMatching.put("NoPolicyno", excelItem.getNoPolicyno());
  1011. }
  1012. resultList.add(noMatching);
  1013. }
  1014. resultMap.put("reason", reason);
  1015. }
  1016. if (strBuilder.length() > 0) {
  1017. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  1018. }
  1019. resultMap.put("ids", ids);
  1020. resultMap.put("totalAmount", totalAmount);
  1021. resultMap.put("resultList", resultList);
  1022. }
  1023. return resultMap;
  1024. } catch (IOException e) {
  1025. throw new SystemException("导入失败!");
  1026. }
  1027. }
  1028. @Override
  1029. public HttpResult bxOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1030. HashMap<String, Object> params = new HashMap<>();
  1031. params = this.saveParams(insPlyIncomeVo, params);
  1032. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1033. String filePathName = "";
  1034. List<BxOtherDetailsNorExcel> resultNoList = new ArrayList<>();
  1035. List<BxOtherDetailsExcel> resultList = new ArrayList<>();
  1036. //判断是否是非车 1 是非车
  1037. if ("1".equals(insPlyIncomeVo.getIsNotCar())) {
  1038. filePathName = "非车跟单明细导出";
  1039. ExportParams exportParams = new ExportParams("非车跟单明细", null, ExcelType.HSSF);
  1040. exportParams.setStyle(ExcelStyleUtil.class);
  1041. for (InsPlyIncome item : insPlyIncomes) {
  1042. BxOtherDetailsNorExcel bxOtherDetailsNorExcel = new BxOtherDetailsNorExcel();
  1043. LocalDateTime signDate = item.getSignDate();
  1044. BeanUtils.copyProperties(item, bxOtherDetailsNorExcel);
  1045. bxOtherDetailsNorExcel.setSigndate(signDate);
  1046. resultNoList.add(bxOtherDetailsNorExcel);
  1047. }
  1048. } else {
  1049. filePathName = "车险跟单明细导出";
  1050. ExportParams exportParams = new ExportParams("车险跟单明细", null, ExcelType.HSSF);
  1051. exportParams.setStyle(ExcelStyleUtil.class);
  1052. for (InsPlyIncome item : insPlyIncomes) {
  1053. BxOtherDetailsExcel bxOtherDetailsExcel = new BxOtherDetailsExcel();
  1054. LocalDateTime signDate = item.getSignDate();
  1055. BeanUtils.copyProperties(item, bxOtherDetailsExcel);
  1056. bxOtherDetailsExcel.setSigndate(signDate);
  1057. resultList.add(bxOtherDetailsExcel);
  1058. }
  1059. }
  1060. String uploadPath = this.uploadPath + "/excel/";
  1061. Path path = Paths.get(uploadPath);
  1062. if (!Files.exists(path)) {
  1063. try {
  1064. Files.createDirectories(path);
  1065. } catch (IOException e) {
  1066. e.printStackTrace();
  1067. }
  1068. }
  1069. String fileName = "";
  1070. if ("1".equals(insPlyIncomeVo.getIsNotCar())) {
  1071. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxOtherDetailsNorExcel.class, resultNoList);
  1072. } else {
  1073. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxOtherDetailsExcel.class, resultList);
  1074. }
  1075. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  1076. }
  1077. /**
  1078. * @param insPlyIncomeVo 传参字段
  1079. * ids 通过ids中的id进行开票分组
  1080. * @return
  1081. */
  1082. @Override
  1083. public HttpResult<List<SettlementDocumentaryFeesEntity>> invicdetail(InsPlyIncomeVo insPlyIncomeVo) {
  1084. HashMap<String, Object> params = new HashMap<>();
  1085. params = this.saveParams(insPlyIncomeVo, params);
  1086. if (StringUtils.isEmpty(insPlyIncomeVo.getIsSettlement())) {
  1087. params.put("isSettlement", "1");
  1088. }
  1089. if (StringUtils.isNotEmpty(insPlyIncomeVo.getSettlementStatus())) {
  1090. params.put("settlementStatus", insPlyIncomeVo.getSettlementStatus());
  1091. }
  1092. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCompletionStatus())) {
  1093. params.put("completionStatus", insPlyIncomeVo.getCompletionStatus());
  1094. }
  1095. List<SettlementDocumentaryFeesEntity> resultList = settlementDocumentaryFeesService.querySettleNew(params);
  1096. if (resultList.size() > 0) {
  1097. return HttpResult.ok(resultList);
  1098. }
  1099. return HttpResult.ok();
  1100. }
  1101. /***
  1102. *
  1103. * @param insPlyIncomeVo
  1104. * @param request
  1105. * @param response
  1106. * @return 保险非车跟单明细导出
  1107. */
  1108. @Override
  1109. public HttpResult bxNoOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1110. HashMap<String, Object> params = new HashMap<>();
  1111. params = this.saveParams(insPlyIncomeVo, params);
  1112. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1113. ExportParams exportParams = new ExportParams("保险非车跟单明细导出", null, ExcelType.HSSF);
  1114. exportParams.setStyle(ExcelStyleUtil.class);
  1115. List<BxNoOtherDetailsExcel> resultList = new ArrayList<>();
  1116. for (InsPlyIncome item : insPlyIncomes) {
  1117. BxNoOtherDetailsExcel bxNoOtherDetailsExcel = new BxNoOtherDetailsExcel();
  1118. BeanUtils.copyProperties(item, bxNoOtherDetailsExcel);
  1119. resultList.add(bxNoOtherDetailsExcel);
  1120. }
  1121. String uploadPath = this.uploadPath + "/excel/";
  1122. Path path = Paths.get(uploadPath);
  1123. if (!Files.exists(path)) {
  1124. try {
  1125. Files.createDirectories(path);
  1126. } catch (IOException e) {
  1127. e.printStackTrace();
  1128. }
  1129. }
  1130. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险非车跟单明细导出", BxNoOtherDetailsExcel.class, resultList);
  1131. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  1132. }
  1133. /**
  1134. * @param insPlyIncomeVo 开票ids
  1135. * @return 返回开票号 开票金额 开票时间
  1136. */
  1137. @Override
  1138. public HttpResult<List<HashMap<String, Object>>> otherSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  1139. HashMap<String, Object> params = new HashMap<>();
  1140. params = this.saveParams(insPlyIncomeVo, params);
  1141. List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(params);
  1142. if (resultList.size() > 0) {
  1143. return HttpResult.ok(resultList);
  1144. }
  1145. return HttpResult.ok();
  1146. }
  1147. @Override
  1148. public InsPlyIncome getEntityById(String id) {
  1149. return baseMapper.getEntityById(id);
  1150. }
  1151. @Override
  1152. @Transactional
  1153. public void updateByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  1154. // 根据协议 如果是含增值税结算 用保费 * 如果是 不含税保费
  1155. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1156. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1157. InsPlyIncome byId = baseMapper.getById(insPlyIncomeVo.getId());
  1158. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  1159. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  1160. BeanUtils.copyProperties(byId,insPlyIncomeLog);
  1161. insPlyIncomeLog.setId(null);
  1162. insPlyIncomeLog.setOperationStatus("2");
  1163. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  1164. this.amountCalculate(insPlyIncomeVo, insPlyIncome);
  1165. insPlyIncome.setUpdateUserId(BaseController.getUser().getId());
  1166. baseMapper.updateById(insPlyIncome);
  1167. }
  1168. @Override
  1169. public void updateNoHand(InsPlyIncomeVo insPlyIncomeVo) {
  1170. // 根据协议 如果是含增值税结算 用保费 * 如果是 不含税保费
  1171. InsPlyIncome insPlyIncome = baseMapper.getById(insPlyIncomeVo.getId());
  1172. BigDecimal bigDecimal = this.getBigDecimal(insPlyIncome.getNoPremium(), insPlyIncomeVo.getNoSuperviseCostsProportion());
  1173. insPlyIncome.setCommissionFeevalue(bigDecimal);
  1174. insPlyIncome.setCommissionFeerate(insPlyIncomeVo.getNoSuperviseCostsProportion());
  1175. insPlyIncome.setNoSuperviseCostsPremiums(bigDecimal);
  1176. insPlyIncome.setAllFeeValue(bigDecimal);
  1177. insPlyIncome.setUpdateUserId(BaseController.getUser().getId());
  1178. insPlyIncome.setNoSuperviseCostsProportion(insPlyIncomeVo.getNoSuperviseCostsProportion());
  1179. insPlyIncome.setAgreementId(insPlyIncomeVo.getAgreementId());
  1180. baseMapper.updateById(insPlyIncome);
  1181. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  1182. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  1183. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  1184. insPlyIncomeLog.setId(null);
  1185. insPlyIncomeLog.setOperationStatus("2");
  1186. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  1187. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo.getNoSuperviseCostsPremiums());
  1188. insPlyIncomeVo.setCrudStatus("2");
  1189. this.saveLog(insPlyIncomeVo);
  1190. }
  1191. @Override
  1192. public HttpResult<Object> batchPinBalanceNew(InsPlyIncomeVo insPlyIncomeVo) {
  1193. LocalDateTime now = LocalDateTime.now();
  1194. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getSettIdList())){
  1195. for (String id : insPlyIncomeVo.getSettIdList()){
  1196. InsPlyIncome insPlyIncome = baseMapper.getById(id);
  1197. if("1".equals(insPlyIncome.getHandlingFeesStatus())){
  1198. throw new SystemException("有已结算数据");
  1199. }
  1200. insPlyIncome.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1201. insPlyIncome.setSettlementUserId(BaseController.getUser().getId());
  1202. insPlyIncome.setSettlementTime(now);
  1203. insPlyIncome.setId(id);
  1204. insPlyIncome.setHandlingFeesStatus("1");
  1205. baseMapper.updateById(insPlyIncome);
  1206. }
  1207. }
  1208. return HttpResult.ok();
  1209. }
  1210. /**
  1211. * @param insPlyIncomeVo
  1212. * @param insPlyIncome 重新计算金额 通过比例
  1213. * 计算逻辑 交强不含税保费* 交强跟单比例 = 交强跟单金额
  1214. */
  1215. private void amountCalculate(InsPlyIncomeVo insPlyIncomeVo, InsPlyIncome insPlyIncome) {
  1216. if ("1".equals(insPlyIncomeVo.getAgreementType())) { //平台
  1217. // 平台 手续费 +跟单费 = 应收 手续费 = 手续费比例*保费 应收比例=手续费比例 + 跟单比例
  1218. BigDecimal jqSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqSuperviseCostsProportion());//交强手续费比例
  1219. BigDecimal sySuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSySuperviseCostsProportion()); //商业手续费比例
  1220. BigDecimal noSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoSuperviseCostsProportion()); //非车手续费比例
  1221. BigDecimal jqOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqOtherCostsProportion()); //交强跟单比例
  1222. BigDecimal syOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSyOtherCostsProportion()); //商业跟单比例
  1223. BigDecimal noOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoOtherCostsProportion()); //非车跟单比例
  1224. BigDecimal jqPremium = initializationBigdecimal(insPlyIncomeVo.getJqPremium()); //交强保费
  1225. BigDecimal syPremium = initializationBigdecimal(insPlyIncomeVo.getSyPremium()); //商业保费
  1226. BigDecimal noPremium = initializationBigdecimal(insPlyIncomeVo.getNoPremium()); //非车保费
  1227. //手续费比例
  1228. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion, sySuperviseCostsProportion,
  1229. noSuperviseCostsProportion)); //手续费比例 = 商业手续费比例 + 交强手续费比例 + 非车手续费比例
  1230. if (jqSuperviseCostsProportion != null && jqPremium != null) {
  1231. insPlyIncome.setJqSuperviseCostsPremiums(algorithmAmount(jqPremium, jqSuperviseCostsProportion)); //交强手续费
  1232. insPlyIncome.setJqSuperviseCostsProportion(jqSuperviseCostsProportion);
  1233. }
  1234. if (sySuperviseCostsProportion != null && syPremium != null) {
  1235. insPlyIncome.setSySuperviseCostsPremiums(algorithmAmount(syPremium, sySuperviseCostsProportion)); //商业手续费
  1236. insPlyIncome.setSySuperviseCostsProportion(sySuperviseCostsProportion);
  1237. }
  1238. if (noSuperviseCostsProportion != null && noPremium != null) {
  1239. insPlyIncome.setNoSuperviseCostsPremiums(algorithmAmount(noPremium, noSuperviseCostsProportion)); //非车手续费
  1240. insPlyIncome.setNoSuperviseCostsProportion(noSuperviseCostsProportion);
  1241. }
  1242. if (jqOtherCostsProportion != null && jqPremium != null) {
  1243. insPlyIncome.setJqOtherCostsPremium(algorithmAmount(jqPremium, jqOtherCostsProportion)); //交强跟单费
  1244. insPlyIncome.setJqOtherCostsProportion(jqOtherCostsProportion);
  1245. }
  1246. if (syOtherCostsProportion != null && syPremium != null) {
  1247. insPlyIncome.setSyOtherCostsPremium(algorithmAmount(syPremium, syOtherCostsProportion)); //商业跟单费
  1248. insPlyIncome.setSyOtherCostsProportion(syOtherCostsProportion);
  1249. }
  1250. if (noOtherCostsProportion != null && noPremium != null) {
  1251. insPlyIncome.setNoOtherCostsPremium(algorithmAmount(noPremium, noOtherCostsProportion)); //非车跟单费
  1252. insPlyIncome.setNoOtherCostsProportion(noOtherCostsProportion);
  1253. }
  1254. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(), insPlyIncome.getSySuperviseCostsPremiums(), insPlyIncome.getNoSuperviseCostsPremiums())); //手续费
  1255. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion, sySuperviseCostsProportion,
  1256. noSuperviseCostsProportion)); //手续费比例
  1257. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(), insPlyIncome.getSyOtherCostsPremium(), insPlyIncome.getNoOtherCostsPremium())); //跟单费金额
  1258. insPlyIncome.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion, syOtherCostsProportion, noOtherCostsProportion));
  1259. //跟单费比例
  1260. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(), insPlyIncome.getOtherFeevalue(), null)); // 总费用 = 手续费+跟单费
  1261. insPlyIncome.setReceivableAmount(this.calculateTotal(insPlyIncome.getCommissionFeevalue(), insPlyIncome.getOtherFeevalue(), null));
  1262. //应收比例 交强应收比例=交强手续费比例+交强非跟单比例
  1263. insPlyIncome.setJqReceivableProportion(this.calculateTotal(jqSuperviseCostsProportion, jqOtherCostsProportion, null)); //交强应收
  1264. insPlyIncome.setSyReceivableProportion(this.calculateTotal(sySuperviseCostsProportion, syOtherCostsProportion, null)); //商业应收
  1265. insPlyIncome.setNoReceivableProportion(this.calculateTotal(noSuperviseCostsProportion, noOtherCostsProportion, null)); //非车应收
  1266. if(insPlyIncomeVo.getPtCommissionFeevalue()!=null && insPlyIncomeVo.getPtCommissionFeevalue().compareTo(BigDecimal.ZERO) >0){
  1267. insPlyIncome.setCommissionFeevalue(insPlyIncomeVo.getPtCommissionFeevalue());
  1268. }
  1269. if(insPlyIncomeVo.getPtOtherFeevalue()!=null && insPlyIncomeVo.getPtOtherFeevalue().compareTo(BigDecimal.ZERO) >0){
  1270. insPlyIncome.setOtherFeevalue(insPlyIncomeVo.getPtOtherFeevalue());
  1271. }
  1272. } else {
  1273. BigDecimal divisor = new BigDecimal("1.06"); // 最好是使用字符串来避免精度损失
  1274. BigDecimal jqNoTaxPremium = insPlyIncomeVo.getJqPremium();// 交强手续费 按照思路 交强不含税保费* 交强手续费比例 =交强手续费
  1275. BigDecimal syNoTaxPremium = insPlyIncomeVo.getSyPremium();// 商业手续费 按照思路 商业不含税保费* 商业手续费比例 =商业手续费
  1276. BigDecimal noNoTaxPremium = insPlyIncomeVo.getNoPremium();// 非车手续费 按照思路 非车不含税保费* 非车手续费比例 =非车手续费
  1277. if (jqNoTaxPremium != null && insPlyIncomeVo.getJqSuperviseCostsProportion() != null && insPlyIncomeVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1278. insPlyIncome.setJqSuperviseCostsPremiums(getBigDecimal(jqNoTaxPremium, insPlyIncomeVo.getJqSuperviseCostsProportion()));
  1279. insPlyIncome.setJqSuperviseCostsProportion(insPlyIncomeVo.getJqSuperviseCostsProportion());
  1280. }
  1281. if (syNoTaxPremium != null && insPlyIncomeVo.getSySuperviseCostsProportion() != null && insPlyIncomeVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1282. insPlyIncome.setSySuperviseCostsPremiums(getBigDecimal(syNoTaxPremium, insPlyIncomeVo.getSySuperviseCostsProportion()));
  1283. insPlyIncome.setSySuperviseCostsProportion(insPlyIncomeVo.getSySuperviseCostsProportion());
  1284. }
  1285. if (noNoTaxPremium != null && insPlyIncomeVo.getNoSuperviseCostsProportion() != null && insPlyIncomeVo.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1286. insPlyIncome.setNoSuperviseCostsProportion(insPlyIncome.getNoSuperviseCostsProportion());
  1287. insPlyIncome.setNoSuperviseCostsPremiums(getBigDecimal(noNoTaxPremium, insPlyIncomeVo.getNoSuperviseCostsProportion()));
  1288. }
  1289. if (jqNoTaxPremium != null && insPlyIncomeVo.getJqOtherCostsProportion() != null && insPlyIncomeVo.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1290. insPlyIncome.setJqOtherCostsPremium(getBigDecimal(jqNoTaxPremium, insPlyIncomeVo.getJqOtherCostsProportion()));
  1291. insPlyIncome.setJqOtherCostsProportion(insPlyIncomeVo.getJqOtherCostsProportion());
  1292. }
  1293. if (syNoTaxPremium != null && insPlyIncomeVo.getSyOtherCostsProportion() != null && insPlyIncomeVo.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1294. insPlyIncome.setSyOtherCostsProportion(insPlyIncome.getSyOtherCostsProportion());
  1295. insPlyIncome.setSyOtherCostsPremium(getBigDecimal(syNoTaxPremium, insPlyIncomeVo.getSyOtherCostsProportion()));
  1296. }
  1297. if (noNoTaxPremium != null && insPlyIncomeVo.getOtherFeerate() != null && insPlyIncomeVo.getOtherFeerate().compareTo(BigDecimal.ZERO) != 0) {
  1298. insPlyIncome.setNoOtherCostsProportion(insPlyIncome.getOtherFeerate());
  1299. insPlyIncome.setNoOtherCostsPremium(getBigDecimal(noNoTaxPremium, insPlyIncomeVo.getOtherFeerate()));
  1300. }
  1301. if ("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())) { //保险 手续费 =不含税保费* 手续费比例
  1302. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(), insPlyIncome.getSySuperviseCostsPremiums(), null)); // 手续费
  1303. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(), insPlyIncome.getSySuperviseCostsProportion(), null));//手续费比例
  1304. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(), null, null));//总金额
  1305. } else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())) { //保险跟单费 交强跟单+商业跟单
  1306. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(), insPlyIncome.getSyOtherCostsPremium(), null));
  1307. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getJqOtherCostsProportion(), insPlyIncome.getSyOtherCostsProportion(), null));
  1308. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(), null, null));//总金额
  1309. }
  1310. if ("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())) {// 非车
  1311. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getNoSuperviseCostsPremiums(), null, null)); // 非车手续费
  1312. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getNoSuperviseCostsProportion(), null, null)); //非车比例
  1313. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(), null, null));//总金额
  1314. } else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())) { //非车跟单
  1315. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getNoOtherCostsPremium(), null, null)); //非车跟单金额
  1316. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getNoOtherCostsProportion(), null, null)); // 非车跟单比例
  1317. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(), null, null));//总金额
  1318. }
  1319. }
  1320. }
  1321. /**
  1322. * 计算 金额
  1323. *
  1324. * @param taxPremium
  1325. * @param proportion
  1326. * @return
  1327. */
  1328. private static BigDecimal getBigDecimal(BigDecimal taxPremium, BigDecimal proportion) {
  1329. BigDecimal divisor = new BigDecimal("1.06"); // 示例除数
  1330. // 先进行除法,保留5位小数,不进行四舍五入(使用RoundingMode.DOWN)
  1331. BigDecimal dividedAmount = taxPremium.divide(divisor, 5, BigDecimal.ROUND_DOWN);
  1332. // 将比例除以100,假设proportion是一个百分比值
  1333. // 然后进行乘法,并进行舍入到5位小数
  1334. BigDecimal result = dividedAmount.multiply( proportion.divide(new BigDecimal(100))).setScale(5, BigDecimal.ROUND_DOWN);
  1335. return result;
  1336. }
  1337. /**
  1338. * @param value1 保费
  1339. * @param value2 比例
  1340. * @return 费用
  1341. */
  1342. private BigDecimal algorithmAmount(BigDecimal value1, BigDecimal value2) {
  1343. BigDecimal divide = value2.divide(new BigDecimal(100));
  1344. return value1.multiply(divide).setScale(5,BigDecimal.ROUND_DOWN);
  1345. }
  1346. private BigDecimal initializationBigdecimal(BigDecimal value) {
  1347. return value != null ? value : BigDecimal.ZERO;
  1348. }
  1349. private void saveLog(InsPlyIncomeVo insPlyIncomeVo) {
  1350. // 添加记录
  1351. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1352. settlementDocumentaryLogEntity.setCrudStatus(insPlyIncomeVo.getCrudStatus());
  1353. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue());
  1354. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId());
  1355. settlementDocumentaryLogEntity.setAmountType("2");
  1356. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1357. }
  1358. @Override
  1359. @Transactional
  1360. public HttpResult<InsPlyIncome> insertByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  1361. Long id = new SnowFlakeUtil().nextId();
  1362. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1363. insPlyIncomeVo.setOrderno(id.toString());
  1364. String signdateStr = insPlyIncomeVo.getSignDate();
  1365. LocalDateTime localDateTime = this.LocalDatePareLocalDateTime(signdateStr);
  1366. insPlyIncomeVo.setSignDate(null);
  1367. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1368. insPlyIncome.setUserId(BaseController.getUser().getId());
  1369. insPlyIncome.setDocumentaryFeesStatus("0");
  1370. insPlyIncome.setHandlingFeesStatus("0");
  1371. insPlyIncome.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1372. insPlyIncome.setIsNotDocumentary(insPlyIncomeVo.getIsNotDocumentary()); //是否是跟单
  1373. insPlyIncome.setSignDate(localDateTime);
  1374. insPlyIncome.setDeptId(BaseController.getUser().getDeptId());
  1375. insPlyIncome.setCreateTime(LocalDateTime.now());
  1376. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncomeVo.getJqOtherCostsProportion(),insPlyIncomeVo.getSyOtherCostsProportion(),insPlyIncomeVo.getNoOtherCostsProportion()));
  1377. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncomeVo.getJqSuperviseCostsProportion(),insPlyIncomeVo.getSySuperviseCostsProportion(),insPlyIncomeVo.getNoSuperviseCostsProportion()));
  1378. if (insPlyIncome.getJqPremium() != null && insPlyIncome.getJqPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getJqSuperviseCostsProportion() != null && insPlyIncome.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1379. insPlyIncome.setJqSuperviseCostsPremiums(getBigDecimal(insPlyIncome.getJqPremium(), insPlyIncomeVo.getJqSuperviseCostsProportion()));
  1380. }
  1381. if (insPlyIncome.getSyPremium() != null && insPlyIncome.getSyPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getSySuperviseCostsProportion() != null && insPlyIncome.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1382. insPlyIncome.setSySuperviseCostsPremiums(getBigDecimal(insPlyIncome.getSyPremium(), insPlyIncomeVo.getSySuperviseCostsProportion()));
  1383. }
  1384. if (insPlyIncome.getNoPremium() != null && insPlyIncome.getNoPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getNoSuperviseCostsProportion() != null && insPlyIncome.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1385. insPlyIncome.setNoSuperviseCostsPremiums(getBigDecimal(insPlyIncome.getNoPremium(), insPlyIncomeVo.getNoSuperviseCostsProportion()));
  1386. }
  1387. if (insPlyIncome.getJqPremium() != null && insPlyIncome.getJqPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getJqOtherCostsProportion() != null && insPlyIncome.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1388. insPlyIncome.setJqOtherCostsPremium(getBigDecimal(insPlyIncome.getJqPremium(), insPlyIncomeVo.getJqOtherCostsProportion()));
  1389. }
  1390. if (insPlyIncome.getSyPremium() != null && insPlyIncome.getSyPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getSyOtherCostsProportion() != null && insPlyIncome.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1391. insPlyIncome.setSyOtherCostsPremium(getBigDecimal(insPlyIncome.getSyPremium(), insPlyIncomeVo.getSyOtherCostsProportion()));
  1392. }
  1393. if (insPlyIncome.getNoPremium() != null && insPlyIncome.getNoPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getNoOtherCostsProportion() != null && insPlyIncome.getNoOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1394. insPlyIncome.setNoOtherCostsPremium(getBigDecimal(insPlyIncome.getNoPremium(), insPlyIncomeVo.getNoOtherCostsProportion()));
  1395. }
  1396. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),insPlyIncome.getOtherFeevalue(),null));
  1397. String partnerCompaniesId = insPlyIncome.getPartnerCompaniesId();
  1398. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  1399. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  1400. String name = esmInsCompany.getNamesimple(); //合作名称
  1401. insPlyIncome.setPartnerCompaniesName(name);
  1402. HashMap<String, Object> params = new HashMap<>();
  1403. params.put("agreeId",insPlyIncomeVo.getAgreeId());
  1404. PtlAgreement ptlAgreement = ptlAgreementService.selectAgreeId(params);
  1405. if (ObjectUtils.isEmpty(ptlAgreement)) {
  1406. return HttpResult.error("协议匹配不上");
  1407. }
  1408. insPlyIncome.setAgreementId(ptlAgreement.getId());
  1409. baseMapper.insert(insPlyIncome);
  1410. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  1411. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  1412. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  1413. insPlyIncomeLog.setId(null);
  1414. insPlyIncomeLog.setOperationStatus("1");
  1415. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  1416. return HttpResult.ok();
  1417. }
  1418. private LocalDateTime LocalDatePareLocalDateTime(String signdateStr) {
  1419. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  1420. // 将字符串解析为LocalDate
  1421. LocalDate signdate = LocalDate.parse(signdateStr, formatter);
  1422. // 创建一个 LocalTime 对象表示中午12点
  1423. LocalTime noon = LocalTime.of(12, 0);
  1424. // 使用 LocalDate 和 LocalTime 来创建 LocalDateTime
  1425. return LocalDateTime.of(signdate, noon);
  1426. }
  1427. /**
  1428. * 删除id 已开票或者已结算都不可以进行 删除
  1429. * 因为跟单没有关联表 也无法关联到开票表所以只能按照 条件去查询判断 保司机构 id
  1430. * @param insPlyIncomeVo
  1431. * @return
  1432. */
  1433. @Override
  1434. @Transactional
  1435. public HttpResult<InsPlyIncome> deleteById(InsPlyIncomeVo insPlyIncomeVo) {
  1436. HashMap<String, Object> params = new HashMap<>();
  1437. params.put("id",insPlyIncomeVo.getId());
  1438. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1439. InsPlyIncome insPlyIncome = insPlyIncomes.get(0);
  1440. if (StringUtils.isNotEmpty(insPlyIncome.getAgreementType()) && "1".equals(insPlyIncome.getAgreementType())) {
  1441. if ("1".equals(insPlyIncome.getHandlingFeesStatus())) {
  1442. throw new SystemException("已结算不可以进行删除");
  1443. }
  1444. } else if (StringUtils.isNotEmpty(insPlyIncome.getAgreementType()) && "2".equals(insPlyIncome.getAgreementType())) {
  1445. if ("0".equals(insPlyIncome.getIsNotDocumentary())) {
  1446. String taskId = insPlyIncome.getTaskId();
  1447. if (StringUtils.isNotEmpty(taskId)) {
  1448. throw new SystemException("已开票不能进行删除");
  1449. }
  1450. } else {
  1451. // 因为跟单没有关联表 也无法关联到开票表所以只能按照 条件去进行判断
  1452. if(StringUtils.isNotEmpty( insPlyIncome.getSettleOtherStatus()) && "1".equals( insPlyIncome.getSettleOtherStatus())){
  1453. throw new SystemException("已经对账不能进行删除");
  1454. }
  1455. }
  1456. }
  1457. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  1458. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  1459. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  1460. insPlyIncomeLog.setId(null);
  1461. insPlyIncomeLog.setOperationStatus("3");
  1462. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  1463. baseMapper.deleteById(insPlyIncomeVo.getId()); //删除 结算 然后删除结算表
  1464. return HttpResult.ok("删除成功");
  1465. }
  1466. @Override
  1467. @Transactional
  1468. public void uodateBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1469. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1470. insPlyIncomeVo.setHandlingFeesStatus("1");
  1471. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1472. insPlyIncome.setSettlementUserId(BaseController.getUser().getId());
  1473. insPlyIncome.setSettlementTime(LocalDateTime.now());
  1474. baseMapper.updateById(insPlyIncome);
  1475. // 生成记录
  1476. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1477. if (StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType()) && "1".equals(insPlyIncomeVo.getAgreementType())) {
  1478. // 只有平台协议 才会跟单费一笔结算
  1479. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); // 跟单费金额
  1480. }
  1481. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); // 手续费金额
  1482. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId()); // 关联id
  1483. settlementDocumentaryLogEntity.setAmountType("1"); //手续费结算
  1484. settlementDocumentaryLogEntity.setCreateTime(new Date());
  1485. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1486. }
  1487. @Override
  1488. @Transactional
  1489. public HttpResult<BasePageResult<InsPlyIncome>> totalQuery(InsPlyIncomeVo insPlyIncomeVo) {
  1490. HashMap<String, Object> params = new HashMap<>();
  1491. PageInfo<List<InsPlyIncome>> pageHelper = null;
  1492. if (insPlyIncomeVo.getStartDate() != null) {
  1493. params.put("startDate", insPlyIncomeVo.getStartDate().toString());
  1494. }
  1495. if (insPlyIncomeVo.getEndDate() != null) {
  1496. params.put("endDate", insPlyIncomeVo.getEndDate().toString());
  1497. }
  1498. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1499. params.put("year", insPlyIncomeVo.getYear());
  1500. }
  1501. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())) {
  1502. params.put("isNotCar", insPlyIncomeVo.getIsNotCar());
  1503. }
  1504. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())) {
  1505. params.put("isOther", insPlyIncomeVo.getIsNotDocumentary());
  1506. }
  1507. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())) {
  1508. params.put("documentaryFeesStatus", insPlyIncomeVo.getDocumentaryFeesStatus());
  1509. }
  1510. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())) {
  1511. params.put("companyId", insPlyIncomeVo.getCompanyId());
  1512. }
  1513. params.put("pageNum", insPlyIncomeVo.getPageNum());
  1514. params.put("pageSize", insPlyIncomeVo.getPageSize());
  1515. List<InsPlyIncome> list = this.baseMapper.totalQuery(params);
  1516. pageHelper = new PageInfo(list);
  1517. return HttpResult.ok(new BasePageResult<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(),
  1518. pageHelper.getPages(), list));
  1519. }
  1520. /**
  1521. *
  1522. * @param insPlyIncomeVo ids ins_ply_income 这个表的ids incomeIds settlement_documentary_fees 这个表的ids
  1523. * @return
  1524. */
  1525. /**
  1526. * 跟单费结算 有分批结算的情况
  1527. *
  1528. * @param insPlyIncomeVo
  1529. * @return
  1530. */
  1531. @Override
  1532. @Transactional
  1533. public HttpResult batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1534. // 分批结算
  1535. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  1536. String id = insPlyIncomeVo.getId(); // 开票id
  1537. SettlementDocumentaryFeesEntity settlementDocumentaryFeesServiceById = settlementDocumentaryFeesService.getById(id); //
  1538. BigDecimal allAmount = settlementDocumentaryFeesServiceById.getSettlementAmount();
  1539. HashMap<String, Object> params = new HashMap<>();
  1540. params.put("id", insPlyIncomeVo.getId());
  1541. params.put("handlingFeesStatus", "1");
  1542. SettlementDocumentaryFeesEntity parentSettlementDocumentaryFeesEntity =
  1543. settlementDocumentaryFeesService.getByParentSettlementAmount(params);
  1544. if (ObjectUtils.isNotEmpty(parentSettlementDocumentaryFeesEntity)) { // 多次结算
  1545. BigDecimal totalAmount = parentSettlementDocumentaryFeesEntity.getTotalAmount();
  1546. totalAmount = totalAmount.add(insPlyIncomeVo.getSettlementAmount());
  1547. if (allAmount.compareTo(totalAmount) < 0) {
  1548. return HttpResult.error("结算金额超出开票金额");
  1549. }
  1550. } else {
  1551. if (allAmount.compareTo(insPlyIncomeVo.getSettlementAmount()) < 0) {
  1552. return HttpResult.error("结算金额超出开票金额");
  1553. }
  1554. }
  1555. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId()); //开票号
  1556. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1557. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1558. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId()); // 保险公司id
  1559. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1560. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算金额
  1561. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1562. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1563. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1564. settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1565. if ("0".equals(insPlyIncomeVo.getInvoicingMethod())) {
  1566. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1567. } else {
  1568. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1569. }
  1570. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1571. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1572. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
  1573. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1574. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1575. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1576. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1577. return HttpResult.ok();
  1578. }
  1579. @Override
  1580. @Transactional
  1581. public HttpResult<Object> batchSumBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1582. List<InsPlyIncomeVo> multipleSelection = insPlyIncomeVo.getMultipleSelection();
  1583. HashMap<String, Object> params = new HashMap<>();
  1584. Date date = new Date();
  1585. BigDecimal settleMentAmount = BigDecimal.ZERO;
  1586. BigDecimal settleNotMentAmount = BigDecimal.ZERO;
  1587. for (InsPlyIncomeVo item : multipleSelection){
  1588. SettlementDocumentaryFeesEntity settlementDocumentaryFeesVo = new SettlementDocumentaryFeesEntity();
  1589. if(item.getInvoicCommissionFeevalue() ==null || item .getInvoicCommissionFeevalue().compareTo(BigDecimal.ZERO) <=0){
  1590. throw new SystemException("请输入正确金额");
  1591. }
  1592. String id = item.getId();
  1593. SettlementDocumentaryFeesEntity settlementDocumentaryFeesEntity = settlementDocumentaryFeesService.getBaseMapper().selectById(id); // 开票
  1594. BigDecimal invoicedNotSettledAmount = settlementDocumentaryFeesEntity.getInvoicedNotSettledAmount();//未结算金额
  1595. if(item.getInvoicCommissionFeevalue().compareTo(invoicedNotSettledAmount) >0){
  1596. throw new SystemException("结算金额大于未结算金额");
  1597. }
  1598. if(item.getInvoicCommissionFeevalue().compareTo(BigDecimal.ZERO) >0){
  1599. settlementDocumentaryFeesVo.setInvoiceId(settlementDocumentaryFeesEntity.getInvoicId()); //开票号
  1600. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1601. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1602. settlementDocumentaryFeesVo.setCompanyId(settlementDocumentaryFeesEntity.getCompanyId()); // 保险公司id
  1603. settlementDocumentaryFeesVo.setPartnerCompaniesId(settlementDocumentaryFeesEntity.getPartnerCompaniesId()); //合作公司id
  1604. // settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算金额
  1605. settlementDocumentaryFeesVo.setIsNotCar(settlementDocumentaryFeesEntity.getIsNotCar()); // 是否是非车
  1606. settlementDocumentaryFeesVo.setInvoicingMethod(settlementDocumentaryFeesEntity.getInvoicingMethod()); //开票方式
  1607. settlementDocumentaryFeesVo.setTaxPoints(settlementDocumentaryFeesEntity.getTaxPoints()); //税点
  1608. settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1609. if ("0".equals(insPlyIncomeVo.getInvoicingMethod())) {
  1610. settlementDocumentaryFeesVo.setExpendAmount(item.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1611. } else {
  1612. settlementDocumentaryFeesVo.setExpendAmount(item.getInvoicCommissionFeevalue()); //进账金额
  1613. }
  1614. settlementDocumentaryFeesVo.setSettlementAmount(item.getInvoicCommissionFeevalue()); //进账金额
  1615. settlementDocumentaryFeesVo.setHandlingFeesStatus(settlementDocumentaryFeesEntity.getHandlingFeesStatus());
  1616. settlementDocumentaryFeesVo.setTotalAmount(settlementDocumentaryFeesEntity.getSettlementAmount());
  1617. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1618. settlementDocumentaryFeesVo.setSettlementTime(LocalDate.now());
  1619. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1620. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1621. settlementDocumentaryFeesVo.setInvoicedSettledAmount(item.getInvoicCommissionFeevalue());
  1622. settlementDocumentaryFeesVo.setInvoicedNotSettledAmount(BigDecimal.ZERO);
  1623. // 生成跟单费结算记录
  1624. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1625. settlementDocumentaryLogEntity.setAmount(item.getInvoicCommissionFeevalue()); // 结算金额
  1626. settlementDocumentaryLogEntity.setSettlementDocumentaryId(settlementDocumentaryFeesEntity.getId()); // 关联id
  1627. settlementDocumentaryLogEntity.setAmountType("2"); //跟单费结算
  1628. settlementDocumentaryLogEntity.setCreateTime(date);
  1629. settlementDocumentaryFeesVo.setSettlementSumId(insPlyIncomeVo.getSettlementSumId());
  1630. settlementDocumentaryFeesService.getBaseMapper().insert(settlementDocumentaryFeesVo);
  1631. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1632. //修改开票金额
  1633. BigDecimal add = settlementDocumentaryFeesEntity.getInvoicedSettledAmount().add(item.getInvoicCommissionFeevalue());
  1634. settlementDocumentaryFeesEntity.setInvoicedSettledAmount(add);
  1635. BigDecimal subtract = settlementDocumentaryFeesEntity.getSettlementAmount().subtract(add);
  1636. settlementDocumentaryFeesEntity.setInvoicedNotSettledAmount(subtract);
  1637. if (subtract.compareTo(BigDecimal.ZERO) == 0) {
  1638. settlementDocumentaryFeesEntity.setCompletionStatus("2");
  1639. } else if (subtract.compareTo(BigDecimal.ZERO) != 0) {
  1640. settlementDocumentaryFeesEntity.setCompletionStatus("1");
  1641. }
  1642. settlementDocumentaryFeesService.updateById(settlementDocumentaryFeesEntity);
  1643. settleMentAmount = settleMentAmount.add(settlementDocumentaryFeesEntity.getInvoicedSettledAmount());
  1644. settleNotMentAmount = settleNotMentAmount.add(settlementDocumentaryFeesEntity.getInvoicedNotSettledAmount());
  1645. }
  1646. // 更新金额
  1647. SettlementDocumentaryFeesSumEntity settlementDocumentaryFeesSumEntity = settlementDocumentaryFeesSumService.getById(insPlyIncomeVo.getSettlementSumId());
  1648. settlementDocumentaryFeesSumEntity.setInvoicedSettledAmount(settleMentAmount);
  1649. settlementDocumentaryFeesSumEntity.setInvoicedNotSettledAmount(settleNotMentAmount);
  1650. if (settleNotMentAmount.compareTo(BigDecimal.ZERO) == 0) {
  1651. settlementDocumentaryFeesSumEntity.setCompletionStatus("2");
  1652. } else if (settleNotMentAmount.compareTo(BigDecimal.ZERO) != 0) {
  1653. settlementDocumentaryFeesSumEntity.setCompletionStatus("1");
  1654. }
  1655. settlementDocumentaryFeesSumService.updateById(settlementDocumentaryFeesSumEntity);
  1656. }
  1657. return HttpResult.ok();
  1658. }
  1659. /**
  1660. * @param insPlyIncomeVo
  1661. * @return
  1662. */
  1663. @Override
  1664. public List<InsPlyIncome> totalBxAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1665. HashMap<String, Object> params = new HashMap<>();
  1666. params = this.saveParams(insPlyIncomeVo, params);
  1667. params.remove("handlingFeesStatus");
  1668. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  1669. for (InsPlyIncome item : resultList) {
  1670. BigDecimal commissionFeevalue = BigDecimal.ZERO; //总金额
  1671. BigDecimal invoicCommissionFeevalue = BigDecimal.ZERO; //开票未结算
  1672. BigDecimal readyCommissionFeevalue = BigDecimal.ZERO; // 已开票已结算
  1673. BigDecimal noInvoicCommissionFeevalue = BigDecimal.ZERO; //未开票金额
  1674. BigDecimal unSettledAmount; //未结算金额
  1675. params.put("partnerCompaniesId", item.getPartnerCompaniesId());
  1676. params.remove("handlingFeesStatus");
  1677. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params); //金额总数
  1678. for (InsPlyIncome all : insPlyIncomes) {
  1679. commissionFeevalue = commissionFeevalue.add(all.getCommissionFeevalue());
  1680. }
  1681. //已开票金额 = 开票未结算+ 开票已结算
  1682. params.put("handlingFeesStatus", "0"); // 开票
  1683. params.put("settlementStatus", "1"); // 开票
  1684. List<SettlementDocumentaryFeesEntity> invoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  1685. for (SettlementDocumentaryFeesEntity invoicInsPlyIncome : invoicInsPlyIncomes) {
  1686. BigDecimal invoicIcommissionFeevalue = invoicInsPlyIncome.getSettlementAmount();// 已经开票金额
  1687. invoicCommissionFeevalue = invoicCommissionFeevalue.add(invoicIcommissionFeevalue); //开票金额
  1688. }
  1689. params.put("settlementStatus", "2"); // 结算
  1690. List<SettlementDocumentaryFeesEntity> settleInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  1691. for (SettlementDocumentaryFeesEntity settleInsPlyIncome : settleInsPlyIncomes) {
  1692. BigDecimal settleIcommissionFeevalue = settleInsPlyIncome.getSettlementAmount();// 已结算金额
  1693. readyCommissionFeevalue = readyCommissionFeevalue.add(settleIcommissionFeevalue); //已结算总
  1694. }
  1695. params.put("settlementStatus", 0); //未开票金额
  1696. List<SettlementDocumentaryFeesEntity> noInvoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  1697. for (SettlementDocumentaryFeesEntity noInvoicInsPlyIncome : noInvoicInsPlyIncomes) {
  1698. BigDecimal noInvoicIcommissionFeevalue = noInvoicInsPlyIncome.getSettlementAmount();// 未开票金额
  1699. noInvoicCommissionFeevalue = noInvoicCommissionFeevalue.add(noInvoicIcommissionFeevalue); //未开票总金额
  1700. }
  1701. noInvoicCommissionFeevalue = commissionFeevalue.subtract(invoicCommissionFeevalue);// 未开票
  1702. unSettledAmount = commissionFeevalue.subtract(readyCommissionFeevalue); //未结算
  1703. //已开票金额
  1704. item.setCommissionFeevalue(commissionFeevalue); //总手续费
  1705. item.setAllInvoicCommissionFeevalue(invoicCommissionFeevalue); //总开票金额
  1706. // 开票未结算 = 开票金额 - 已开票已结算
  1707. invoicCommissionFeevalue = invoicCommissionFeevalue.subtract(readyCommissionFeevalue);
  1708. item.setInvoicCommissionFeevalue(invoicCommissionFeevalue); //开票未结算
  1709. item.setReadyCommissionFeevalue(readyCommissionFeevalue); //已开票已结算
  1710. item.setNoInvoicCommissionFeevalue(noInvoicCommissionFeevalue); //未开票金额
  1711. item.setUnSettledAmount(unSettledAmount); // 未结算金额
  1712. }
  1713. return resultList;
  1714. }
  1715. /**
  1716. * @param idList 要开票的数据集合
  1717. * @param resultList 总返回数据
  1718. */
  1719. private void splicingIds(List<InsPlyIncome> idList, List<InsPlyIncome> resultList) {
  1720. // 使用Map来存储agreementId到其id列表的映射
  1721. Map<String, List<String>> idMap = new HashMap<>();
  1722. for (InsPlyIncome idItem : idList) {
  1723. String partnerCompaniesId = idItem.getPartnerCompaniesId();
  1724. idMap.computeIfAbsent(partnerCompaniesId, k -> new ArrayList<>()).add(idItem.getId());
  1725. }
  1726. for (InsPlyIncome resultItem : resultList) {
  1727. List<String> ids = idMap.getOrDefault(resultItem.getPartnerCompaniesId(), Collections.emptyList());
  1728. String idsString = String.join(",", ids);
  1729. resultItem.setIds(idsString);
  1730. }
  1731. }
  1732. /**
  1733. * @param insPlyIncomeVo
  1734. * @return 保险手续费改成多次结算
  1735. */
  1736. @Override
  1737. @Transactional
  1738. public HttpResult<Object> batchInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1739. ImportResult importResult = importAsyncService.getById(insPlyIncomeVo.getSelectIds().get(0)); // 查询 任务
  1740. List<String> byTaskId = incomeTaskRelationshipService.getByTaskId(importResult.getId());
  1741. HashMap<String, Object> params = new HashMap<>();
  1742. if (StringUtils.isNotEmpty(importResult.getId())) {
  1743. params.put("companyId", importResult.getCompanyId());
  1744. params.put("partnerCompaniesId", importResult.getPartnerCompaniesId());
  1745. params.put("isOther", "0");
  1746. if (StringUtils.isNotEmpty(importResult.getHandStatus())) {
  1747. if ("0".equals(importResult.getHandStatus())) {
  1748. params.put("isNotCar", "0");
  1749. } else if ("1".equals(importResult.getHandStatus())) {
  1750. params.put("isNotCar", "1");
  1751. }
  1752. }
  1753. if (!CollectionUtils.isEmpty(byTaskId)) {
  1754. params.put("incomeIds", byTaskId);
  1755. }
  1756. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1757. if (!CollectionUtils.isEmpty(insPlyIncomes)) {
  1758. if (insPlyIncomeVo != null) { // 确保insPlyIncomeVo不是null
  1759. for (InsPlyIncome item : insPlyIncomes) {
  1760. item.setInvoicTime(LocalDate.now());
  1761. item.setInvoicId(insPlyIncomeVo.getInvoicId());
  1762. item.setHandlingFeesStatus("2");
  1763. if (StringUtils.isNotEmpty(item.getTaskId())) {
  1764. return HttpResult.error("该单据已经开票 ");
  1765. } else {
  1766. item.setTaskId(importResult.getId());
  1767. item.setSettlementTime(LocalDateTime.now());
  1768. baseMapper.updateById(item);
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. insPlyIncomeVo.setNoInvoicCommissionFeevalue(importResult.getTotalAmount());
  1775. insPlyIncomeVo.setOtherFeevalue(importResult.getTotalAmount());
  1776. insPlyIncomeVo.setHandlingFeesStatus("0"); // 0手续费 1 跟单费
  1777. insPlyIncomeVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1778. insPlyIncomeVo.setAgreementId(importResult.getAgreementId());
  1779. insPlyIncomeVo.setAgreementType(insPlyIncomeVo.getAgreementType());
  1780. insPlyIncomeVo.setPartnerCompaniesId(importResult.getPartnerCompaniesId());
  1781. insPlyIncomeVo.setSettlementAmount(importResult.getTotalAmount());
  1782. insPlyIncomeVo.setContractId(insPlyIncomeVo.getInvoicId());
  1783. insPlyIncomeVo.setCompanyId(importResult.getCompanyId());
  1784. insPlyIncomeVo.setTaskId(importResult.getId());
  1785. this.batchInvoic(insPlyIncomeVo);
  1786. return HttpResult.ok();
  1787. }
  1788. @Override
  1789. public HttpResult<InsPlyIncome> queryInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1790. HashMap<String, Object> params = new HashMap<>();
  1791. params = this.saveParams(insPlyIncomeVo, params);
  1792. InsPlyIncome result = baseMapper.queryInvoicing(params); //总金额
  1793. params.put("handlingFeesStatus", "0");
  1794. InsPlyIncome noResult = baseMapper.queryInvoicing(params); //未结算金额
  1795. result.setReadyCommissionFeevalue(noResult.getCommissionFeevalue());
  1796. return HttpResult.ok(result);
  1797. }
  1798. @Override
  1799. @Transactional
  1800. public HttpResult<Object> batchBxBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1801. if( insPlyIncomeVo.getSettlementAmount() ==null || insPlyIncomeVo.getSettlementAmount().compareTo(BigDecimal.ZERO) <=0){
  1802. throw new SystemException("金额未填写");
  1803. }
  1804. // 表内总金额
  1805. SettlementDocumentaryFeesEntity byIdSettlementDocumentaryFeesEntity =
  1806. settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
  1807. BigDecimal invoicAmount = byIdSettlementDocumentaryFeesEntity.getTotalAmount();
  1808. String taskId = byIdSettlementDocumentaryFeesEntity.getTaskId();
  1809. List<String> byTaskId = incomeTaskRelationshipService.getByTaskId(taskId);
  1810. HashMap<String, Object> params = new HashMap<>();
  1811. params.put("id", insPlyIncomeVo.getId());
  1812. params.put("handlingFeesStatus", "0");
  1813. SettlementDocumentaryFeesEntity parentSettlementDocumentaryFeesEntity =
  1814. settlementDocumentaryFeesService.getByParentSettlementAmount(params);
  1815. if (ObjectUtils.isNotEmpty(parentSettlementDocumentaryFeesEntity)) { // 多次结算
  1816. BigDecimal totalAmount = parentSettlementDocumentaryFeesEntity.getTotalAmount();
  1817. totalAmount = totalAmount.add(insPlyIncomeVo.getSettlementAmount());
  1818. if (invoicAmount.compareTo(totalAmount) < 0) {
  1819. return HttpResult.error("结算金额大于开票金额");
  1820. }
  1821. if(totalAmount.compareTo(invoicAmount) ==0){
  1822. HashMap<String, Object> incomeParams = new HashMap<>();
  1823. incomeParams.put("incomeIds", byTaskId);
  1824. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(incomeParams);
  1825. for (InsPlyIncome item : insPlyIncomes) {
  1826. item.setHandlingFeesStatus("1");
  1827. item.setSettlementUserId(BaseController.getUser().getId());
  1828. baseMapper.updateById(item);
  1829. }
  1830. }
  1831. } else {
  1832. if (invoicAmount.compareTo(insPlyIncomeVo.getSettlementAmount()) < 0) {
  1833. return HttpResult.error("结算金额大于开票金额");
  1834. } else if (invoicAmount.compareTo(insPlyIncomeVo.getSettlementAmount()) == 0) {
  1835. HashMap<String, Object> incomeParams = new HashMap<>();
  1836. incomeParams.put("incomeIds", byTaskId);
  1837. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(incomeParams);
  1838. for (InsPlyIncome item : insPlyIncomes) {
  1839. item.setHandlingFeesStatus("1");
  1840. item.setSettlementUserId(BaseController.getUser().getId());
  1841. baseMapper.updateById(item);
  1842. }
  1843. }
  1844. }
  1845. // 分批结算
  1846. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  1847. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId()); //开票号
  1848. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1849. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1850. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId()); // 保险公司id
  1851. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1852. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1853. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1854. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1855. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1856. settlementDocumentaryFeesVo.setTaskId(insPlyIncomeVo.getTaskId());
  1857. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1858. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
  1859. settlementDocumentaryFeesVo.setHandlingFeesStatus("0");
  1860. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1861. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());
  1862. settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1863. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1864. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1865. BigDecimal add = byIdSettlementDocumentaryFeesEntity.getInvoicedSettledAmount().add(insPlyIncomeVo.getSettlementAmount());
  1866. byIdSettlementDocumentaryFeesEntity.setInvoicedSettledAmount(add);
  1867. BigDecimal subtract = byIdSettlementDocumentaryFeesEntity.getTotalAmount().subtract(add);
  1868. byIdSettlementDocumentaryFeesEntity.setInvoicedNotSettledAmount(subtract);
  1869. if (subtract.compareTo(BigDecimal.ZERO) == 0) {
  1870. byIdSettlementDocumentaryFeesEntity.setCompletionStatus("2");
  1871. } else if (subtract.compareTo(BigDecimal.ZERO) != 0) {
  1872. byIdSettlementDocumentaryFeesEntity.setCompletionStatus("1");
  1873. }
  1874. settlementDocumentaryFeesService.updateById(byIdSettlementDocumentaryFeesEntity);
  1875. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1876. return HttpResult.ok();
  1877. }
  1878. @Override
  1879. public HttpResult<InsPlyIncome> querySettInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1880. HashMap<String, Object> params = new HashMap<>();
  1881. params = this.saveParams(insPlyIncomeVo, params);
  1882. InsPlyIncome insPlyIncome = baseMapper.queryInvoicing(params); //已经开票
  1883. return HttpResult.ok(insPlyIncome);
  1884. }
  1885. /**
  1886. * @param insPlyIncomeVo
  1887. * @return
  1888. */
  1889. @Override
  1890. public HttpResult<List<InsPlyIncome>> allOtherAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1891. HashMap<String, Object> params = new HashMap<>();
  1892. params = this.saveParams(insPlyIncomeVo, params);
  1893. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  1894. //总跟单费
  1895. for (InsPlyIncome item : resultList) {
  1896. BigDecimal otherFeevalue = BigDecimal.ZERO; //总跟单金额
  1897. BigDecimal invoicCommissionFeevalue = BigDecimal.ZERO; //已开票跟单费
  1898. BigDecimal readyCommissionFeevalue = BigDecimal.ZERO; // 已开票已结算 跟单费
  1899. BigDecimal noInvoicCommissionFeevalue = BigDecimal.ZERO; //未开票跟单金额
  1900. BigDecimal unSettledAmount = BigDecimal.ZERO; //未结算跟单金额
  1901. BigDecimal expendAmount = BigDecimal.ZERO; //实收金额
  1902. BigDecimal taxesFees = BigDecimal.ZERO; //税费
  1903. BigDecimal taxPoints = BigDecimal.ZERO; //税点
  1904. params.put("partnerCompaniesId", item.getPartnerCompaniesId());
  1905. params.remove("handlingFeesStatus");
  1906. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params); // 总跟单费
  1907. for (InsPlyIncome all : insPlyIncomes) {
  1908. otherFeevalue = otherFeevalue.add(all.getOtherFeevalue());
  1909. }
  1910. //已开票金额 = 开票未结算+ 开票已结算
  1911. params.put("handlingFeesStatus", "1"); // 开票
  1912. params.put("settlementStatus", "1"); // 开票
  1913. List<SettlementDocumentaryFeesEntity> invoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  1914. for (SettlementDocumentaryFeesEntity invoicInsPlyIncome : invoicInsPlyIncomes) {
  1915. BigDecimal invoicIcommissionFeevalue = invoicInsPlyIncome.getSettlementAmount();// 已经开票金额
  1916. invoicCommissionFeevalue = invoicCommissionFeevalue.add(invoicIcommissionFeevalue); //开票金额
  1917. }
  1918. params.put("settlementStatus", "2"); // 结算
  1919. List<SettlementDocumentaryFeesEntity> settleInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  1920. for (SettlementDocumentaryFeesEntity settleInsPlyIncome : settleInsPlyIncomes) {
  1921. BigDecimal settleIcommissionFeevalue = settleInsPlyIncome.getSettlementAmount();// 已结算金额
  1922. readyCommissionFeevalue = readyCommissionFeevalue.add(settleIcommissionFeevalue); //已结算总
  1923. BigDecimal divide = new BigDecimal(100).subtract(settleInsPlyIncome.getTaxPoints()).divide(new BigDecimal(100));
  1924. expendAmount = expendAmount.add(settleInsPlyIncome.getSettlementAmount().multiply(divide));
  1925. }
  1926. params.put("settlementStatus", 0); //未开票金额
  1927. List<SettlementDocumentaryFeesEntity> noInvoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  1928. for (SettlementDocumentaryFeesEntity noInvoicInsPlyIncome : noInvoicInsPlyIncomes) {
  1929. BigDecimal noInvoicIcommissionFeevalue = noInvoicInsPlyIncome.getSettlementAmount();// 未开票金额
  1930. noInvoicCommissionFeevalue = noInvoicCommissionFeevalue.add(noInvoicIcommissionFeevalue); //未开票总金额
  1931. }
  1932. noInvoicCommissionFeevalue = otherFeevalue.subtract(invoicCommissionFeevalue);// 未开票
  1933. unSettledAmount = otherFeevalue.subtract(readyCommissionFeevalue); //未结算
  1934. //已开票金额
  1935. item.setOtherFeevalue(otherFeevalue); //总手续费
  1936. item.setAllInvoicCommissionFeevalue(invoicCommissionFeevalue); //总开票金额
  1937. // 开票未结算 = 开票金额 - 已开票已结算
  1938. invoicCommissionFeevalue = invoicCommissionFeevalue.subtract(readyCommissionFeevalue);
  1939. item.setInvoicCommissionFeevalue(invoicCommissionFeevalue); //开票未结算
  1940. item.setReadyCommissionFeevalue(readyCommissionFeevalue); //已开票已结算
  1941. item.setNoInvoicCommissionFeevalue(noInvoicCommissionFeevalue); //未开票金额
  1942. item.setUnSettledAmount(unSettledAmount); // 未结算金额
  1943. // 实收金额 = 结算金额 *1-税点
  1944. taxesFees = readyCommissionFeevalue.subtract(expendAmount);
  1945. item.setExpendAmount(expendAmount);
  1946. item.setTaxesFees(taxesFees);
  1947. }
  1948. return HttpResult.ok(resultList);
  1949. }
  1950. @Override
  1951. @Transactional
  1952. public HttpResult<Object> batchInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  1953. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  1954. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1955. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  1956. }
  1957. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getMultipleSelection())) {
  1958. InsPlyIncomeVo insPlyIncomeVo1 = insPlyIncomeVo.getMultipleSelection().get(0);
  1959. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo1.getSettlementAmount());
  1960. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo1.getAllTotalOtherFeevalue());
  1961. YearMonth yearMonth = YearMonth.parse(insPlyIncomeVo1.getMonthYear());
  1962. LocalDate signingTime = yearMonth.atDay(1);
  1963. settlementDocumentaryFeesVo.setSigningTime(signingTime);
  1964. }
  1965. if (insPlyIncomeVo.getOtherFeevalue().compareTo(BigDecimal.ZERO) == 0) {
  1966. throw new SystemException("总金额为0不允许开票");
  1967. }
  1968. if (insPlyIncomeVo.getNoInvoicCommissionFeevalue().compareTo(BigDecimal.ZERO) == 0) {
  1969. throw new SystemException("未开票金额为0不允许开票");
  1970. }
  1971. if (insPlyIncomeVo.getSettlementAmount() == null || insPlyIncomeVo.getSettlementAmount().compareTo(BigDecimal.ZERO) <= 0) {
  1972. throw new SystemException("开票金额错误不允许开票");
  1973. }
  1974. if (insPlyIncomeVo.getNoInvoicCommissionFeevalue().compareTo(insPlyIncomeVo.getSettlementAmount()) < 0) {
  1975. throw new SystemException("开票金额必须小于未开票金额 不允许开票");
  1976. }
  1977. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1978. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  1979. }
  1980. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  1981. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  1982. }
  1983. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDay())) {
  1984. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  1985. }
  1986. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  1987. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1988. settlementDocumentaryFeesVo.setAgreementId(insPlyIncomeVo.getAgreementId());
  1989. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  1990. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  1991. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  1992. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1993. settlementDocumentaryFeesVo.setSettlementStatus("1");
  1994. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1995. if (StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())) {
  1996. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  1997. }
  1998. if (StringUtils.isNotEmpty(insPlyIncomeVo.getTaskId())) {
  1999. settlementDocumentaryFeesVo.setTaskId(insPlyIncomeVo.getTaskId());
  2000. }
  2001. settlementDocumentaryFeesVo.setAgreementType("2");
  2002. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  2003. settlementDocumentaryFeesVo.setCompletionStatus("0");
  2004. settlementDocumentaryFeesVo.setInvoicedSettledAmount(BigDecimal.ZERO);
  2005. settlementDocumentaryFeesVo.setInvoicedNotSettledAmount(insPlyIncomeVo.getSettlementAmount());
  2006. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  2007. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  2008. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
  2009. // 税点支出
  2010. if ("0".equals(insPlyIncomeVo.getInvoicingMethod()) && BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) != null && insPlyIncomeVo.getTaxPoints().compareTo(BigDecimal.ZERO) != 0 && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) != null) {
  2011. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  2012. settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  2013. } else {
  2014. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount());
  2015. }
  2016. // 跟单生成批次表
  2017. SettlementDocumentaryFeesSumEntity settlementDocumentaryFeesSumEntity = this.saveSumSettlement(insPlyIncomeVo);
  2018. if(ObjectUtils.isNotEmpty(settlementDocumentaryFeesSumEntity)){
  2019. settlementDocumentaryFeesVo.setSettlementSumId(settlementDocumentaryFeesSumEntity.getId());
  2020. }
  2021. return settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  2022. }
  2023. private SettlementDocumentaryFeesSumEntity saveSumSettlement(InsPlyIncomeVo insPlyIncomeVo) {
  2024. String handlingFeesStatus = insPlyIncomeVo.getHandlingFeesStatus();
  2025. SettlementDocumentaryFeesSumEntity settlementDocumentaryFeesSumEntity = new SettlementDocumentaryFeesSumEntity();
  2026. BigDecimal totalAmount = BigDecimal.ZERO;
  2027. if("1".equals(handlingFeesStatus)){
  2028. List<InsPlyIncomeVo> nowInsPlyIncomeVo = insPlyIncomeVo.getMultipleSelection();
  2029. for (InsPlyIncomeVo item: nowInsPlyIncomeVo ){
  2030. totalAmount = totalAmount.add(item.getSettlementAmount()) ;
  2031. }
  2032. settlementDocumentaryFeesSumEntity.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());
  2033. settlementDocumentaryFeesSumEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  2034. settlementDocumentaryFeesSumEntity.setCreateTime(new Date());
  2035. settlementDocumentaryFeesSumEntity.setInvoicId(insPlyIncomeVo.getContractId());
  2036. settlementDocumentaryFeesSumEntity.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod());
  2037. settlementDocumentaryFeesSumEntity.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  2038. settlementDocumentaryFeesSumEntity.setSettlementStatus("1");
  2039. settlementDocumentaryFeesSumEntity.setUserId(BaseController.getUser().getId());
  2040. settlementDocumentaryFeesSumEntity.setInvoicedSettledAmount(BigDecimal.ZERO);
  2041. settlementDocumentaryFeesSumEntity.setCompletionStatus("0");
  2042. settlementDocumentaryFeesSumEntity.setTotalAmount(totalAmount);// 开票总额
  2043. settlementDocumentaryFeesSumEntity.setInvoicedNotSettledAmount(totalAmount);
  2044. settlementDocumentaryFeesSumService.getBaseMapper().insert(settlementDocumentaryFeesSumEntity);
  2045. return settlementDocumentaryFeesSumEntity;
  2046. }
  2047. return settlementDocumentaryFeesSumEntity;
  2048. }
  2049. @Override
  2050. public HttpResult pinHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  2051. HashMap<String, Object> params = new HashMap<>();
  2052. params = this.saveParams(insPlyIncomeVo, params);
  2053. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  2054. ExportParams exportParams = new ExportParams("平台手续费", null, ExcelType.HSSF);
  2055. exportParams.setStyle(ExcelStyleUtil.class);
  2056. List<SettlementFeesExcel> resultList = new ArrayList<>();
  2057. for (InsPlyIncome item : insPlyIncomes) {
  2058. SettlementFeesExcel bxSettlementFeesExcel = new SettlementFeesExcel();
  2059. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  2060. if ("1".equals(item.getHandlingFeesStatus())) {
  2061. bxSettlementFeesExcel.setHandlingFeesStatus("已结算");
  2062. } else {
  2063. bxSettlementFeesExcel.setHandlingFeesStatus("未结算");
  2064. }
  2065. resultList.add(bxSettlementFeesExcel);
  2066. }
  2067. String uploadPath = this.uploadPath + "/excel/";
  2068. Path path = Paths.get(uploadPath);
  2069. if (!Files.exists(path)) {
  2070. try {
  2071. Files.createDirectories(path);
  2072. } catch (IOException e) {
  2073. e.printStackTrace();
  2074. }
  2075. }
  2076. String fileName = EasyExcelUtils.downExcel(uploadPath, "平台手续费导出", SettlementFeesExcel.class, resultList);
  2077. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  2078. }
  2079. @Override
  2080. public HttpResult bxHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  2081. HashMap<String, Object> params = new HashMap<>();
  2082. params = this.saveParams(insPlyIncomeVo, params);
  2083. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  2084. String filePathName = "";
  2085. List<BxSettlementFeesNorExcel> resultNoList = new ArrayList<>();
  2086. List<BxSettlementFeesExcel> resultList = new ArrayList<>();
  2087. //判断是否是非车 1 是非车
  2088. if ("1".equals(insPlyIncomeVo.getIsNotCar())) {
  2089. filePathName = "非车手续费导出";
  2090. ExportParams exportParams = new ExportParams("非车手续费", null, ExcelType.HSSF);
  2091. exportParams.setStyle(ExcelStyleUtil.class);
  2092. for (InsPlyIncome item : insPlyIncomes) {
  2093. BxSettlementFeesNorExcel bxSettlementFeesNorExcel = new BxSettlementFeesNorExcel();
  2094. LocalDateTime signDate = item.getSignDate();
  2095. BeanUtils.copyProperties(item, bxSettlementFeesNorExcel);
  2096. bxSettlementFeesNorExcel.setSigndate(signDate);
  2097. resultNoList.add(bxSettlementFeesNorExcel);
  2098. }
  2099. } else {
  2100. filePathName = "车险手续费导出";
  2101. ExportParams exportParams = new ExportParams("车险手续费", null, ExcelType.HSSF);
  2102. exportParams.setStyle(ExcelStyleUtil.class);
  2103. for (InsPlyIncome item : insPlyIncomes) {
  2104. BxSettlementFeesExcel bxSettlementFeesExcel = new BxSettlementFeesExcel();
  2105. LocalDateTime signDate = item.getSignDate();
  2106. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  2107. bxSettlementFeesExcel.setSigndate(signDate);
  2108. resultList.add(bxSettlementFeesExcel);
  2109. }
  2110. }
  2111. String uploadPath = this.uploadPath + "/excel/";
  2112. Path path = Paths.get(uploadPath);
  2113. if (!Files.exists(path)) {
  2114. try {
  2115. Files.createDirectories(path);
  2116. } catch (IOException e) {
  2117. e.printStackTrace();
  2118. }
  2119. }
  2120. String fileName = "";
  2121. if ("1".equals(insPlyIncomeVo.getIsNotCar())) {
  2122. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxSettlementFeesNorExcel.class, resultNoList);
  2123. } else {
  2124. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxSettlementFeesExcel.class, resultList);
  2125. }
  2126. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  2127. }
  2128. @Override
  2129. public HttpResult bxOtherExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  2130. HashMap<String, Object> params = new HashMap<>();
  2131. params = this.saveParams(insPlyIncomeVo, params);
  2132. params.put("agreementType", "2");
  2133. params.put("isOther", "1");
  2134. params.put("isNotCar", "0");
  2135. List<InsPlyIncome> insPlyIncomes = baseMapper.allOtherAmount(params);
  2136. ExportParams exportParams = new ExportParams("跟单费导出", null, ExcelType.HSSF);
  2137. exportParams.setStyle(ExcelStyleUtil.class);
  2138. List<BxOtherExcel> resultList = new ArrayList<>();
  2139. for (InsPlyIncome item : insPlyIncomes) {
  2140. BxOtherExcel bxSettlementFeesExcel = new BxOtherExcel();
  2141. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  2142. resultList.add(bxSettlementFeesExcel);
  2143. }
  2144. String uploadPath = this.uploadPath + "/excel/";
  2145. Path path = Paths.get(uploadPath);
  2146. if (!Files.exists(path)) {
  2147. try {
  2148. Files.createDirectories(path);
  2149. } catch (IOException e) {
  2150. e.printStackTrace();
  2151. }
  2152. }
  2153. String fileName = EasyExcelUtils.downExcel(uploadPath, "跟单费导出", BxOtherExcel.class, resultList);
  2154. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  2155. }
  2156. @Override
  2157. public InsPlyIncome bxTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  2158. InsPlyIncome insPlyIncome = new InsPlyIncome();
  2159. HashMap<String, Object> params = new HashMap<>();
  2160. params = this.saveParams(insPlyIncomeVo, params);
  2161. BigDecimal sumCommissionFeevalue = BigDecimal.ZERO; //总金额
  2162. BigDecimal sumInvoicCommissionFeevalue = BigDecimal.ZERO; //开票未结算
  2163. BigDecimal sumReadyCommissionFeevalue = BigDecimal.ZERO; // 已开票已结算
  2164. BigDecimal sumNoInvoicCommissionFeevalue = BigDecimal.ZERO; //未开票金额
  2165. BigDecimal sumUnSettledAmount = BigDecimal.ZERO; //未结算金额
  2166. BigDecimal sumAllInvoicCommissionFeevalue = BigDecimal.ZERO; //总开票
  2167. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  2168. for (InsPlyIncome item : resultList) {
  2169. BigDecimal commissionFeevalue = BigDecimal.ZERO; //总金额
  2170. BigDecimal invoicCommissionFeevalue = BigDecimal.ZERO; //开票未结算
  2171. BigDecimal readyCommissionFeevalue = BigDecimal.ZERO; // 已开票已结算
  2172. BigDecimal noInvoicCommissionFeevalue = BigDecimal.ZERO; //未开票金额
  2173. BigDecimal unSettledAmount; //未结算金额
  2174. params.put("partnerCompaniesId", item.getPartnerCompaniesId());
  2175. params.remove("handlingFeesStatus");
  2176. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params); //金额总数
  2177. for (InsPlyIncome all : insPlyIncomes) {
  2178. if(ObjectUtils.isNotEmpty(all)){
  2179. commissionFeevalue = commissionFeevalue.add(all.getCommissionFeevalue());
  2180. }
  2181. }
  2182. //已开票金额 = 开票未结算+ 开票已结算
  2183. params.put("handlingFeesStatus", "0"); // 开票
  2184. params.put("settlementStatus", "1"); // 开票
  2185. List<SettlementDocumentaryFeesEntity> invoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  2186. for (SettlementDocumentaryFeesEntity invoicInsPlyIncome : invoicInsPlyIncomes) {
  2187. BigDecimal invoicIcommissionFeevalue = invoicInsPlyIncome.getSettlementAmount();// 已经开票金额
  2188. invoicCommissionFeevalue = invoicCommissionFeevalue.add(invoicIcommissionFeevalue); //开票金额
  2189. }
  2190. params.put("settlementStatus", "2"); // 结算
  2191. List<SettlementDocumentaryFeesEntity> settleInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  2192. for (SettlementDocumentaryFeesEntity settleInsPlyIncome : settleInsPlyIncomes) {
  2193. BigDecimal settleIcommissionFeevalue = settleInsPlyIncome.getSettlementAmount();// 已结算金额
  2194. readyCommissionFeevalue = readyCommissionFeevalue.add(settleIcommissionFeevalue); //已结算总
  2195. }
  2196. params.put("settlementStatus", 0); //未开票金额
  2197. List<SettlementDocumentaryFeesEntity> noInvoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  2198. for (SettlementDocumentaryFeesEntity noInvoicInsPlyIncome : noInvoicInsPlyIncomes) {
  2199. BigDecimal noInvoicIcommissionFeevalue = noInvoicInsPlyIncome.getSettlementAmount();// 未开票金额
  2200. noInvoicCommissionFeevalue = noInvoicCommissionFeevalue.add(noInvoicIcommissionFeevalue); //未开票总金额
  2201. }
  2202. noInvoicCommissionFeevalue = commissionFeevalue.subtract(invoicCommissionFeevalue);// 未开票
  2203. unSettledAmount = commissionFeevalue.subtract(readyCommissionFeevalue); //未结算
  2204. //已开票金额
  2205. item.setCommissionFeevalue(commissionFeevalue); //总手续费
  2206. item.setAllInvoicCommissionFeevalue(invoicCommissionFeevalue); //总开票金额
  2207. // 开票未结算 = 开票金额 - 已开票已结算
  2208. invoicCommissionFeevalue = invoicCommissionFeevalue.subtract(readyCommissionFeevalue);
  2209. item.setInvoicCommissionFeevalue(invoicCommissionFeevalue); //开票未结算
  2210. item.setReadyCommissionFeevalue(readyCommissionFeevalue); //已开票已结算
  2211. item.setNoInvoicCommissionFeevalue(noInvoicCommissionFeevalue); //未开票金额
  2212. item.setUnSettledAmount(unSettledAmount); // 未结算金额
  2213. sumCommissionFeevalue = sumCommissionFeevalue.add(item.getCommissionFeevalue());
  2214. sumInvoicCommissionFeevalue = sumInvoicCommissionFeevalue.add(item.getInvoicCommissionFeevalue());
  2215. sumReadyCommissionFeevalue = sumReadyCommissionFeevalue.add(item.getReadyCommissionFeevalue());
  2216. sumNoInvoicCommissionFeevalue = sumNoInvoicCommissionFeevalue.add(item.getNoInvoicCommissionFeevalue());
  2217. sumUnSettledAmount = sumUnSettledAmount.add(item.getUnSettledAmount());
  2218. sumAllInvoicCommissionFeevalue = sumAllInvoicCommissionFeevalue.add(item.getAllInvoicCommissionFeevalue());
  2219. }
  2220. if(sumCommissionFeevalue.compareTo(sumReadyCommissionFeevalue) <0){
  2221. sumAllInvoicCommissionFeevalue=sumCommissionFeevalue;
  2222. sumReadyCommissionFeevalue=sumCommissionFeevalue;
  2223. sumNoInvoicCommissionFeevalue =sumCommissionFeevalue.subtract(sumAllInvoicCommissionFeevalue);
  2224. sumUnSettledAmount=sumAllInvoicCommissionFeevalue.subtract(sumReadyCommissionFeevalue);
  2225. }
  2226. insPlyIncome.setCommissionFeevalue(sumCommissionFeevalue);
  2227. insPlyIncome.setInvoicCommissionFeevalue(sumInvoicCommissionFeevalue);
  2228. insPlyIncome.setReadyCommissionFeevalue(sumReadyCommissionFeevalue);
  2229. insPlyIncome.setNoInvoicCommissionFeevalue(sumNoInvoicCommissionFeevalue);
  2230. insPlyIncome.setAllInvoicCommissionFeevalue(sumAllInvoicCommissionFeevalue);
  2231. insPlyIncome.setUnSettledAmount(sumUnSettledAmount);
  2232. return insPlyIncome;
  2233. }
  2234. @Override
  2235. public InsPlyIncome ptTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  2236. HashMap<String, Object> params = new HashMap<>();
  2237. params = this.saveParams(insPlyIncomeVo, params);
  2238. InsPlyIncome totalledAmount = baseMapper.ptTotalAmount(params); //总金额
  2239. return totalledAmount;
  2240. }
  2241. @Override
  2242. public HttpResult<List<HashMap<String, Object>>> otherTimeDetail(InsPlyIncomeVo insPlyIncomeVo) {
  2243. HashMap<String, Object> params = new HashMap<>();
  2244. this.saveParams(insPlyIncomeVo, params);
  2245. List<HashMap<String, Object>> resultMap = baseMapper.otherTimeDetail(params);
  2246. Set<String> uniqueYears = new HashSet<>();
  2247. for (Map<String, Object> map : resultMap) {
  2248. // 假设年份是以 "year" 为键的,并且它的值是 String 类型
  2249. String year = String.valueOf(map.get("year"));
  2250. if (year != null) { // 确保年份不是 null
  2251. uniqueYears.add(year);
  2252. }
  2253. }
  2254. this.addMonthYear(uniqueYears, resultMap);
  2255. return HttpResult.ok(resultMap);
  2256. }
  2257. /**
  2258. * uniqueYears 年份间隔 resultMap 返回结果
  2259. *
  2260. * @param uniqueYears
  2261. * @param resultMap 返回一到十二月数据
  2262. */
  2263. private void addMonthYear(Set<String> uniqueYears, List<HashMap<String, Object>> resultMap) {
  2264. // 存储已存在的年份-月份组合,以便快速查找
  2265. Set<String> existingYearMonths = new HashSet<>();
  2266. for (Map<String, Object> entry : resultMap) {
  2267. String monthYear = String.valueOf(entry.get("monthYear"));
  2268. existingYearMonths.add(monthYear);
  2269. }
  2270. // 遍历所有年份和月份,并添加缺失的条目
  2271. for (String year : uniqueYears) {
  2272. for (int month = 1; month <= 12; month++) {
  2273. String strNumber = String.valueOf(month);
  2274. if (strNumber.length() < 2) {
  2275. strNumber = String.format("%02d", Integer.parseInt(strNumber));
  2276. }
  2277. String yearMonth = year + "-" + strNumber;
  2278. if (!existingYearMonths.contains(yearMonth)) {
  2279. // 创建一个新的条目并添加到resultMap中
  2280. HashMap<String, Object> newEntry = new HashMap<>();
  2281. newEntry.put("year", year);
  2282. newEntry.put("monthNumber", strNumber);
  2283. newEntry.put("allTotalOtherFeevalue", 0);
  2284. newEntry.put("invoicCommissionFeevalue", 0);
  2285. newEntry.put("monthYear", yearMonth);
  2286. newEntry.put("noInvoicCommissionFeevalue", 0);
  2287. resultMap.add(newEntry);
  2288. }
  2289. }
  2290. }
  2291. // 使用自定义Comparator对resultMap进行排序
  2292. Collections.sort(resultMap, new Comparator<HashMap<String, Object>>() {
  2293. @Override
  2294. public int compare(HashMap<String, Object> o1, HashMap<String, Object> o2) {
  2295. // 比较 year
  2296. String year1 = String.valueOf(o1.get("year"));
  2297. String year2 = String.valueOf(o2.get("year"));
  2298. int yearComparison = year1.compareTo(year2);
  2299. if (yearComparison != 0) {
  2300. return yearComparison;
  2301. }
  2302. // 如果 year 相同,则比较 monthNumber
  2303. Integer monthNum1 = Integer.parseInt(String.format("%2s", o1.get("monthNumber")).replaceAll(" ", "0"));
  2304. Integer monthNum2 = Integer.parseInt(String.format("%2s", o2.get("monthNumber")).replaceAll(" ", "0"));
  2305. return monthNum1.compareTo(monthNum2);
  2306. }
  2307. });
  2308. }
  2309. @Override
  2310. @Transactional
  2311. public HttpResult<Object> singleInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  2312. // 通过ids 查出跟单非结算单
  2313. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  2314. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getMultipleSelection())) {
  2315. SettlementDocumentaryFeesSumEntity settlementDocumentaryFeesSumEntity = this.saveSumSettlement(insPlyIncomeVo);
  2316. for (InsPlyIncomeVo insPlyIncomeVo1 : insPlyIncomeVo.getMultipleSelection()) {
  2317. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo1.getSettlementAmount());
  2318. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo1.getAllTotalOtherFeevalue());
  2319. YearMonth yearMonth = YearMonth.parse(insPlyIncomeVo1.getMonthYear());
  2320. LocalDate signingTime = yearMonth.atDay(1);
  2321. settlementDocumentaryFeesVo.setSigningTime(signingTime);
  2322. if (insPlyIncomeVo.getOtherFeevalue().compareTo(BigDecimal.ZERO) == 0) {
  2323. throw new SystemException("总金额为0不允许开票");
  2324. }
  2325. if (insPlyIncomeVo.getNoInvoicCommissionFeevalue().compareTo(BigDecimal.ZERO) == 0) {
  2326. throw new SystemException("未开票金额为0不允许开票");
  2327. }
  2328. if (insPlyIncomeVo.getSettlementAmount() == null || insPlyIncomeVo.getSettlementAmount().compareTo(BigDecimal.ZERO) <= 0) {
  2329. throw new SystemException("开票金额错误不允许开票");
  2330. }
  2331. if (insPlyIncomeVo.getNoInvoicCommissionFeevalue().compareTo(insPlyIncomeVo.getSettlementAmount()) < 0) {
  2332. throw new SystemException("开票金额必须小于未开票金额 不允许开票");
  2333. }
  2334. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  2335. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  2336. }
  2337. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  2338. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  2339. }
  2340. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  2341. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  2342. }
  2343. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDay())) {
  2344. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  2345. }
  2346. settlementDocumentaryFeesVo.setCompletionStatus("0");
  2347. settlementDocumentaryFeesVo.setInvoicedSettledAmount(BigDecimal.ZERO);
  2348. settlementDocumentaryFeesVo.setInvoicedNotSettledAmount(insPlyIncomeVo.getSettlementAmount());
  2349. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  2350. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  2351. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  2352. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  2353. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  2354. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  2355. settlementDocumentaryFeesVo.setAgreementType("2");
  2356. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIncomeIds());
  2357. settlementDocumentaryFeesVo.setSettlementStatus("1");
  2358. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  2359. if (StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())) {
  2360. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  2361. }
  2362. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  2363. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  2364. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  2365. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
  2366. // settlementDocumentaryFeesVo.setSigningTime(insPlyIncomeVo.getSettlementTime()); //签单日期
  2367. // 税点支出
  2368. if (BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) != null && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) != null) {
  2369. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  2370. settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  2371. }
  2372. if(ObjectUtils.isNotEmpty(settlementDocumentaryFeesSumEntity)){
  2373. settlementDocumentaryFeesVo.setSettlementSumId(settlementDocumentaryFeesSumEntity.getId());
  2374. }
  2375. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  2376. }
  2377. }
  2378. return HttpResult.ok();
  2379. }
  2380. @Override
  2381. public void batchUpdate(InsPlyIncomeVo insPlyIncomeVo) {
  2382. HashMap<String, Object> params = new HashMap<>();
  2383. params = this.saveParams(insPlyIncomeVo, params);
  2384. List<InsPlyIncome> list = this.baseMapper.queryNew(params);
  2385. for (InsPlyIncome item : list) {
  2386. item.setContractFileId(insPlyIncomeVo.getContractFileId());
  2387. item.setSettleOtherStatus("1");
  2388. baseMapper.updateById(item);
  2389. }
  2390. }
  2391. @Override
  2392. @Transactional
  2393. public HashMap<String, Object> bxImportOther(MultipartFile multipartFile, String isNotCar) {
  2394. HashMap<String, Object> resultMap = new HashMap<>();
  2395. List<HashMap<String, Object>> resultList = new ArrayList<>();
  2396. HashMap<String, Object> params = new HashMap<>();
  2397. BigDecimal allAmount = BigDecimal.ZERO;
  2398. params.put("isNotCar", isNotCar);
  2399. try {
  2400. List<InsBxOtherExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxOtherExcelDto.class, 0, 1, 1);
  2401. for (InsBxOtherExcelDto item : dtoList) {
  2402. if (StringUtils.isNotEmpty(item.getLicenseno())) {
  2403. params.put("licenseno", item.getLicenseno());
  2404. }
  2405. if (StringUtils.isNotEmpty(item.getPolicyno())) {
  2406. params.put("policyno", item.getPolicyno());
  2407. }
  2408. if (StringUtils.isNotEmpty(item.getSyPolicyno())) {
  2409. params.put("syPolicyno", item.getSyPolicyno());
  2410. }
  2411. params.put("handlingFeesStatus", "0");
  2412. // isOther
  2413. params.put("isOther", "1");
  2414. params.put("isNotCar", "0");
  2415. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  2416. if (item.getJqOtherCostsProportion() == null) {
  2417. item.setJqOtherCostsProportion(BigDecimal.ZERO);
  2418. }
  2419. if (item.getSyOtherCostsProportion() == null) {
  2420. item.setSyOtherCostsProportion(BigDecimal.ZERO);
  2421. }
  2422. if (ObjectUtils.isNotEmpty(byBxLicenseno) && (byBxLicenseno.getJqOtherCostsProportion().compareTo(item.getJqOtherCostsProportion()) != 0 || byBxLicenseno.getSyOtherCostsProportion().compareTo(item.getSyOtherCostsProportion()) != 0)) {
  2423. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  2424. BeanUtils.copyProperties(byBxLicenseno,insPlyIncomeLog);
  2425. insPlyIncomeLog.setOperationStatus("2");
  2426. insPlyIncomeLog.setId(null);
  2427. insPlyIncomeLog.setIncomeId(byBxLicenseno.getId());
  2428. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  2429. // 如果比例不相等
  2430. BigDecimal jqOtherCostsProportion = item.getJqOtherCostsProportion();
  2431. BigDecimal syOtherCostsProportion = item.getSyOtherCostsProportion();
  2432. BigDecimal jqOtherAmount = getBigDecimal( byBxLicenseno.getJqPremium(),item.getJqOtherCostsProportion());
  2433. BigDecimal syOtherAmount = getBigDecimal( byBxLicenseno.getSyPremium(),item.getSyOtherCostsProportion());
  2434. byBxLicenseno.setJqOtherCostsPremium(jqOtherAmount);
  2435. byBxLicenseno.setSyOtherCostsPremium(syOtherAmount);
  2436. byBxLicenseno.setJqOtherCostsProportion(jqOtherCostsProportion);
  2437. byBxLicenseno.setSyOtherCostsProportion(syOtherCostsProportion);
  2438. byBxLicenseno.setOtherFeevalue(this.calculateTotal(jqOtherAmount, syOtherAmount, null));
  2439. byBxLicenseno.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion, syOtherCostsProportion, null));
  2440. byBxLicenseno.setAllFeeValue(this.calculateTotal(jqOtherAmount, syOtherAmount, null));
  2441. byBxLicenseno.setUpdateUserId(BaseController.getUser().getId());
  2442. byBxLicenseno.setUpdateUserName(BaseController.getUser().getName());
  2443. baseMapper.updateById(byBxLicenseno);
  2444. HashMap<String, Object> map = new HashMap<>();
  2445. map.put("licenseno", item.getLicenseno());
  2446. map.put("policyno", item.getPolicyno());
  2447. map.put("syPolicyno", item.getSyPolicyno());
  2448. map.put("jqOtherCostsPremium", jqOtherAmount);
  2449. map.put("syOtherCostsPremium", syOtherAmount);
  2450. map.put("jqOtherCostsProportion", jqOtherCostsProportion);
  2451. map.put("syOtherCostsProportion", syOtherCostsProportion);
  2452. map.put("otherFeevalue", byBxLicenseno.getOtherFeevalue());
  2453. map.put("otherFeerate", byBxLicenseno.getOtherFeerate());
  2454. resultList.add(map);
  2455. allAmount = allAmount.add(jqOtherAmount).add(syOtherAmount);
  2456. }
  2457. }
  2458. resultMap.put("allAmount", allAmount);
  2459. resultMap.put("resultList", resultList);
  2460. } catch (IOException e) {
  2461. throw new RuntimeException(e);
  2462. }
  2463. return resultMap;
  2464. }
  2465. @Override
  2466. public HashMap<String, Object> ptImportOther(MultipartFile multipartFile) {
  2467. HashMap<String, Object> resultMap = new HashMap<>();
  2468. List<HashMap<String, Object>> resultList = new ArrayList<>();
  2469. HashMap<String, Object> params = new HashMap<>();
  2470. BigDecimal allAmount = BigDecimal.ZERO;
  2471. try {
  2472. List<InsPtHandExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsPtHandExcelDto.class, 0, 1, 1);
  2473. for (InsPtHandExcelDto item : dtoList) {
  2474. if (StringUtils.isNotEmpty(item.getLicenseno())) {
  2475. params.put("licenseno", item.getLicenseno());
  2476. }
  2477. if (StringUtils.isNotEmpty(item.getPolicyno())) {
  2478. params.put("policyno", item.getPolicyno());
  2479. }
  2480. if (StringUtils.isNotEmpty(item.getSyPolicyno())) {
  2481. params.put("syPolicyno", item.getSyPolicyno());
  2482. }
  2483. if (StringUtils.isNotEmpty(item.getNoPolicyno())) {
  2484. params.put("noPolicyno", item.getNoPolicyno());
  2485. }
  2486. params.put("handlingFeesStatus", "0");
  2487. // isOther
  2488. params.put("isOther", "0");
  2489. params.put("isNotCar", "0");
  2490. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  2491. if (item.getNoOtherCostsProportion() == null) {
  2492. item.setNoOtherCostsProportion(BigDecimal.ZERO);
  2493. }
  2494. if (item.getJqOtherCostsProportion() == null) {
  2495. item.setJqOtherCostsProportion(BigDecimal.ZERO);
  2496. }
  2497. if (item.getSyOtherCostsProportion() == null) {
  2498. item.setSyOtherCostsProportion(BigDecimal.ZERO);
  2499. }
  2500. if (item.getJqSuperviseCostsProportion() == null) {
  2501. item.setJqSuperviseCostsProportion(BigDecimal.ZERO);
  2502. }
  2503. if (item.getSySuperviseCostsProportion() == null) {
  2504. item.setSySuperviseCostsProportion(BigDecimal.ZERO);
  2505. }
  2506. if (item.getNoSuperviseCostsProportion() == null) {
  2507. item.setNoSuperviseCostsProportion(BigDecimal.ZERO);
  2508. }
  2509. if (ObjectUtils.isNotEmpty(byBxLicenseno) && (byBxLicenseno.getJqOtherCostsProportion().compareTo(item.getJqOtherCostsProportion()) != 0 || byBxLicenseno.getSyOtherCostsProportion().compareTo(item.getSyOtherCostsProportion()) != 0)) {
  2510. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  2511. BeanUtils.copyProperties(byBxLicenseno,insPlyIncomeLog);
  2512. insPlyIncomeLog.setOperationStatus("2");
  2513. insPlyIncomeLog.setId(null);
  2514. insPlyIncomeLog.setIncomeId(byBxLicenseno.getId());
  2515. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  2516. // 如果比例不相等
  2517. BigDecimal jqOtherCostsProportion = item.getJqOtherCostsProportion();
  2518. BigDecimal syOtherCostsProportion = item.getSyOtherCostsProportion();
  2519. BigDecimal noOtherCostsProportion = item.getNoOtherCostsProportion();
  2520. BigDecimal jqSuperviseCostsProportion = item.getJqSuperviseCostsProportion();
  2521. BigDecimal sySuperviseCostsProportion = item.getSySuperviseCostsProportion();
  2522. BigDecimal noSuperviseCostsProportion = item.getNoSuperviseCostsProportion();
  2523. BigDecimal jqOtherAmount = algorithmAmount( byBxLicenseno.getJqPremium(),jqOtherCostsProportion);
  2524. BigDecimal syOtherAmount = algorithmAmount( byBxLicenseno.getSyPremium(),syOtherCostsProportion);
  2525. BigDecimal noOtherAmount = algorithmAmount( byBxLicenseno.getNoPremium(),noOtherCostsProportion);
  2526. BigDecimal jqSuperviseCostsAmount = algorithmAmount( byBxLicenseno.getJqPremium(),jqSuperviseCostsProportion);
  2527. BigDecimal sySuperviseCostsAmount = algorithmAmount( byBxLicenseno.getSyPremium(),sySuperviseCostsProportion);
  2528. BigDecimal noSuperviseCostsAmount = algorithmAmount( byBxLicenseno.getNoPremium(),noSuperviseCostsProportion);
  2529. byBxLicenseno.setJqOtherCostsPremium(jqOtherAmount);
  2530. byBxLicenseno.setSyOtherCostsPremium(syOtherAmount);
  2531. byBxLicenseno.setNoOtherCostsPremium(noOtherAmount);
  2532. byBxLicenseno.setJqSuperviseCostsPremiums(jqSuperviseCostsAmount);
  2533. byBxLicenseno.setSySuperviseCostsPremiums(sySuperviseCostsAmount);
  2534. byBxLicenseno.setNoSuperviseCostsPremiums(noSuperviseCostsAmount);
  2535. byBxLicenseno.setJqOtherCostsProportion(jqOtherCostsProportion);
  2536. byBxLicenseno.setSyOtherCostsProportion(syOtherCostsProportion);
  2537. byBxLicenseno.setNoOtherCostsProportion(noOtherCostsProportion);
  2538. byBxLicenseno.setJqSuperviseCostsProportion(jqSuperviseCostsProportion);
  2539. byBxLicenseno.setSySuperviseCostsProportion(sySuperviseCostsProportion);
  2540. byBxLicenseno.setNoSuperviseCostsProportion(noSuperviseCostsProportion);
  2541. byBxLicenseno.setOtherFeevalue(this.calculateTotal(jqOtherAmount, syOtherAmount, noOtherAmount));
  2542. byBxLicenseno.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion, syOtherCostsProportion, noOtherCostsProportion));
  2543. byBxLicenseno.setCommissionFeevalue(this.calculateTotal(jqSuperviseCostsAmount, sySuperviseCostsAmount, noSuperviseCostsAmount));
  2544. byBxLicenseno.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion,sySuperviseCostsProportion,noSuperviseCostsProportion));
  2545. byBxLicenseno.setAllFeeValue(this.calculateTotal(byBxLicenseno.getOtherFeevalue(),byBxLicenseno.getCommissionFeevalue(),null));
  2546. byBxLicenseno.setJqReceivableProportion(this.calculateTotal(jqSuperviseCostsProportion,jqOtherCostsProportion,null));
  2547. byBxLicenseno.setSyReceivableProportion(this.calculateTotal(sySuperviseCostsProportion,syOtherCostsProportion,null));
  2548. byBxLicenseno.setNoReceivableProportion(this.calculateTotal(noSuperviseCostsProportion,noOtherCostsProportion,null));
  2549. byBxLicenseno.setUpdateUserId(BaseController.getUser().getId());
  2550. byBxLicenseno.setUpdateUserName(BaseController.getUser().getName());
  2551. baseMapper.updateById(byBxLicenseno);
  2552. HashMap<String, Object> map = new HashMap<>();
  2553. map.put("licenseno", item.getLicenseno());
  2554. map.put("policyno", item.getPolicyno());
  2555. map.put("syPolicyno", item.getSyPolicyno());
  2556. map.put("noPolicyno", item.getNoPolicyno());
  2557. map.put("jqOtherCostsPremium", jqOtherAmount);
  2558. map.put("syOtherCostsPremium", syOtherAmount);
  2559. map.put("noOtherCostsPremium", noOtherAmount);
  2560. map.put("jqSuperviseCostsPremiums", jqSuperviseCostsAmount);
  2561. map.put("sySuperviseCostsPremiums", sySuperviseCostsAmount);
  2562. map.put("noSuperviseCostsPremiums", noSuperviseCostsAmount);
  2563. map.put("jqOtherCostsProportion", jqOtherCostsProportion);
  2564. map.put("syOtherCostsProportion", syOtherCostsProportion);
  2565. map.put("noOtherCostsProportion", noOtherCostsProportion);
  2566. map.put("jqSuperviseCostsProportion", jqSuperviseCostsProportion);
  2567. map.put("sySuperviseCostsProportion", sySuperviseCostsProportion);
  2568. map.put("noSuperviseCostsProportion", noSuperviseCostsProportion);
  2569. map.put("otherFeevalue", byBxLicenseno.getOtherFeevalue());
  2570. map.put("otherFeerate", byBxLicenseno.getOtherFeerate());
  2571. resultList.add(map);
  2572. allAmount = allAmount.add(jqOtherAmount).add(syOtherAmount).add(noOtherAmount);
  2573. }
  2574. }
  2575. resultMap.put("allAmount", allAmount);
  2576. resultMap.put("resultList", resultList);
  2577. } catch (IOException e) {
  2578. throw new RuntimeException(e);
  2579. }
  2580. return resultMap;
  2581. }
  2582. @Override
  2583. @Transactional
  2584. public HashMap<String, Object> noBxImportOther(MultipartFile multipartFile, String isNotCar) {
  2585. HashMap<String, Object> resultMap = new HashMap<>();
  2586. List<HashMap<String, Object>> resultList = new ArrayList<>();
  2587. HashMap<String, Object> params = new HashMap<>();
  2588. BigDecimal allAmount = BigDecimal.ZERO;
  2589. params.put("isNotCar", isNotCar);
  2590. try {
  2591. List<InsNoBxOtherExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsNoBxOtherExcelDto.class, 0, 1, 1);
  2592. for (InsNoBxOtherExcelDto item : dtoList) {
  2593. if (StringUtils.isNotEmpty(item.getLicenseno())) {
  2594. params.put("licenseno", item.getLicenseno());
  2595. }
  2596. if (StringUtils.isNotEmpty(item.getNoPolicyno())) {
  2597. params.put("noPolicyno", item.getNoPolicyno());
  2598. }
  2599. params.put("handlingFeesStatus", "0");
  2600. params.put("isNotCar", "1");
  2601. params.put("isOther", "1");
  2602. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  2603. if (ObjectUtils.isNotEmpty(byBxLicenseno) && byBxLicenseno.getNoOtherCostsProportion().compareTo(item.getNoOtherCostsProportion()) != 0) {
  2604. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  2605. insPlyIncomeLog.setIncomeId(byBxLicenseno.getId());
  2606. BeanUtils.copyProperties(byBxLicenseno,insPlyIncomeLog);
  2607. insPlyIncomeLog.setOperationStatus("2");
  2608. insPlyIncomeLog.setId(null);
  2609. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  2610. HashMap<String, Object> newMap = new HashMap<>();
  2611. // 如果比例不相等
  2612. BigDecimal noOtherCostsProportion = item.getNoOtherCostsProportion();
  2613. BigDecimal noNoTaxPremium = byBxLicenseno.getNoPremium();
  2614. BigDecimal divisor = new BigDecimal("1.06"); // 最好是使用字符串来避免精度损失
  2615. BigDecimal noOtherAmount = getBigDecimal( noNoTaxPremium,item.getNoOtherCostsProportion());
  2616. byBxLicenseno.setNoOtherCostsPremium(noOtherAmount);
  2617. byBxLicenseno.setNoOtherCostsProportion(item.getNoOtherCostsProportion());
  2618. byBxLicenseno.setAllFeeValue(this.calculateTotal(noOtherAmount, null, null));
  2619. byBxLicenseno.setOtherFeevalue(this.calculateTotal(noOtherAmount, null, null));
  2620. byBxLicenseno.setOtherFeerate(this.calculateTotal(noOtherCostsProportion, null, null));
  2621. baseMapper.updateById(byBxLicenseno);
  2622. newMap.put("licenseno", item.getLicenseno());
  2623. newMap.put("noPolicyno", item.getNoPolicyno());
  2624. newMap.put("noOtherCostsPremium", noOtherAmount);
  2625. newMap.put("otherFeevalue", byBxLicenseno.getOtherFeevalue());
  2626. newMap.put("otherFeerate", byBxLicenseno.getOtherFeerate());
  2627. resultList.add(newMap);
  2628. allAmount = allAmount.add(noOtherAmount);
  2629. }
  2630. }
  2631. resultMap.put("allAmount", allAmount);
  2632. resultMap.put("resultList", resultList);
  2633. } catch (IOException e) {
  2634. throw new RuntimeException(e);
  2635. }
  2636. return resultMap;
  2637. }
  2638. @Override
  2639. public void batchUpdateVoucher(InsPlyIncomeVo insPlyIncomeVo) {
  2640. String s = insPlyIncomeVo.getSelectIds().get(0);
  2641. ImportResult importResult = importAsyncService.getById(s);
  2642. String[] split = importResult.getIds().split(",");
  2643. InsPlyIncome insPlyIncome = new InsPlyIncome();
  2644. for (String id : split) {
  2645. insPlyIncome.setId(id);
  2646. insPlyIncome.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  2647. insPlyIncome.setSettleOtherStatus("1");
  2648. baseMapper.updateById(insPlyIncome);
  2649. }
  2650. }
  2651. /**
  2652. * 通过任务id 去查询关联表
  2653. *
  2654. * @param insPlyIncomeVo
  2655. * @return
  2656. */
  2657. @Override
  2658. public HttpResult<Object> reconciliation(InsPlyIncomeVo insPlyIncomeVo) {
  2659. String taskId = insPlyIncomeVo.getTaskId();
  2660. List<String> incomeIdList = incomeTaskRelationshipService.getByTaskId(taskId);
  2661. for (String incomeId : incomeIdList) {
  2662. InsPlyIncome insPlyIncome = baseMapper.getById(incomeId);
  2663. insPlyIncome.setSettleOtherStatus("1");
  2664. insPlyIncome.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  2665. baseMapper.updateById(insPlyIncome);
  2666. }
  2667. return HttpResult.ok();
  2668. }
  2669. /**
  2670. * @version
  2671. * @author: hxl
  2672. * @Date: 2024/6/18 10:14
  2673. * @Description: 通过保险公司id和状态查询平台的记录
  2674. */
  2675. @Override
  2676. public List<PlatformSettlementRecordDto> platformSettlementRecord(InsPlyIncomeVo insPlyIncomeVo) {
  2677. if(insPlyIncomeVo.getPartnerCompaniesId()==null || "".equals(insPlyIncomeVo.getPartnerCompaniesId())){
  2678. throw new SystemException("合作公司编码(partnerCompaniesId)不能为空");
  2679. }
  2680. if(insPlyIncomeVo.getHandlingFeesStatus()==null || "".equals(insPlyIncomeVo.getHandlingFeesStatus())){
  2681. throw new SystemException("结算状态 0 未结算 1已结算(handlingFeesStatus)不能为空");
  2682. }
  2683. return baseMapper.platformSettlementRecord(insPlyIncomeVo.getPartnerCompaniesId(),insPlyIncomeVo.getHandlingFeesStatus());
  2684. }
  2685. /**
  2686. * @param insPlyIncomeVo
  2687. * @Description: 平台新增
  2688. * @return InsPlyIncome
  2689. */
  2690. @Override
  2691. public HttpResult<InsPlyIncome> ptInsert(InsPlyIncomeVo insPlyIncomeVo) {
  2692. InsPlyIncome insPlyIncome = new InsPlyIncome();
  2693. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  2694. String agreementId = insPlyIncomeVo.getAgreementId();
  2695. if(StringUtils.isNotEmpty(agreementId)){
  2696. HttpResult<PtlAgreementQueryVo> byAgreementId = ptlAgreementService.getByAgreementId(agreementId);
  2697. if(byAgreementId!=null && ObjectUtils.isNotEmpty(byAgreementId.getData())){
  2698. PtlAgreementQueryVo data = byAgreementId.getData();
  2699. PtlAgreement agreement = data.getAgreement();
  2700. if(ObjectUtils.isNotEmpty(agreement)){
  2701. insPlyIncomeVo.setPartnerCompaniesId(agreement.getPartnerCompaniesId());
  2702. insPlyIncomeVo.setCompanyId(agreement.getInsuranceCompanyId());
  2703. }
  2704. }
  2705. }
  2706. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  2707. if (StringUtils.isNotEmpty(insPlyIncome.getPartnerCompaniesId())) {
  2708. // 合作公司id
  2709. String partnerCompaniesId = insPlyIncome.getPartnerCompaniesId();
  2710. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  2711. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  2712. String name = esmInsCompany.getNamesimple(); //合作名称
  2713. insPlyIncome.setPartnerCompaniesName(name);
  2714. insPlyIncome.setPartnerCompaniesId(insPlyIncome.getPartnerCompaniesId());
  2715. }
  2716. if (StringUtils.isNotEmpty(insPlyIncome.getCompanyId())) {
  2717. String insuranceCompanyId = insPlyIncome.getCompanyId();
  2718. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(insuranceCompanyId);
  2719. String name = esmInsCompany.getNamesimple(); //保险公司名称 简称
  2720. insPlyIncome.setCompanyName(name);
  2721. }
  2722. // if (insPlyIncome.getJqPremium() != null && insPlyIncome.getJqPremium().compareTo(BigDecimal.ZERO) > 0 && insPlyIncome.getJqSuperviseCostsProportion() != null && insPlyIncome.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
  2723. // insPlyIncome.setJqSuperviseCostsPremiums(this.getBigDecimal(insPlyIncome.getJqPremium(),insPlyIncome.getJqSuperviseCostsProportion()));
  2724. // }
  2725. // if (insPlyIncome.getSyPremium() != null && insPlyIncome.getSyPremium().compareTo(BigDecimal.ZERO) > 0 && insPlyIncome.getSySuperviseCostsProportion() != null && insPlyIncome.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
  2726. // insPlyIncome.setSySuperviseCostsPremiums(this.getBigDecimal(insPlyIncome.getSyPremium(),insPlyIncome.getSySuperviseCostsProportion()));
  2727. // }
  2728. // if (insPlyIncome.getNoPremium() != null && insPlyIncome.getNoPremium().compareTo(BigDecimal.ZERO) > 0 && insPlyIncome.getNoSuperviseCostsProportion() != null && insPlyIncome.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
  2729. // insPlyIncome.setNoSuperviseCostsPremiums(this.getBigDecimal(insPlyIncome.getNoPremium(),insPlyIncome.getNoSuperviseCostsProportion()));
  2730. // }
  2731. // if (insPlyIncome.getJqPremium() != null && insPlyIncome.getJqPremium().compareTo(BigDecimal.ZERO) > 0 && insPlyIncome.getJqOtherCostsProportion() != null && insPlyIncome.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
  2732. // insPlyIncome.setJqOtherCostsPremium(this.getBigDecimal(insPlyIncome.getJqPremium(),insPlyIncome.getJqOtherCostsProportion()));
  2733. // }
  2734. // if (insPlyIncome.getSyPremium() != null && insPlyIncome.getSyPremium().compareTo(BigDecimal.ZERO) > 0 && insPlyIncome.getSyOtherCostsProportion() != null && insPlyIncome.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
  2735. // insPlyIncome.setSyOtherCostsPremium(this.getBigDecimal(insPlyIncome.getSyPremium(),insPlyIncome.getSyOtherCostsProportion()));
  2736. // }
  2737. // if (insPlyIncome.getNoPremium() != null && insPlyIncome.getNoPremium().compareTo(BigDecimal.ZERO) > 0 && insPlyIncome.getNoOtherCostsProportion() != null && insPlyIncome.getNoOtherCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
  2738. // insPlyIncome.setNoOtherCostsPremium(this.getBigDecimal(insPlyIncome.getNoPremium(),insPlyIncome.getNoOtherCostsProportion()));
  2739. // }
  2740. HashMap<String, Object> params = new HashMap<>();
  2741. params.put("agreeId",insPlyIncomeVo.getAgreeId());
  2742. PtlAgreement ptlAgreement = ptlAgreementService.selectAgreeId(params);
  2743. if (ObjectUtils.isEmpty(ptlAgreement)) {
  2744. return HttpResult.error("协议匹配不上");
  2745. }
  2746. insPlyIncome.setAgreementId(ptlAgreement.getId());
  2747. insPlyIncome.setJqReceivableProportion(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(),insPlyIncome.getNoOtherCostsProportion(),null));
  2748. insPlyIncome.setSyReceivableProportion(this.calculateTotal(insPlyIncome.getSySuperviseCostsProportion(),insPlyIncome.getNoOtherCostsProportion(),null));
  2749. insPlyIncome.setNoReceivableProportion(this.calculateTotal(insPlyIncome.getNoSuperviseCostsProportion(),insPlyIncome.getNoOtherCostsProportion(),null));
  2750. insPlyIncome.setCreateTime(LocalDateTime.now());
  2751. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(),insPlyIncome.getSySuperviseCostsProportion(),insPlyIncome.getNoSuperviseCostsPremiums()));
  2752. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),insPlyIncome.getNoSuperviseCostsPremiums()));
  2753. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getJqOtherCostsProportion(),insPlyIncome.getSyOtherCostsProportion(),insPlyIncome.getNoOtherCostsProportion()));
  2754. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),insPlyIncome.getNoOtherCostsPremium()));
  2755. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),insPlyIncome.getOtherFeevalue(),null));
  2756. insPlyIncome.setAgreementType("1");
  2757. insPlyIncome.setHandlingFeesStatus("0");
  2758. insPlyIncome.setCommissionFeevalue(insPlyIncomeVo.getCommissionFeevalue());
  2759. insPlyIncome.setOtherFeevalue(insPlyIncomeVo.getOtherFeevalue());
  2760. insPlyIncome.setIsNotCar("0");
  2761. insPlyIncome.setIsNotDocumentary("0");
  2762. insPlyIncome.setDocumentaryFeesStatus("0");
  2763. insPlyIncome.setAllFeeValue(insPlyIncome.getReceivableAmount());
  2764. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSignDate())){
  2765. LocalDate signDate = LocalDate.parse(insPlyIncomeVo.getSignDate(), formatter);
  2766. insPlyIncome.setSignDate(signDate.atStartOfDay());
  2767. }
  2768. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  2769. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  2770. insPlyIncome.setId(null);
  2771. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  2772. insPlyIncomeLog.setOperationStatus("1");
  2773. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  2774. baseMapper.insert(insPlyIncome);
  2775. return HttpResult.ok();
  2776. }
  2777. /***
  2778. *
  2779. * @param insPlyIncomeVo
  2780. * @return 返回私有 平台 应收 已收 未收
  2781. */
  2782. @Override
  2783. public HttpResult<ArrayList<Map<String,Object>>> totalReceivables(InsPlyIncomeVo insPlyIncomeVo) {
  2784. ArrayList<Map<String,Object>> resultList = new ArrayList<>();
  2785. BigDecimal bxhandAmount = BigDecimal.ZERO; //保险手续费应收
  2786. BigDecimal receivedAmount = BigDecimal.ZERO; //保险手续费应收
  2787. HashMap<String, Object> ptParams = new HashMap<>();
  2788. ptParams.put("agreementType","1");
  2789. InsPlyIncome totalledAmount = baseMapper.ptTotalAmount(ptParams); //应收 未收 已收
  2790. ptParams.clear();
  2791. ptParams.put("commissionFeevalue",totalledAmount.getCommissionFeevalue());
  2792. ptParams.put("noInvoicCommissionFeevalue",totalledAmount.getNoInvoicCommissionFeevalue());
  2793. ptParams.put("readyCommissionFeevalue",totalledAmount.getReadyCommissionFeevalue());
  2794. resultList.add(ptParams);
  2795. //手续费应收
  2796. HashMap<String, Object> privateParams= new HashMap<>();
  2797. privateParams.put("agreementType","2");
  2798. List<InsPlyIncome> bxHandList = baseMapper.queryNew(privateParams);
  2799. for (InsPlyIncome bxhandItem : bxHandList){
  2800. bxhandAmount=bxhandAmount.add(bxhandItem.getAllFeeValue());
  2801. }
  2802. privateParams.clear();
  2803. //已开票金额 = 开票未结算+ 开票已结算
  2804. privateParams.put("settlementStatus", "2"); // 结算
  2805. List<SettlementDocumentaryFeesEntity> invoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(privateParams); //金额总数
  2806. for (SettlementDocumentaryFeesEntity invoicInsPlyIncome : invoicInsPlyIncomes) {
  2807. receivedAmount =receivedAmount.add(invoicInsPlyIncome.getSettlementAmount());
  2808. }
  2809. if(receivedAmount.compareTo(BigDecimal.ZERO)== 0){
  2810. receivedAmount=bxhandAmount;
  2811. }
  2812. BigDecimal subtract = bxhandAmount.subtract(receivedAmount);
  2813. privateParams.clear();
  2814. privateParams.put("commissionFeevalue",bxhandAmount);
  2815. privateParams.put("noInvoicCommissionFeevalue",receivedAmount);
  2816. privateParams.put("readyCommissionFeevalue",subtract);
  2817. resultList.add(privateParams);
  2818. return HttpResult.ok(resultList);
  2819. }
  2820. /**
  2821. * 根据签单日期月份分组
  2822. * @param insPlyIncomeVo
  2823. * @return 平台 私有 应收 已收
  2824. */
  2825. @Override
  2826. public HttpResult<List<HashMap<String, Object>>> monthTotalReceivables(InsPlyIncomeVo insPlyIncomeVo) {
  2827. HashMap<String, Object> params = new HashMap<>();
  2828. params.put("agreementType", insPlyIncomeVo.getAgreementType());
  2829. if ("1".equals(insPlyIncomeVo.getAgreementType())) { //平台
  2830. params.put("year", insPlyIncomeVo.getYear());
  2831. List<HashMap<String, Object>> ptResultList = baseMapper.ptSumGroupByMonth(params);
  2832. params.put("handlingFeesStatus", "1");
  2833. List<HashMap<String, Object>> ptSettleResultList = baseMapper.ptSumGroupByMonth(params);
  2834. Map<String, BigDecimal> ptMap = new HashMap<>(); // 假设commissionFeevalue是BigDecimal类型
  2835. for (HashMap<String, Object> ptSettleResultListItem : ptSettleResultList) {
  2836. String month = (String) ptSettleResultListItem.get("month");
  2837. if (month == null) {
  2838. // 处理month为null的情况
  2839. continue;
  2840. }
  2841. BigDecimal commissionFeevalue = (BigDecimal) ptSettleResultListItem.get("commissionFeevalue");
  2842. if (commissionFeevalue == null) {
  2843. // 处理commissionFeevalue为null的情况
  2844. continue;
  2845. }
  2846. ptMap.put(month, commissionFeevalue);
  2847. }
  2848. for (HashMap<String, Object> ptResultListItem : ptResultList) {
  2849. BigDecimal bigDecimal1 = ptMap.get(ptResultListItem.get("month"));
  2850. ptResultListItem.put("readyCommissionFeevalue", bigDecimal1);
  2851. BigDecimal commissionFeevalue = new BigDecimal(ptResultListItem.get("commissionFeevalue").toString());
  2852. if (bigDecimal1 !=null && bigDecimal1.compareTo(BigDecimal.ZERO) > 0) {
  2853. BigDecimal subtract = commissionFeevalue.subtract(bigDecimal1);
  2854. ptResultListItem.put("noInvoicCommissionFeevalue", subtract);
  2855. } else {
  2856. ptResultListItem.put("noInvoicCommissionFeevalue", ptResultListItem.get("commissionFeevalue"));
  2857. }
  2858. }
  2859. return HttpResult.ok(ptResultList);
  2860. } else if ("2".equals(insPlyIncomeVo.getAgreementType())) {
  2861. params.put("year", insPlyIncomeVo.getYear());
  2862. List<HashMap<String, Object>> bxResultList = baseMapper.ptSumGroupByMonth(params);
  2863. params.clear();
  2864. params.put("settlementStatus", "2");
  2865. List<HashMap<String, Object>> bxReadyCommissionFeevalue = settlementDocumentaryFeesService.bxSumGroupByMonth(params);
  2866. Map<String, BigDecimal> bxMap = new HashMap<>(); // 假设commissionFeevalue是BigDecimal类型
  2867. for (HashMap<String, Object> bxSettleResultListItem : bxReadyCommissionFeevalue) {
  2868. String month = (String) bxSettleResultListItem.get("month");
  2869. if (month == null) {
  2870. // 处理month为null的情况
  2871. continue;
  2872. }
  2873. BigDecimal commissionFeevalue = (BigDecimal) bxSettleResultListItem.get("commissionFeevalue");
  2874. if (commissionFeevalue == null) {
  2875. // 处理commissionFeevalue为null的情况
  2876. continue;
  2877. }
  2878. bxMap.put(month, commissionFeevalue);
  2879. }
  2880. for (HashMap<String, Object> bxResultListItem : bxResultList) {
  2881. BigDecimal bigDecimal1 = bxMap.get(bxResultListItem.get("month"));
  2882. bxResultListItem.put("readyCommissionFeevalue", bigDecimal1);
  2883. BigDecimal commissionFeevalue = new BigDecimal(bxResultListItem.get("commissionFeevalue").toString());
  2884. if (bigDecimal1 !=null && bigDecimal1.compareTo(BigDecimal.ZERO) > 0) {
  2885. BigDecimal subtract = commissionFeevalue.subtract(bigDecimal1);
  2886. bxResultListItem.put("noInvoicCommissionFeevalue", subtract);
  2887. } else {
  2888. bxResultListItem.put("noInvoicCommissionFeevalue", bxResultListItem.get("commissionFeevalue"));
  2889. }
  2890. }
  2891. return HttpResult.ok(bxResultList);
  2892. }
  2893. return HttpResult.ok();
  2894. }
  2895. }