InsPlyIncomeServiceImpl.java 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117
  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.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.fasterxml.jackson.databind.JsonNode;
  7. import com.fasterxml.jackson.databind.ObjectMapper;
  8. import com.github.pagehelper.PageHelper;
  9. import com.github.pagehelper.PageInfo;
  10. import com.ydtech.constants.enums.dict.agreement.ProductsType;
  11. import com.ydtech.core.page.HttpResult;
  12. import com.ydtech.exception.SystemException;
  13. import com.ydtech.modules.base.controller.BaseController;
  14. import com.ydtech.modules.esm.model.EsmInsCompany;
  15. import com.ydtech.modules.esm.service.EsmInsCompanyService;
  16. import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
  17. import com.ydtech.modules.fnc.entity.*;
  18. import com.ydtech.modules.fnc.service.*;
  19. import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
  20. import com.ydtech.modules.fnc.vo.SettlementDocumentaryFeesVo;
  21. import com.ydtech.modules.ins.model.vo.res.*;
  22. import com.ydtech.modules.inv.model.dto.*;
  23. import com.ydtech.modules.inv.utils.EasyExcelUtils;
  24. import com.ydtech.modules.order.entity.BasePageResult;
  25. import com.ydtech.modules.order.entity.InsOrders;
  26. import com.ydtech.modules.order.service.InsAreaCompanyService;
  27. import com.ydtech.modules.order.service.InsOrdersService;
  28. import com.ydtech.modules.protocol.entity.po.PtlAgreement;
  29. import com.ydtech.modules.protocol.entity.vo.PtlAgreementQueryVo;
  30. import com.ydtech.modules.protocol.service.PtlAgreementService;
  31. import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
  32. import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
  33. import com.ydtech.utils.BigDecimalUtils;
  34. import com.ydtech.utils.SnowFlakeUtil;
  35. import com.ydtech.utils.StringOperations;
  36. import com.ydtech.utils.excel.ExcelEasypoiUtils;
  37. import com.ydtech.utils.excel.ExcelStyleUtil;
  38. import lombok.extern.slf4j.Slf4j;
  39. import org.apache.commons.lang3.ObjectUtils;
  40. import org.apache.commons.lang3.StringUtils;
  41. import org.springframework.beans.BeanUtils;
  42. import org.springframework.beans.factory.annotation.Autowired;
  43. import org.springframework.beans.factory.annotation.Value;
  44. import org.springframework.context.annotation.Lazy;
  45. import org.springframework.stereotype.Service;
  46. import org.springframework.transaction.annotation.Transactional;
  47. import org.springframework.util.CollectionUtils;
  48. import org.springframework.web.multipart.MultipartFile;
  49. import javax.servlet.http.HttpServletRequest;
  50. import javax.servlet.http.HttpServletResponse;
  51. import java.io.IOException;
  52. import java.math.BigDecimal;
  53. import java.math.RoundingMode;
  54. import java.nio.file.Files;
  55. import java.nio.file.Path;
  56. import java.nio.file.Paths;
  57. import java.time.LocalDate;
  58. import java.time.LocalDateTime;
  59. import java.time.YearMonth;
  60. import java.util.*;
  61. /**
  62. * <p>
  63. * 保司结算手续费 服务实现类
  64. * </p>
  65. *
  66. * @author gws
  67. * @since 2024-01-05
  68. */
  69. @Slf4j
  70. @Service
  71. public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, InsPlyIncome> implements InsPlyIncomeService {
  72. @Autowired
  73. @Lazy
  74. private InsOrdersService insOrdersService;
  75. @Autowired
  76. private InsAreaCompanyService insAreaCompanyService;
  77. @Autowired
  78. private InsFeeOrderNewService insFeeOrderNewService;
  79. @Autowired
  80. private SettlementDocumentaryFeesService settlementDocumentaryFeesService;
  81. @Autowired
  82. private SettlementDocumentaryLogService settlementDocumentaryLogService;
  83. @Autowired
  84. private PtlAgreementService ptlAgreementService;
  85. @Autowired
  86. private EsmInsCompanyService EsmInsCompanyService;
  87. @Autowired
  88. private ImportAsyncService importAsyncService;
  89. @Autowired
  90. private IncomeTaskRelationshipService incomeTaskRelationshipService;
  91. @Value("${upload.file.path}")
  92. private String uploadPath;
  93. @Value("${upload.file.url}")
  94. private String uploadUrl;
  95. public HttpResult<BasePageResult<InsPlyIncome>> queryplyIncome(InsPlyIncomeVo insPlyIncomeVo){
  96. try{
  97. Page<InsOrders> page = new Page<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  98. PageInfo<List<InsPlyIncome>> pageHelper = null;
  99. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  100. List<InsPlyIncome> list= this.baseMapper.selectByCondition(insPlyIncomeVo);
  101. pageHelper=new PageInfo(list);
  102. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  103. return HttpResult.ok(pageResult);
  104. }catch (Exception e){
  105. e.printStackTrace();
  106. return HttpResult.error("查询异常");
  107. }
  108. }
  109. @Override
  110. public void saveBalanceNew(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  111. if (ObjectUtils.isEmpty(order) || ObjectUtils.isEmpty(insFeeOrderNew) || ObjectUtils.isEmpty(insAreaCompany)) {
  112. return;
  113. }
  114. String agreeType = this.judgeAgreeType(insAreaCompany.getAgreementId());
  115. if (StringUtils.isNotEmpty(agreeType)) {
  116. // 判断协议类型 平台 保险
  117. if ("1".equals(agreeType)) {
  118. this.savePinTai(order,insFeeOrderNew,insAreaCompany); //手续费不分非车不非车 跟单也不分
  119. }else { // 保险 逻辑: 手续费生成一条 跟单费生成一条 非车手续费一条 非车跟单费一条
  120. if (((insFeeOrderNew.getJqSuperviseCostsPremiums() != null && insFeeOrderNew.getJqSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0)) || (insFeeOrderNew.getSySuperviseCostsPremiums() != null && insFeeOrderNew.getSySuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0)) { //手续费
  121. this.saveInsuranceProcedures(order,insFeeOrderNew,insAreaCompany);
  122. }
  123. if(insFeeOrderNew.getJqOtherCostsPremiums()!=null && insFeeOrderNew.getJqOtherCostsPremiums().compareTo(BigDecimal.ZERO) != 0){ //跟单费
  124. this.saveOtherAmount(order,insFeeOrderNew,insAreaCompany);
  125. }
  126. if(insFeeOrderNew.getNoSuperviseCostsPremiums() !=null && insFeeOrderNew.getNoSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { // 非车手续费
  127. this.saveNoSupervise(order,insFeeOrderNew,insAreaCompany);
  128. }
  129. if(insFeeOrderNew.getNoOtherCostsPremiums() !=null && insFeeOrderNew.getNoOtherCostsPremiums().compareTo(BigDecimal.ZERO) != 0){ // 非车跟单费
  130. this.saveNoOtherAmount(order,insFeeOrderNew,insAreaCompany);
  131. }
  132. }
  133. }
  134. }
  135. private void saveNoOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  136. InsPlyIncome insPlyIncome = new InsPlyIncome();
  137. insPlyIncome.setOrderno(insFeeOrderNew.getInsOrderNo()); // 子订单号
  138. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  139. if(StringUtils.isNotEmpty(noPolicyno)){
  140. insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
  141. }
  142. insPlyIncome.setOtherFeevalue(insFeeOrderNew.getNoOtherCostsPremiums()); //非车跟单费
  143. insPlyIncome.setOtherFeerate(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费用比例
  144. // insPlyIncome.setDeptId(insFeeOrderNew.getDeptId());
  145. this.saveRiskCode(order.getProductid(),insPlyIncome);
  146. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  147. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  148. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  149. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  150. insPlyIncome.setLicenseno(order.getLicenseno());
  151. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  152. insPlyIncome.setNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  153. insPlyIncome.setCreateTime(LocalDate.now());
  154. insPlyIncome.setDocumentaryFeesStatus("0");
  155. insPlyIncome.setHandlingFeesStatus("0");
  156. insPlyIncome.setNoNoTaxPremium(insPlyIncome.getNoNoTaxPremium());
  157. insPlyIncome.setNoPremium(insPlyIncome.getNoPremium());
  158. insPlyIncome.setIsNotCar("1");
  159. insPlyIncome.setIsNotDocumentary("1");
  160. insPlyIncome.setJqStartDate(insAreaCompany.getJqStartDate());
  161. insPlyIncome.setJqEndDate(insAreaCompany.getJqEndDate());
  162. insPlyIncome.setSyStartDate(insAreaCompany.getSyStartDate());
  163. insPlyIncome.setSyEndDate(insAreaCompany.getSyEndDate());
  164. insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoOtherCostsPremiums());
  165. insPlyIncome.setNoOtherCostsPremium(insFeeOrderNew.getNoOtherCostsPremiums());
  166. insPlyIncome.setNoOtherCostsProportion(insFeeOrderNew.getNoOtherCostsProportion());
  167. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  168. this.getDeptId(insPlyIncome);
  169. baseMapper.insert(insPlyIncome);
  170. }
  171. private void saveNoSupervise(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  172. InsPlyIncome insPlyIncome = new InsPlyIncome();
  173. insPlyIncome.setOrderno(insFeeOrderNew.getInsOrderNo()); // 子订单号
  174. insPlyIncome.setCommissionFeevalue(insFeeOrderNew.getNoSuperviseCostsPremiums());// 非车手续费
  175. insPlyIncome.setCommissionFeerate(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费比例
  176. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  177. if(StringUtils.isNotEmpty(noPolicyno)){
  178. insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
  179. }
  180. // insPlyIncome.setDeptId(insFeeOrderNew.getDeptId());
  181. this.saveRiskCode(order.getProductid(),insPlyIncome);
  182. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  183. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  184. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  185. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  186. insPlyIncome.setLicenseno(order.getLicenseno());
  187. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  188. insPlyIncome.setCreateTime(LocalDate.now());
  189. insPlyIncome.setDocumentaryFeesStatus("0");
  190. insPlyIncome.setHandlingFeesStatus("0");
  191. insPlyIncome.setIsNotCar("1");
  192. insPlyIncome.setIsNotDocumentary("0");
  193. insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoSuperviseCostsPremiums());
  194. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  195. insPlyIncome.setInsuredName(order.getInsuredname());
  196. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium()); //非车保费
  197. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium()); //非车不含税保费
  198. insPlyIncome.setJqStartDate(insAreaCompany.getJqStartDate());
  199. insPlyIncome.setJqEndDate(insAreaCompany.getJqEndDate());
  200. insPlyIncome.setSyStartDate(insAreaCompany.getSyStartDate());
  201. insPlyIncome.setSyEndDate(insAreaCompany.getSyEndDate());
  202. insPlyIncome.setNoSuperviseCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums());
  203. insPlyIncome.setNoSuperviseCostsProportion(insFeeOrderNew.getNoSuperviseCostsProportion());
  204. this.getDeptId(insPlyIncome);
  205. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  206. baseMapper.insert(insPlyIncome);
  207. }
  208. private void saveRiskCode(String productid,InsPlyIncome insPlyIncome) {
  209. if(ProductsType.PT_0330.getCode().equals(productid)){
  210. insPlyIncome.setRiskcode(ProductsType.PT_0330.getDesc());
  211. }
  212. if(ProductsType.PT_034001.getCode().equals(productid)){
  213. insPlyIncome.setRiskcode(ProductsType.PT_034001.getDesc());
  214. }
  215. if(ProductsType.PT_034002.getCode().equals(productid)){
  216. insPlyIncome.setRiskcode(ProductsType.PT_034002.getDesc());
  217. }
  218. if(ProductsType.PT_0330034002.getCode().equals(productid)){
  219. insPlyIncome.setRiskcode(ProductsType.PT_0330034002.getDesc());
  220. }
  221. if(ProductsType.PT_0330034001.getCode().equals(productid)){
  222. insPlyIncome.setRiskcode(ProductsType.PT_0330034001.getDesc());
  223. }
  224. }
  225. private void saveOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  226. BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),null);
  227. BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(), insFeeOrderNew.getJqOtherCostsProportion(),null);
  228. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null); //交强不含税保费
  229. BigDecimal allPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);// 总保费
  230. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(),insAreaCompany.getJqpolicyno(),insAreaCompany.getSypolicyno(),null,null,null,null,order.getProductid(),insAreaCompany.getPayDate(),insAreaCompany.getSigningTime(),insAreaCompany.getCompanyId(),null,insFeeOrderNew.getAgreementId(),order.getLicenseno(),insAreaCompany.getTaxamount(),
  231. allNoTaxPremium,null,otherProportion,null,otherAmount,otherAmount,null,null,LocalDate.now(),null,null,null,"0","0","0","1");
  232. this.saveRiskCode(order.getProductid(),insPlyIncome);
  233. insPlyIncome.setTaxPremium(allPremium);
  234. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  235. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  236. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  237. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  238. insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
  239. insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
  240. insPlyIncome.setSyOtherCostsPremium(insFeeOrderNew.getSyOtherCostsPremiums());
  241. insPlyIncome.setJqOtherCostsPremium(insFeeOrderNew.getJqOtherCostsPremiums());
  242. insPlyIncome.setJqStartDate(insAreaCompany.getJqStartDate());
  243. insPlyIncome.setJqEndDate(insAreaCompany.getJqEndDate());
  244. insPlyIncome.setSyStartDate(insAreaCompany.getSyStartDate());
  245. insPlyIncome.setSyEndDate(insAreaCompany.getSyEndDate());
  246. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  247. insPlyIncome.setInsuredName(order.getInsuredname());
  248. this.getDeptId(insPlyIncome);
  249. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  250. baseMapper.insert(insPlyIncome);
  251. }
  252. private void saveInsuranceProcedures(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  253. // 保险手续费
  254. BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(), insFeeOrderNew.getSySuperviseCostsPremiums(),null);
  255. BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(), insFeeOrderNew.getSySuperviseCostsProportion(),null);
  256. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null);//不含税保费
  257. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(),insAreaCompany.getJqpolicyno(),insAreaCompany.getSypolicyno(),null,null,null,null,order.getProductid(),insAreaCompany.getPayDate(),insAreaCompany.getSigningTime(),insAreaCompany.getCompanyId(),null,insFeeOrderNew.getAgreementId(),order.getLicenseno(),insAreaCompany.getTaxamount()
  258. ,allNoTaxPremium,handlingProportion,null,handlingAmount,null,handlingAmount,null,null,LocalDate.now(),null,null,null,"0","0","0","0");
  259. BigDecimal allTaxPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);
  260. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  261. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  262. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  263. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  264. insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion());
  265. insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums());
  266. insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion());
  267. insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums());
  268. this.saveRiskCode(order.getProductid(),insPlyIncome);
  269. insPlyIncome.setTaxPremium(allTaxPremium);
  270. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  271. insPlyIncome.setInsuredName(order.getInsuredname());
  272. insPlyIncome.setJqStartDate(insAreaCompany.getJqStartDate());
  273. insPlyIncome.setJqEndDate(insAreaCompany.getJqEndDate());
  274. insPlyIncome.setSyStartDate(insAreaCompany.getSyStartDate());
  275. insPlyIncome.setSyEndDate(insAreaCompany.getSyEndDate());
  276. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  277. this.getDeptId(insPlyIncome);
  278. baseMapper.insert(insPlyIncome);
  279. }
  280. private String setNoPolicyno(com.ydtech.modules.fnc.entity.InsAreaCompany insAreaCompany) {
  281. String crossInsurance = insAreaCompany.getCrossInsurance();
  282. if (StringUtils.isEmpty(crossInsurance)) {
  283. return null;
  284. }
  285. try {
  286. ObjectMapper objJson = new ObjectMapper();
  287. JsonNode jsonArryNode = objJson.readTree(crossInsurance);
  288. if (jsonArryNode.isArray() && jsonArryNode.size() > 0) {
  289. JsonNode firstNode = jsonArryNode.get(0);
  290. JsonNode policyNumberNode = firstNode.get("policyNumber");
  291. if (policyNumberNode != null) {
  292. return policyNumberNode.asText();
  293. } else {
  294. return firstNode.get("policy").asText();
  295. }
  296. }
  297. } catch (IOException e) {
  298. e.printStackTrace(); // 可以打印异常信息
  299. }
  300. return null;
  301. }
  302. private void savePinTai(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  303. BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(), insFeeOrderNew.getSySuperviseCostsPremiums(),insFeeOrderNew.getNoSuperviseCostsPremiums()); //手续费
  304. BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(), insFeeOrderNew.getSySuperviseCostsProportion(),insFeeOrderNew.getNoSuperviseCostsProportion());//手续费比例
  305. BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),insFeeOrderNew.getNoOtherCostsPremiums());//跟单费
  306. BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(), insFeeOrderNew.getJqOtherCostsProportion(),insFeeOrderNew.getNoOtherCostsProportion()); //跟单费比例
  307. // 不含税保费
  308. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), insFeeOrderNew.getNoNoTaxPremium());
  309. BigDecimal allAmount = this.calculateTotal(otherAmount, handlingAmount, null);
  310. BigDecimal jqReceivableProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(), insFeeOrderNew.getJqOtherCostsProportion(), null);// 交强应收 比例
  311. BigDecimal syReceivableProportion = this.calculateTotal(insFeeOrderNew.getSySuperviseCostsProportion(), insFeeOrderNew.getSyOtherCostsProportion(), null);//商业应收比例
  312. BigDecimal noReceivableProportion = this.calculateTotal(insFeeOrderNew.getNoSuperviseCostsProportion(), insFeeOrderNew.getNoOtherCostsProportion(), null);
  313. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  314. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(),insAreaCompany.getJqpolicyno(),insAreaCompany.getSypolicyno(),
  315. noPolicyno,null,null, null,order.getProductid(),insAreaCompany.getPayDate(),insAreaCompany.getSigningTime(),insAreaCompany.getCompanyId(),
  316. null,insFeeOrderNew.getAgreementId(),order.getLicenseno(),insAreaCompany.getTaxamount(),allNoTaxPremium,handlingProportion,
  317. otherProportion,handlingAmount,otherAmount,allAmount,null,null,LocalDate.now(),null,null,null,"0","0","0","0");
  318. insPlyIncome.setJqReceivableProportion(jqReceivableProportion);
  319. insPlyIncome.setSyReceivableProportion(syReceivableProportion);
  320. insPlyIncome.setNoReceivableProportion(noReceivableProportion);
  321. // 应收金额 = 商业手续费+商业跟单 + 交强手续费 +交强跟单费 + 非车手续费 + 非车跟单费 = allAmount
  322. insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums()); // 交强手续费
  323. insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums()); // 商业手续费
  324. insPlyIncome.setNoSuperviseCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums()); // 非车手续费
  325. insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion()); //交强手续费 比例
  326. insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion()); // 商业手续费 比例
  327. insPlyIncome.setNoSuperviseCostsProportion(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费 比例
  328. insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
  329. insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
  330. insPlyIncome.setNoOtherCostsProportion(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费比例
  331. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  332. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  333. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium());
  334. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  335. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  336. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  337. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  338. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  339. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  340. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  341. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  342. this.getDeptId(insPlyIncome);
  343. this.saveRiskCode(order.getProductid(),insPlyIncome);
  344. insPlyIncome.setInsuredName(order.getInsuredname());
  345. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  346. baseMapper.insert(insPlyIncome);
  347. }
  348. private void getDeptId(InsPlyIncome insPlyIncome) {
  349. PtlAgreement ptlAgreement = ptlAgreementService.getById(insPlyIncome.getAgreementId());
  350. String deptId = ptlAgreement.getDeptId();
  351. insPlyIncome.setDeptId(deptId);
  352. }
  353. private void saveByCompanyId(InsFeeOrderNew insFeeOrderNew,String companyId, InsPlyIncome insPlyIncome) {
  354. PtlAgreement ptlAgreementQueryVo = this.ptlAgreementService.getByAgreementIdNew(insFeeOrderNew.getAgreementId());
  355. if(ObjectUtils.isNotEmpty(ptlAgreementQueryVo)){
  356. if(StringUtils.isNotEmpty(ptlAgreementQueryVo.getPartnerCompaniesId())){
  357. // 合作公司id
  358. String partnerCompaniesId = ptlAgreementQueryVo.getPartnerCompaniesId();
  359. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  360. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  361. String name = esmInsCompany.getNamesimple(); //合作名称
  362. insPlyIncome.setPartnerCompaniesName(name);
  363. insPlyIncome.setPartnerCompaniesId(ptlAgreementQueryVo.getPartnerCompaniesId());
  364. }
  365. if(StringUtils.isNotEmpty(ptlAgreementQueryVo.getInsuranceCompanyId())){
  366. String insuranceCompanyId = ptlAgreementQueryVo.getInsuranceCompanyId();
  367. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(insuranceCompanyId);
  368. String name = esmInsCompany.getNamesimple(); //保险公司名称 简称
  369. insPlyIncome.setCompanyName(name);
  370. }
  371. }
  372. }
  373. private BigDecimal calculateTotal(BigDecimal value1, BigDecimal value2, BigDecimal value3) {
  374. BigDecimal total = BigDecimal.ZERO;
  375. if (value1 != null) {
  376. total = total.add(value1);
  377. }
  378. if (value2 != null) {
  379. total = total.add(value2);
  380. }
  381. if (value3 != null) {
  382. total = total.add(value3);
  383. }
  384. return total;
  385. }
  386. private String judgeAgreeType(Long agreementId) {
  387. if (agreementId == null) {
  388. return null;
  389. }
  390. HttpResult<PtlAgreementQueryVo> byAgreementId = ptlAgreementService.getByAgreementId(agreementId.toString());
  391. if (byAgreementId != null && ObjectUtils.isNotEmpty(byAgreementId.getData())) {
  392. PtlAgreement agreement = byAgreementId.getData().getAgreement();
  393. String agreementType = agreement.getAgreementType();
  394. if (StringUtils.isNotEmpty(agreementType)) {
  395. return agreementType;
  396. }
  397. }
  398. return null;
  399. }
  400. public HttpResult<BasePageResult<InsPlyIncome>> queryNew(InsPlyIncomeVo insPlyIncomeVo){
  401. try{
  402. HashMap<String, Object> params = new HashMap<>();
  403. PageInfo<List<InsPlyIncome>> pageHelper = null;
  404. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  405. params.put("pageNum",insPlyIncomeVo.getPageNum());
  406. params.put("pageSize",insPlyIncomeVo.getPageSize());
  407. params =this.saveParams(insPlyIncomeVo,params);
  408. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){
  409. params.put("ids",insPlyIncomeVo.getIds().split(","));
  410. }
  411. if (StringUtils.isNotEmpty(insPlyIncomeVo.getId())) {
  412. SettlementDocumentaryFeesEntity settlementDocumentaryFeesEntity = settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
  413. // 通过任务id查询 明细
  414. String taskId = settlementDocumentaryFeesEntity.getTaskId();
  415. List<String> incomeIds = incomeTaskRelationshipService.getByTaskId(taskId);
  416. if (!CollectionUtils.isEmpty(incomeIds)) {
  417. params.put("incomeIds", incomeIds);
  418. params.remove("handlingFeesStatus");
  419. }
  420. }
  421. List<InsPlyIncome> list = this.baseMapper.queryNew(params);
  422. pageHelper=new PageInfo(list);
  423. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  424. return HttpResult.ok(pageResult);
  425. }catch (Exception e){
  426. e.printStackTrace();
  427. return HttpResult.error("查询异常");
  428. }
  429. }
  430. @Override
  431. public HashMap<String,Object> totalAmount(List<String> selectIds) {
  432. HashMap<String, Object> params = new HashMap<>();
  433. params.put("selectIds",selectIds);
  434. HashMap<String,Object> resultMap =baseMapper.totalAmount(params);
  435. return resultMap;
  436. }
  437. @Override
  438. @Transactional
  439. public HttpResult<Object> batchPinBalance(InsPlyIncomeVo insPlyIncomeVo) {
  440. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())){
  441. List<String> selectIds = insPlyIncomeVo.getSelectIds();
  442. for(String id: selectIds){
  443. InsPlyIncome insPlyIncome = new InsPlyIncome();
  444. insPlyIncome.setHandlingFeesStatus("1");
  445. insPlyIncome.setSettlementTime(LocalDate.now());
  446. insPlyIncome.setId(id);
  447. baseMapper.updateById(insPlyIncome);
  448. }
  449. }
  450. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  451. settlementDocumentaryLogEntity.setIds(insPlyIncomeVo.getIds());
  452. // settlementDocumentaryLogEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  453. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); //跟单费金额
  454. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); //手续费金额
  455. settlementDocumentaryLogEntity.setCreateTime(new Date());
  456. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  457. return HttpResult.ok();
  458. }
  459. @Override
  460. public List<InsPlyIncome> totalPinAmount(InsPlyIncomeVo insPlyIncomeVo) {
  461. HashMap<String, Object> params = new HashMap<>();
  462. params = this.saveParams(insPlyIncomeVo,params);
  463. List<InsPlyIncome> result=baseMapper.totalPinAmount(params);
  464. return result;
  465. }
  466. private HashMap<String, Object> saveParams(InsPlyIncomeVo insPlyIncomeVo, HashMap<String, Object> params) {
  467. if(ObjectUtils.isNotEmpty(insPlyIncomeVo.getStartDate())){
  468. params.put("startDate",insPlyIncomeVo.getStartDate().toString());
  469. }
  470. if(ObjectUtils.isNotEmpty(insPlyIncomeVo.getEndDate())){
  471. params.put("endDate",insPlyIncomeVo.getEndDate().toString());
  472. }
  473. if(StringUtils.isNotEmpty(insPlyIncomeVo.getOrderno())){
  474. params.put("orderno",insPlyIncomeVo.getOrderno());
  475. }
  476. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  477. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  478. }
  479. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  480. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  481. }
  482. if(StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType())){
  483. params.put("agreementType",insPlyIncomeVo.getAgreementType());
  484. }
  485. if(StringUtils.isNotEmpty(insPlyIncomeVo.getLicenseno())){
  486. params.put("licenseno", insPlyIncomeVo.getLicenseno());
  487. }
  488. if(StringUtils.isNotEmpty(insPlyIncomeVo.getUserId())){
  489. params.put("userId",insPlyIncomeVo.getUserId());
  490. }
  491. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  492. params.put("companyId",insPlyIncomeVo.getCompanyId());
  493. }
  494. if(StringUtils.isNotEmpty(insPlyIncomeVo.getRiskcode())){
  495. params.put("riskcode",insPlyIncomeVo.getRiskcode());
  496. }
  497. if(StringUtils.isNotEmpty(insPlyIncomeVo.getPolicyno())){
  498. params.put("policyno",insPlyIncomeVo.getPolicyno());
  499. }
  500. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSyPolicyno())){
  501. params.put("syPolicyno",insPlyIncomeVo.getSyPolicyno());
  502. }
  503. if(StringUtils.isNotEmpty(insPlyIncomeVo.getNoPolicyno())){
  504. params.put("noPolicyno",insPlyIncomeVo.getNoPolicyno());
  505. }
  506. if(insPlyIncomeVo.getCreateTime()!=null){
  507. params.put("createTime",insPlyIncomeVo.getCreateTime().toString());
  508. }
  509. if(insPlyIncomeVo.getSettlementTime()!=null){
  510. params.put("settlementTime",insPlyIncomeVo.getSettlementTime().toString());
  511. }
  512. if(StringUtils.isNotEmpty(insPlyIncomeVo.getHandlingFeesStatus())){
  513. params.put("handlingFeesStatus",insPlyIncomeVo.getHandlingFeesStatus());
  514. }
  515. if(StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesId())){
  516. params.put("partnerCompaniesId",insPlyIncomeVo.getPartnerCompaniesId());
  517. }
  518. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  519. params.put("year",insPlyIncomeVo.getYear());
  520. }
  521. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  522. params.put("month",insPlyIncomeVo.getMonth());
  523. }
  524. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDay())){
  525. params.put("day",insPlyIncomeVo.getDay());
  526. }
  527. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateEnd())){
  528. params.put("signDateEnd",insPlyIncomeVo.getSignDateEnd());
  529. }
  530. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateStart())){
  531. params.put("signDateStart",insPlyIncomeVo.getSignDateStart());
  532. }
  533. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyName())){
  534. params.put("companyName",insPlyIncomeVo.getCompanyName());
  535. }
  536. if(StringUtils.isNotEmpty(insPlyIncomeVo.getInsuredName())){
  537. params.put("insuredName",insPlyIncomeVo.getInsuredName());
  538. }
  539. if(StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesName())){
  540. params.put("partnerCompaniesName",insPlyIncomeVo.getPartnerCompaniesName());
  541. }
  542. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDockingPerson())){
  543. params.put("dockingPerson",insPlyIncomeVo.getDockingPerson());
  544. }
  545. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYeartsStart()) && StringUtils.isNotEmpty(insPlyIncomeVo.getYeartsEnd())){
  546. params.put("yeartsStart",insPlyIncomeVo.getYeartsStart());
  547. params.put("yeartsEnd",insPlyIncomeVo.getYeartsEnd());
  548. }
  549. if(insPlyIncomeVo.getJqStartDate() !=null){
  550. params.put("jqStartDate",insPlyIncomeVo.getJqStartDate());
  551. }
  552. if(insPlyIncomeVo.getJqStartDate() !=null){
  553. params.put("jqEndDate",insPlyIncomeVo.getJqEndDate());
  554. }
  555. if(insPlyIncomeVo.getSyStartDate() !=null){
  556. params.put("syStartDate",insPlyIncomeVo.getSyStartDate());
  557. }
  558. if(insPlyIncomeVo.getSyEndDate() !=null){
  559. params.put("syEndDate",insPlyIncomeVo.getSyEndDate());
  560. }
  561. if( StringUtils.isNotEmpty(insPlyIncomeVo.getProvinceId())){
  562. params.put("provinceId",insPlyIncomeVo.getProvinceId());
  563. }
  564. if( StringUtils.isNotEmpty(insPlyIncomeVo.getCityId())){
  565. params.put("cityId",insPlyIncomeVo.getCityId());
  566. }
  567. if( StringUtils.isNotEmpty(insPlyIncomeVo.getCountyId())){
  568. params.put("countyId",insPlyIncomeVo.getCountyId());
  569. }
  570. if( StringUtils.isNotEmpty(insPlyIncomeVo.getDeptId())){
  571. params.put("deptId",insPlyIncomeVo.getDeptId());
  572. }
  573. if( StringUtils.isNotEmpty(insPlyIncomeVo.getAllPartnerCompaniesId())){
  574. params.put("allPartnerCompaniesId",insPlyIncomeVo.getAllPartnerCompaniesId().substring(0,5));
  575. }
  576. if( StringUtils.isNotEmpty(insPlyIncomeVo.getProvincePartnerCompaniesId())){
  577. params.put("provincePartnerCompaniesId",insPlyIncomeVo.getProvincePartnerCompaniesId());
  578. }
  579. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())){
  580. params.put("selectIds",insPlyIncomeVo.getSelectIds());
  581. }
  582. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getPartnerCompaniesIdList())){
  583. params.put("partnerCompaniesIdList",insPlyIncomeVo.getPartnerCompaniesIdList());
  584. }
  585. return params;
  586. }
  587. @Override
  588. public HttpResult<BasePageResult<InsPlyIncome>> nonSettlementQuery(InsPlyIncomeVo insPlyIncomeVo) {
  589. try{
  590. HashMap<String, Object> params = new HashMap<>();
  591. PageInfo<List<InsPlyIncome>> pageHelper = null;
  592. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  593. params.put("pageNum",insPlyIncomeVo.getPageNum());
  594. params.put("pageSize",insPlyIncomeVo.getPageSize());
  595. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  596. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  597. }
  598. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  599. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  600. }
  601. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  602. params.put("year",insPlyIncomeVo.getYear());
  603. }
  604. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  605. params.put("month",insPlyIncomeVo.getMonth());
  606. }
  607. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())){
  608. params.put("documentaryFeesStatus",insPlyIncomeVo.getDocumentaryFeesStatus());
  609. }
  610. List<InsPlyIncome> list= this.baseMapper.NonSettlementQuery(params);
  611. pageHelper=new PageInfo(list);
  612. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  613. return HttpResult.ok(pageResult);
  614. }catch (Exception e){
  615. e.printStackTrace();
  616. return HttpResult.error("查询异常");
  617. }
  618. }
  619. @Override
  620. public HttpResult<List<InsPlyIncome>> nonSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  621. try {
  622. String ids = insPlyIncomeVo.getIds();
  623. ArrayList<InsPlyIncome> resultList = new ArrayList<>();
  624. if (ObjectUtils.isNotEmpty(ids)) {
  625. String[] split = ids.split(",");
  626. for (int i =0; i <split.length ; i++) {
  627. String id = split[i];
  628. resultList.add(this.baseMapper.getById(id));
  629. }
  630. }
  631. return HttpResult.ok(resultList);
  632. } catch (Exception e) {
  633. e.printStackTrace();
  634. return HttpResult.error("查询异常");
  635. }
  636. }
  637. /**
  638. *
  639. * @param multipartFile
  640. * @return totalAmount 总金额
  641. * totalHandingAmount 总手续费金额
  642. * totalOtherAmount 总跟单费金额
  643. * resultHashMap 返回 ids 已经上面的金额
  644. * resultNoSelect 未匹配的车牌号
  645. */
  646. @Override
  647. public HashMap<String, Object> importData(MultipartFile multipartFile) {
  648. BigDecimal totalAmount=BigDecimal.ZERO;
  649. BigDecimal totalHandingAmount=BigDecimal.ZERO;
  650. BigDecimal totalOtherAmount=BigDecimal.ZERO;
  651. HashMap<String, Object> params = new HashMap<>();
  652. HashMap<String, Object> resultHashMap = new HashMap<>();
  653. ArrayList<HashMap<String,Object>> resultNoSelect = new ArrayList<>();
  654. try {
  655. List<InsPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsPlyIncomeExcelDto.class, 0, 1, 1);
  656. for (InsPlyIncomeExcelDto excelItem : dtoList) {
  657. params.clear();
  658. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  659. params.put("licenseno",excelItem.getLicenseno());//车牌号
  660. }
  661. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  662. params.put("policyno",excelItem.getPolicyno()); //交强保单号
  663. }
  664. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  665. params.put("syPolicyno", excelItem.getSyPolicyno());//商业保单号
  666. }
  667. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  668. params.put("noPolicyno",excelItem.getNoPolicyno()); //非车保单号
  669. }
  670. InsPlyIncome insPlyIncome=baseMapper.findByLicenseno(params);
  671. if(ObjectUtils.isNotEmpty(insPlyIncome)){
  672. if(insPlyIncome.getAllFeeValue()!=null && insPlyIncome.getAllFeeValue().compareTo(BigDecimal.ZERO)!=0){
  673. totalAmount = totalAmount.add(insPlyIncome.getAllFeeValue()); //总金额
  674. }
  675. if(insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  676. totalHandingAmount=totalHandingAmount.add(insPlyIncome.getCommissionFeevalue()); //总手续费
  677. }
  678. if(insPlyIncome.getOtherFeevalue()!=null && insPlyIncome.getOtherFeevalue().compareTo(BigDecimal.ZERO)!=0){
  679. totalOtherAmount=totalOtherAmount.add(insPlyIncome.getOtherFeevalue()); //总跟单费
  680. }
  681. }else {
  682. resultNoSelect.add(params); // 添加未匹配的车牌号
  683. }
  684. }
  685. resultHashMap.put("totalAmount",totalAmount);
  686. resultHashMap.put("totalHandingAmount",totalHandingAmount);
  687. resultHashMap.put("totalOtherAmount",totalOtherAmount);
  688. resultHashMap.put("resultList",resultNoSelect);
  689. return resultHashMap;
  690. } catch (IOException e) {
  691. throw new SystemException("导入失败!");
  692. }
  693. }
  694. /**
  695. *
  696. * @param multipartFile
  697. * @return resultList 包含总金额 还有 未匹配表中的数据
  698. */
  699. @Override
  700. public HashMap<String, Object> bxImportData(MultipartFile multipartFile,String isNotCar) {
  701. BigDecimal totalAmount=BigDecimal.ZERO;
  702. HashMap<String, Object> params = new HashMap<>();
  703. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  704. HashMap<String, Object> resultMap = new HashMap<>();
  705. StringBuffer strBuilder = new StringBuffer();
  706. boolean open=true;
  707. String ids="";
  708. try {
  709. List<InsBxPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxPlyIncomeExcelDto.class, 0, 1, 1);
  710. Integer i=0;
  711. if(!CollectionUtils.isEmpty(dtoList)){
  712. for (InsBxPlyIncomeExcelDto excelItem : dtoList) {
  713. String reason ="";
  714. i=i+1;
  715. params.clear();
  716. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  717. String licenseno = excelItem.getLicenseno();//车牌号
  718. params.put("licenseno",licenseno);
  719. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  720. if(ObjectUtils.isEmpty(byBxLicenseno)){
  721. reason="该数据车牌号有问题";
  722. }
  723. }
  724. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  725. String policyno = excelItem.getPolicyno(); //交强保单号
  726. params.put("policyno",policyno);
  727. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  728. if(ObjectUtils.isEmpty(byBxLicenseno)){
  729. reason="该数据交强保单号有问题";
  730. }
  731. }
  732. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  733. String syPolicyno = excelItem.getSyPolicyno(); //商业保单号
  734. params.put("syPolicyno",syPolicyno);
  735. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  736. if(ObjectUtils.isEmpty(byBxLicenseno)){
  737. reason="该数据商业保单号有问题";
  738. }
  739. }
  740. if(excelItem.getJqSuperviseCostsPremiums() !=null && excelItem.getJqSuperviseCostsPremiums().compareTo(BigDecimal.ZERO)!=0){
  741. params.put("jqSuperviseCostsPremiums",excelItem.getJqSuperviseCostsPremiums());
  742. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  743. if(ObjectUtils.isEmpty(byBxLicenseno)){
  744. reason="该数据交强手续费金额有问题";
  745. }
  746. }
  747. if(excelItem.getJqSuperviseCostsProportion() !=null && excelItem.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO)!=0){
  748. params.put("jqSuperviseCostsProportion",excelItem.getJqSuperviseCostsProportion());
  749. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  750. if(ObjectUtils.isEmpty(byBxLicenseno)){
  751. reason="该数据交强手续费比例有问题";
  752. }
  753. }
  754. if(excelItem.getSySuperviseCostsProportion() !=null && excelItem.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO)!=0){
  755. params.put("sySuperviseCostsProportion",excelItem.getSySuperviseCostsProportion());
  756. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  757. if(ObjectUtils.isEmpty(byBxLicenseno)){
  758. reason="该数据商业手续费比例有问题";
  759. }
  760. }
  761. if(excelItem.getSySuperviseCostsPremiums() !=null && excelItem.getSySuperviseCostsPremiums().compareTo(BigDecimal.ZERO)!=0){
  762. params.put("sySuperviseCostsPremiums",excelItem.getSySuperviseCostsPremiums());
  763. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  764. if(ObjectUtils.isEmpty(byBxLicenseno)){
  765. reason="该数据商业手续费金额有问题";
  766. }
  767. }
  768. if(excelItem.getJqPremium() !=null && excelItem.getJqPremium().compareTo(BigDecimal.ZERO)!=0){
  769. params.put("jqPremium",excelItem.getJqPremium());
  770. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  771. if(ObjectUtils.isEmpty(byBxLicenseno)){
  772. reason="该数据交强保费有问题";
  773. }
  774. }
  775. if(excelItem.getSyPremium() !=null && excelItem.getSyPremium().compareTo(BigDecimal.ZERO)!=0){
  776. params.put("syPremium",excelItem.getSyPremium());
  777. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  778. if(ObjectUtils.isEmpty(byBxLicenseno)){
  779. reason="该数据商业保费有问题";
  780. }
  781. }
  782. // 只查手续费
  783. params.put("isOther","0");
  784. params.put("isNotCar",isNotCar);
  785. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  786. if(ObjectUtils.isNotEmpty(insPlyIncome) && open){
  787. open=false;
  788. resultMap.put("companyId",insPlyIncome.getCompanyId()); // 保险公司id
  789. resultMap.put("partnerCompaniesId",insPlyIncome.getPartnerCompaniesId()); //合作公司id
  790. resultMap.put("agreementId",insPlyIncome.getAgreementId()); //协议id
  791. }
  792. if(ObjectUtils.isNotEmpty(insPlyIncome)){ // 比配上汇总金额 未匹配则返回到数据当中
  793. strBuilder.append(insPlyIncome.getId()).append(",");
  794. if( insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  795. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  796. }
  797. }else {
  798. HashMap<String, Object> noMatching = new HashMap<>();
  799. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  800. noMatching.put("licenseno",excelItem.getLicenseno());
  801. }
  802. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  803. noMatching.put("policyno",excelItem.getPolicyno());
  804. }
  805. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  806. noMatching.put("syPolicyno",excelItem.getSyPolicyno());
  807. }
  808. resultList.add(noMatching);
  809. }
  810. resultMap.put("reason",reason);
  811. }
  812. }
  813. if(strBuilder.length() >0){
  814. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  815. }
  816. resultMap.put("ids",ids);
  817. resultMap.put("totalAmount",totalAmount);
  818. resultMap.put("resultList",resultList);
  819. return resultMap;
  820. } catch (IOException e) {
  821. throw new SystemException("导入失败!");
  822. }
  823. }
  824. @Override
  825. public HashMap<String, Object> bxImportNoData(MultipartFile multipartFile,String isNotCar) {
  826. BigDecimal totalAmount=BigDecimal.ZERO;
  827. HashMap<String, Object> params = new HashMap<>();
  828. HashMap<String, Object> resultMap = new HashMap<>();
  829. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  830. StringBuffer strBuilder = new StringBuffer();
  831. String ids="";
  832. try {
  833. Integer i=0;
  834. List<InsBxNoPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxNoPlyIncomeExcelDto.class, 0, 1, 1);
  835. if(!CollectionUtils.isEmpty(dtoList)){
  836. for (InsBxNoPlyIncomeExcelDto excelItem : dtoList) {
  837. String reason ="";
  838. i=i+1;
  839. params.clear();
  840. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  841. String licenseno = excelItem.getLicenseno();//车牌号
  842. params.put("licenseno",licenseno);
  843. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  844. if(ObjectUtils.isEmpty(byBxLicenseno)){
  845. reason="该数据车牌号有问题";
  846. }
  847. }
  848. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  849. String policyno = excelItem.getNoPolicyno(); //非车保单号
  850. params.put("NoPolicyno",policyno);
  851. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  852. if(ObjectUtils.isEmpty(byBxLicenseno)){
  853. reason="该数据非车保单号有问题";
  854. }
  855. }
  856. if(excelItem.getNoPremium() !=null && excelItem.getNoPremium().compareTo(BigDecimal.ZERO)!=0){
  857. params.put("noPolicyno",excelItem.getNoPremium());
  858. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  859. if(ObjectUtils.isEmpty(byBxLicenseno)){
  860. reason="该数据非车保费有问题";
  861. }
  862. }
  863. if( excelItem.getNoSuperviseCostsPremiums() !=null && excelItem.getNoSuperviseCostsPremiums().compareTo(BigDecimal.ZERO)!=0){
  864. params.put("noSuperviseCostsPremiums",excelItem.getNoSuperviseCostsPremiums());
  865. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  866. if(ObjectUtils.isEmpty(byBxLicenseno)){
  867. reason="该数据非车手续费有问题";
  868. }
  869. }
  870. if(excelItem.getNoSuperviseCostsProportion() != null && excelItem.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO)!=0){
  871. params.put("noSuperviseCostsProportion",excelItem.getNoSuperviseCostsProportion());
  872. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  873. if(ObjectUtils.isEmpty(byBxLicenseno)){
  874. reason="该数据非车手续费比例有问题";
  875. }
  876. }
  877. // 只查手续费
  878. params.put("isOther","0");
  879. params.put("isNotCar",isNotCar);
  880. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  881. if(i==dtoList.size() && ObjectUtils.isNotEmpty(insPlyIncome)){
  882. resultMap.put("companyId",insPlyIncome.getCompanyId()); // 保险公司id
  883. resultMap.put("partnerCompaniesId",insPlyIncome.getPartnerCompaniesId()); //合作公司id
  884. resultMap.put("agreementId",insPlyIncome.getAgreementId()); //协议id
  885. }
  886. if(ObjectUtils.isNotEmpty(insPlyIncome)){ // 比配上汇总金额 未匹配则返回到数据当中
  887. strBuilder.append(insPlyIncome.getId()).append(",");
  888. if( insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  889. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  890. }
  891. }else {
  892. HashMap<String, Object> noMatching = new HashMap<>();
  893. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  894. noMatching.put("licenseno",excelItem.getLicenseno());
  895. }
  896. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  897. noMatching.put("NoPolicyno",excelItem.getNoPolicyno());
  898. }
  899. resultList.add(noMatching);
  900. }
  901. resultMap.put("reason",reason);
  902. }
  903. if(strBuilder.length() >0){
  904. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  905. }
  906. resultMap.put("ids",ids);
  907. resultMap.put("totalAmount",totalAmount);
  908. resultMap.put("resultList",resultList);
  909. }
  910. return resultMap;
  911. } catch (IOException e) {
  912. throw new SystemException("导入失败!");
  913. }
  914. }
  915. @Override
  916. public HttpResult bxOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  917. HashMap<String, Object> params = new HashMap<>();
  918. params =this.saveParams(insPlyIncomeVo,params);
  919. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  920. String filePathName ="";
  921. List<BxOtherDetailsNorExcel> resultNoList=new ArrayList<>();
  922. List<BxOtherDetailsExcel> resultList=new ArrayList<>();
  923. //判断是否是非车 1 是非车
  924. if("1".equals(insPlyIncomeVo.getIsNotCar())){
  925. filePathName="非车跟单明细导出";
  926. ExportParams exportParams = new ExportParams("非车跟单明细", null, ExcelType.HSSF);
  927. exportParams.setStyle(ExcelStyleUtil.class);
  928. for (InsPlyIncome item :insPlyIncomes){
  929. BxOtherDetailsNorExcel bxOtherDetailsNorExcel = new BxOtherDetailsNorExcel();
  930. LocalDateTime signDate = item.getSignDate();
  931. BeanUtils.copyProperties(item, bxOtherDetailsNorExcel);
  932. bxOtherDetailsNorExcel.setSigndate(signDate);
  933. resultNoList.add(bxOtherDetailsNorExcel);
  934. }
  935. }else{
  936. filePathName="车险跟单明细导出";
  937. ExportParams exportParams = new ExportParams("车险跟单明细", null, ExcelType.HSSF);
  938. exportParams.setStyle(ExcelStyleUtil.class);
  939. for (InsPlyIncome item :insPlyIncomes){
  940. BxOtherDetailsExcel bxOtherDetailsExcel = new BxOtherDetailsExcel();
  941. LocalDateTime signDate = item.getSignDate();
  942. BeanUtils.copyProperties(item, bxOtherDetailsExcel);
  943. bxOtherDetailsExcel.setSigndate(signDate);
  944. resultList.add(bxOtherDetailsExcel);
  945. }
  946. }
  947. String uploadPath = this.uploadPath + "/excel/";
  948. Path path = Paths.get(uploadPath);
  949. if (!Files.exists(path)) {
  950. try {
  951. Files.createDirectories(path);
  952. } catch (IOException e) {
  953. e.printStackTrace();
  954. }
  955. }
  956. String fileName="";
  957. if("1".equals(insPlyIncomeVo.getIsNotCar())){
  958. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxOtherDetailsNorExcel.class, resultNoList);
  959. }else{
  960. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxOtherDetailsExcel.class, resultList);
  961. }
  962. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  963. }
  964. /**
  965. *
  966. * @param insPlyIncomeVo 传参字段
  967. * ids 通过ids中的id进行开票分组
  968. *
  969. * @return
  970. */
  971. @Override
  972. public HttpResult<List<HashMap<String,Object>>> invicdetail(InsPlyIncomeVo insPlyIncomeVo) {
  973. HashMap<String, Object> params = new HashMap<>();
  974. params =this.saveParams(insPlyIncomeVo,params);
  975. if (StringUtils.isEmpty(insPlyIncomeVo.getIsSettlement())){
  976. params.put("isSettlement","1");
  977. }
  978. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSettlementStatus())){
  979. params.put("settlementStatus",insPlyIncomeVo.getSettlementStatus());
  980. }
  981. List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(params);
  982. if (resultList.size() > 0) {
  983. return HttpResult.ok(resultList);
  984. }
  985. return HttpResult.ok();
  986. }
  987. /***
  988. *
  989. * @param insPlyIncomeVo
  990. * @param request
  991. * @param response
  992. * @return 保险非车跟单明细导出
  993. */
  994. @Override
  995. public HttpResult bxNoOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  996. HashMap<String, Object> params = new HashMap<>();
  997. params =this.saveParams(insPlyIncomeVo,params);
  998. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  999. ExportParams exportParams = new ExportParams("保险非车跟单明细导出", null, ExcelType.HSSF);
  1000. exportParams.setStyle(ExcelStyleUtil.class);
  1001. List<BxNoOtherDetailsExcel> resultList = new ArrayList<>();
  1002. for (InsPlyIncome item :insPlyIncomes){
  1003. BxNoOtherDetailsExcel bxNoOtherDetailsExcel = new BxNoOtherDetailsExcel();
  1004. BeanUtils.copyProperties(item, bxNoOtherDetailsExcel);
  1005. resultList.add(bxNoOtherDetailsExcel);
  1006. }
  1007. String uploadPath = this.uploadPath + "/excel/";
  1008. Path path = Paths.get(uploadPath);
  1009. if (!Files.exists(path)) {
  1010. try {
  1011. Files.createDirectories(path);
  1012. } catch (IOException e) {
  1013. e.printStackTrace();
  1014. }
  1015. }
  1016. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险非车跟单明细导出", BxNoOtherDetailsExcel.class, resultList);
  1017. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1018. }
  1019. /**
  1020. *
  1021. * @param insPlyIncomeVo 开票ids
  1022. * @return 返回开票号 开票金额 开票时间
  1023. */
  1024. @Override
  1025. public HttpResult<List<HashMap<String, Object>>> otherSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  1026. HashMap<String, Object> params = new HashMap<>();
  1027. params =this.saveParams(insPlyIncomeVo,params);
  1028. List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(params);
  1029. if (resultList.size() > 0) {
  1030. return HttpResult.ok(resultList);
  1031. }
  1032. return HttpResult.ok();
  1033. }
  1034. @Override
  1035. public InsPlyIncome getEntityById(String id) {
  1036. return baseMapper.getEntityById(id);
  1037. }
  1038. @Override
  1039. @Transactional
  1040. public void updateByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  1041. // 根据协议 如果是含增值税结算 用保费 * 如果是 不含税保费
  1042. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1043. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1044. this.amountCalculate(insPlyIncomeVo,insPlyIncome);
  1045. baseMapper.updateById(insPlyIncome);
  1046. insPlyIncomeVo.setCrudStatus("2");
  1047. this.saveLog(insPlyIncomeVo);
  1048. }
  1049. /**
  1050. *
  1051. * @param insPlyIncomeVo
  1052. * @param insPlyIncome
  1053. *
  1054. * 重新计算金额 通过比例
  1055. * 计算逻辑 交强不含税保费* 交强跟单比例 = 交强跟单金额
  1056. */
  1057. private void amountCalculate(InsPlyIncomeVo insPlyIncomeVo,InsPlyIncome insPlyIncome) {
  1058. if("1".equals(insPlyIncomeVo.getAgreementType())){ //平台
  1059. // 平台 手续费 +跟单费 = 应收 手续费 = 手续费比例*保费 应收比例=手续费比例 + 跟单比例
  1060. BigDecimal jqSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqSuperviseCostsProportion());//交强手续费比例
  1061. BigDecimal sySuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSySuperviseCostsProportion()); //商业手续费比例
  1062. BigDecimal noSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoSuperviseCostsProportion()); //非车手续费比例
  1063. BigDecimal jqOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqOtherCostsProportion()); //交强跟单比例
  1064. BigDecimal syOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSyOtherCostsProportion()); //商业跟单比例
  1065. BigDecimal noOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoOtherCostsProportion()); //非车跟单比例
  1066. BigDecimal jqPremium = initializationBigdecimal(insPlyIncomeVo.getJqPremium()); //交强保费
  1067. BigDecimal syPremium = initializationBigdecimal(insPlyIncomeVo.getSyPremium()); //商业保费
  1068. BigDecimal noPremium = initializationBigdecimal(insPlyIncomeVo.getNoPremium()); //非车保费
  1069. //手续费比例
  1070. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion,sySuperviseCostsProportion,noSuperviseCostsProportion)); //手续费比例 = 商业手续费比例 + 交强手续费比例 + 非车手续费比例
  1071. if(jqSuperviseCostsProportion !=null && jqPremium!=null ){
  1072. insPlyIncome.setJqSuperviseCostsPremiums(this.algorithmAmount(jqPremium,jqSuperviseCostsProportion)); //交强手续费
  1073. }
  1074. if(sySuperviseCostsProportion !=null && syPremium !=null){
  1075. insPlyIncome.setSySuperviseCostsPremiums(this.algorithmAmount(syPremium,sySuperviseCostsProportion)); //商业手续费
  1076. }
  1077. if(noSuperviseCostsProportion !=null && noPremium!=null){
  1078. insPlyIncome.setNoSuperviseCostsPremiums(this.algorithmAmount(noPremium,noSuperviseCostsProportion)); //非车手续费
  1079. }
  1080. if(jqOtherCostsProportion !=null && jqPremium!=null ){
  1081. insPlyIncome.setJqOtherCostsPremium(this.algorithmAmount(jqPremium,jqOtherCostsProportion)); //交强跟单费
  1082. }
  1083. if(syOtherCostsProportion !=null && syPremium !=null ){
  1084. insPlyIncome.setSyOtherCostsPremium(this.algorithmAmount(syPremium,syOtherCostsProportion)); //商业跟单费
  1085. }
  1086. if(noOtherCostsProportion !=null && noPremium !=null){
  1087. insPlyIncome.setNoOtherCostsPremium(this.algorithmAmount(noPremium,noOtherCostsProportion)); //非车跟单费
  1088. }
  1089. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),insPlyIncome.getNoSuperviseCostsPremiums())); //手续费
  1090. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion,sySuperviseCostsProportion,noSuperviseCostsProportion)); //手续费比例
  1091. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),insPlyIncome.getNoOtherCostsPremium())); //跟单费金额
  1092. insPlyIncome.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion,syOtherCostsProportion,noOtherCostsProportion)); //跟单费比例
  1093. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),insPlyIncome.getOtherFeevalue(),null)); // 总费用 = 手续费+跟单费
  1094. //应收比例 交强应收比例=交强手续费比例+交强非跟单比例
  1095. insPlyIncome.setJqReceivableProportion(this.calculateTotal(jqSuperviseCostsProportion,jqOtherCostsProportion,null)); //交强应收
  1096. insPlyIncome.setSyReceivableProportion(this.calculateTotal(sySuperviseCostsProportion,syOtherCostsProportion,null)); //商业应收
  1097. insPlyIncome.setNoReceivableProportion(this.calculateTotal(noSuperviseCostsProportion,noOtherCostsProportion,null)); //非车应收
  1098. }else {
  1099. BigDecimal jqNoTaxPremium = insPlyIncomeVo.getJqNoTaxPremium();// 交强手续费 按照思路 交强不含税保费* 交强手续费比例 =交强手续费
  1100. BigDecimal syNoTaxPremium = insPlyIncomeVo.getSyNoTaxPremium();// 商业手续费 按照思路 商业不含税保费* 商业手续费比例 =商业手续费
  1101. BigDecimal noNoTaxPremium = insPlyIncomeVo.getNoNoTaxPremium();// 非车手续费 按照思路 非车不含税保费* 非车手续费比例 =非车手续费
  1102. if(insPlyIncomeVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1103. BigDecimal jqhandingFee = jqNoTaxPremium.multiply(insPlyIncomeVo.getJqSuperviseCostsProportion().divide(new BigDecimal(100)));
  1104. insPlyIncome.setJqSuperviseCostsPremiums(jqhandingFee);
  1105. }
  1106. if(insPlyIncomeVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1107. BigDecimal syhandingFee = syNoTaxPremium.multiply(insPlyIncomeVo.getSySuperviseCostsProportion().divide(new BigDecimal(100)));
  1108. insPlyIncome.setSySuperviseCostsPremiums(syhandingFee);
  1109. }
  1110. if(insPlyIncomeVo.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1111. BigDecimal nohandingFee = noNoTaxPremium.multiply(insPlyIncomeVo.getNoSuperviseCostsProportion().divide(new BigDecimal(100)));
  1112. insPlyIncome.setNoSuperviseCostsPremiums(nohandingFee);
  1113. }
  1114. if(insPlyIncomeVo.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1115. BigDecimal jqother = jqNoTaxPremium.multiply(insPlyIncomeVo.getJqOtherCostsProportion().divide(new BigDecimal(100)));//交强跟单费 按照思路 交强不含税保费* 交强跟单比例 = 交强跟单金额
  1116. insPlyIncome.setJqOtherCostsPremium(jqother);
  1117. }
  1118. if(insPlyIncomeVo.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1119. BigDecimal syother = syNoTaxPremium.multiply(insPlyIncomeVo.getSyOtherCostsProportion().divide(new BigDecimal(100)));//交强跟单费 按照思路 交强不含税保费* 交强跟单比例 = 交强跟单金额
  1120. insPlyIncome.setSyOtherCostsPremium(syother);
  1121. }
  1122. if(insPlyIncomeVo.getNoOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1123. BigDecimal syother = syNoTaxPremium.multiply(insPlyIncomeVo.getNoOtherCostsProportion().divide(new BigDecimal(100)));//非车跟单费 按照思路 非车不含税保费* 非车跟单比例 = 非车跟单金额
  1124. insPlyIncome.setNoOtherCostsPremium(syother);
  1125. }
  1126. if("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())){ //保险 手续费 =不含税保费* 手续费比例
  1127. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),null)); // 手续费
  1128. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(),insPlyIncome.getSySuperviseCostsProportion(),null));//手续费比例
  1129. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),null,null));//总金额
  1130. }else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())){ //保险跟单费 交强跟单+商业跟单
  1131. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),null));
  1132. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getJqOtherCostsProportion(),insPlyIncome.getSyOtherCostsProportion(),null));
  1133. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(),null,null));//总金额
  1134. }
  1135. if("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())){// 非车
  1136. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getNoSuperviseCostsPremiums(),null,null)); // 非车手续费
  1137. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getNoSuperviseCostsProportion(),null,null)); //非车比例
  1138. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),null,null));//总金额
  1139. }else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())){ //非车跟单
  1140. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getNoOtherCostsPremium(),null,null)); //非车跟单金额
  1141. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getNoOtherCostsProportion(),null,null)); // 非车跟单比例
  1142. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(),null,null));//总金额
  1143. }
  1144. }
  1145. }
  1146. /**
  1147. *
  1148. * @param value1 保费
  1149. * @param value2 比例
  1150. * @return 费用
  1151. */
  1152. private BigDecimal algorithmAmount(BigDecimal value1, BigDecimal value2) {
  1153. return value1.multiply(value2.divide(new BigDecimal(100)));
  1154. }
  1155. private BigDecimal initializationBigdecimal(BigDecimal value) {
  1156. return value != null ? value : BigDecimal.ZERO;
  1157. }
  1158. private void saveLog(InsPlyIncomeVo insPlyIncomeVo) {
  1159. // 添加记录
  1160. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1161. settlementDocumentaryLogEntity.setCrudStatus(insPlyIncomeVo.getCrudStatus());
  1162. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue());
  1163. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId());
  1164. settlementDocumentaryLogEntity.setAmountType("2");
  1165. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1166. }
  1167. @Override
  1168. @Transactional
  1169. public HttpResult<InsPlyIncome> insertByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  1170. Long id = new SnowFlakeUtil().nextId();
  1171. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1172. insPlyIncomeVo.setOrderno(id.toString());
  1173. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1174. insPlyIncome.setUserId(BaseController.getUser().getId());
  1175. insPlyIncome.setDocumentaryFeesStatus("0");
  1176. insPlyIncome.setHandlingFeesStatus("0");
  1177. insPlyIncome.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1178. insPlyIncome.setIsNotDocumentary(insPlyIncomeVo.getIsNotDocumentary()); //是否是跟单
  1179. HashMap<String, Object> params = new HashMap<>();
  1180. params.put("companyId",insPlyIncomeVo.getCompanyId());
  1181. params.put("partnerCompaniesId",insPlyIncomeVo.getPartnerCompaniesId());
  1182. PtlAgreement ptlAgreement = ptlAgreementService.selectAgreeId(params);
  1183. if(ObjectUtils.isEmpty(ptlAgreement)){
  1184. return HttpResult.error("协议匹配不上");
  1185. }
  1186. insPlyIncome.setAgreementId(ptlAgreement.getId());
  1187. baseMapper.insert(insPlyIncome);
  1188. insPlyIncomeVo.setId(insPlyIncome.getId());
  1189. insPlyIncomeVo.setCrudStatus("1");
  1190. this.saveLog(insPlyIncomeVo); //添加日志
  1191. // HashMap<String, Object> params = new HashMap<>();
  1192. //
  1193. // if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  1194. // params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  1195. // }
  1196. // params.put("isOther","1");
  1197. // if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1198. // params.put("year",insPlyIncomeVo.getYear());
  1199. // }
  1200. // if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1201. // params.put("companyId",insPlyIncomeVo.getCompanyId());
  1202. // }
  1203. //
  1204. // List<InsPlyIncome> list= this.baseMapper.NonSettlementQuery(params);
  1205. // if(!CollectionUtils.isEmpty(list)){
  1206. // for (InsPlyIncome item :list){
  1207. // return HttpResult.ok(item.getIds());
  1208. // }
  1209. // }
  1210. return HttpResult.ok();
  1211. }
  1212. @Override
  1213. @Transactional
  1214. public HttpResult<InsPlyIncome> deleteById(InsPlyIncomeVo insPlyIncomeVo) {
  1215. HashMap<String, Object> params = new HashMap<>();
  1216. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  1217. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  1218. }
  1219. params.put("isOther","1");
  1220. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1221. params.put("year",insPlyIncomeVo.getYear());
  1222. }
  1223. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1224. params.put("companyId",insPlyIncomeVo.getCompanyId());
  1225. }
  1226. baseMapper.deleteById(insPlyIncomeVo.getId());
  1227. insPlyIncomeVo.setCrudStatus("3");
  1228. this.saveLog(insPlyIncomeVo);
  1229. List<InsPlyIncome> list = this.baseMapper.NonSettlementQuery(params);
  1230. if (!CollectionUtils.isEmpty(list)) {
  1231. for (InsPlyIncome item : list) {
  1232. return HttpResult.ok(item.getIds());
  1233. }
  1234. } else {
  1235. return HttpResult.ok(null);
  1236. }
  1237. return HttpResult.ok("删除成功");
  1238. }
  1239. @Override
  1240. @Transactional
  1241. public void uodateBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1242. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1243. insPlyIncomeVo.setHandlingFeesStatus("1");
  1244. insPlyIncomeVo.setSettlementTime(LocalDate.now());
  1245. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1246. baseMapper.updateById(insPlyIncome);
  1247. // 生成记录
  1248. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1249. if(StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType()) && "1".equals(insPlyIncomeVo.getAgreementType())){
  1250. // 只有平台协议 才会跟单费一笔结算
  1251. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); // 跟单费金额
  1252. }
  1253. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); // 手续费金额
  1254. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId()); // 关联id
  1255. settlementDocumentaryLogEntity.setAmountType("1"); //手续费结算
  1256. settlementDocumentaryLogEntity.setCreateTime(new Date());
  1257. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1258. }
  1259. @Override
  1260. @Transactional
  1261. public HttpResult<BasePageResult<InsPlyIncome>> totalQuery(InsPlyIncomeVo insPlyIncomeVo) {
  1262. HashMap<String, Object> params = new HashMap<>();
  1263. PageInfo<List<InsPlyIncome>> pageHelper = null;
  1264. if(insPlyIncomeVo.getStartDate()!=null){
  1265. params.put("startDate",insPlyIncomeVo.getStartDate().toString());
  1266. }
  1267. if(insPlyIncomeVo.getEndDate()!=null){
  1268. params.put("endDate",insPlyIncomeVo.getEndDate().toString());
  1269. }
  1270. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1271. params.put("year",insPlyIncomeVo.getYear());
  1272. }
  1273. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  1274. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  1275. }
  1276. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  1277. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  1278. }
  1279. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())){
  1280. params.put("documentaryFeesStatus",insPlyIncomeVo.getDocumentaryFeesStatus());
  1281. }
  1282. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1283. params.put("companyId",insPlyIncomeVo.getCompanyId());
  1284. }
  1285. params.put("pageNum",insPlyIncomeVo.getPageNum());
  1286. params.put("pageSize",insPlyIncomeVo.getPageSize());
  1287. List<InsPlyIncome> list= this.baseMapper.totalQuery(params);
  1288. pageHelper=new PageInfo(list);
  1289. return HttpResult.ok(new BasePageResult<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list));
  1290. }
  1291. /**
  1292. *
  1293. * @param insPlyIncomeVo ids ins_ply_income 这个表的ids incomeIds settlement_documentary_fees 这个表的ids
  1294. * @return
  1295. */
  1296. /**
  1297. * 跟单费结算 有分批结算的情况
  1298. * @param insPlyIncomeVo
  1299. * @return
  1300. */
  1301. @Override
  1302. @Transactional
  1303. public HttpResult batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1304. // 通过ids 查出跟单非结算单
  1305. BigDecimal allAmount = BigDecimal.ZERO;
  1306. // 分批结算
  1307. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  1308. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId()); //开票号
  1309. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1310. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1311. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId()); // 保险公司id
  1312. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1313. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算金额
  1314. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1315. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1316. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1317. if ("0".equals(insPlyIncomeVo.getInvoicingMethod())) {
  1318. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1319. } else {
  1320. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1321. }
  1322. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1323. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1324. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
  1325. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1326. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1327. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1328. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1329. return HttpResult.ok();
  1330. }
  1331. /**
  1332. *
  1333. * @param insPlyIncomeVo
  1334. * @return
  1335. */
  1336. @Override
  1337. public List<InsPlyIncome> totalBxAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1338. HashMap<String, Object> params = new HashMap<>();
  1339. params=this.saveParams(insPlyIncomeVo,params);
  1340. params.remove("handlingFeesStatus");
  1341. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  1342. // 数据库数据太多是 用sql拼接id会丢失 所以只能逻辑拼接
  1343. List<InsPlyIncome> idList=baseMapper.getIncomeIdList(params);
  1344. if(!CollectionUtils.isEmpty(idList) && !CollectionUtils.isEmpty(resultList)){
  1345. this.splicingIds(idList,resultList);
  1346. }
  1347. return resultList;
  1348. }
  1349. /**
  1350. *
  1351. * @param idList 要开票的数据集合
  1352. * @param resultList 总返回数据
  1353. */
  1354. private void splicingIds(List<InsPlyIncome> idList, List<InsPlyIncome> resultList) {
  1355. // 使用Map来存储agreementId到其id列表的映射
  1356. Map<String, List<String>> idMap = new HashMap<>();
  1357. for (InsPlyIncome idItem : idList) {
  1358. String partnerCompaniesId = idItem.getPartnerCompaniesId();
  1359. idMap.computeIfAbsent(partnerCompaniesId, k -> new ArrayList<>()).add(idItem.getId());
  1360. }
  1361. for (InsPlyIncome resultItem : resultList) {
  1362. List<String> ids = idMap.getOrDefault(resultItem.getPartnerCompaniesId(), Collections.emptyList());
  1363. String idsString = String.join(",", ids);
  1364. resultItem.setIds(idsString);
  1365. }
  1366. }
  1367. /**
  1368. *
  1369. * @param insPlyIncomeVo
  1370. * @return 保险手续费改成多次结算
  1371. */
  1372. @Override
  1373. @Transactional
  1374. public HttpResult<Object> batchInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1375. ImportResult importResult = importAsyncService.getById(insPlyIncomeVo.getSelectIds().get(0)); // 查询 任务
  1376. HashMap<String, Object> params = new HashMap<>();
  1377. if (StringUtils.isNotEmpty(importResult.getId())) {
  1378. params.put("companyId",importResult.getCompanyId());
  1379. params.put("partnerCompaniesId",importResult.getPartnerCompaniesId());
  1380. params.put("isOther","0");
  1381. if (StringUtils.isNotEmpty(importResult.getHandStatus())) {
  1382. if ("0".equals(importResult.getHandStatus())) {
  1383. params.put("isNotCar", "0");
  1384. } else if ("1".equals(importResult.getHandStatus())) {
  1385. params.put("isNotCar", "1");
  1386. }
  1387. }
  1388. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1389. if (!CollectionUtils.isEmpty(insPlyIncomes)) {
  1390. if (insPlyIncomeVo != null) { // 确保insPlyIncomeVo不是null
  1391. for (InsPlyIncome item : insPlyIncomes) {
  1392. item.setInvoicTime(LocalDate.now());
  1393. item.setInvoicId(insPlyIncomeVo.getInvoicId());
  1394. item.setHandlingFeesStatus("2");
  1395. if (StringUtils.isNotEmpty(item.getTaskId())) {
  1396. return HttpResult.error("该单据已经开票 ");
  1397. } else {
  1398. item.setTaskId(importResult.getId());
  1399. baseMapper.updateById(item);
  1400. }
  1401. }
  1402. }
  1403. }
  1404. }
  1405. insPlyIncomeVo.setNoInvoicCommissionFeevalue(importResult.getTotalAmount());
  1406. insPlyIncomeVo.setOtherFeevalue(importResult.getTotalAmount());
  1407. insPlyIncomeVo.setHandlingFeesStatus("0"); // 0手续费 1 跟单费
  1408. insPlyIncomeVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1409. insPlyIncomeVo.setAgreementId(importResult.getAgreementId());
  1410. insPlyIncomeVo.setPartnerCompaniesId(importResult.getPartnerCompaniesId());
  1411. insPlyIncomeVo.setSettlementAmount(importResult.getTotalAmount());
  1412. insPlyIncomeVo.setContractId(insPlyIncomeVo.getInvoicId());
  1413. insPlyIncomeVo.setCompanyId(importResult.getCompanyId());
  1414. insPlyIncomeVo.setTaskId(importResult.getId());
  1415. this.batchInvoic(insPlyIncomeVo);
  1416. return HttpResult.ok();
  1417. }
  1418. @Override
  1419. public HttpResult<InsPlyIncome> queryInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1420. HashMap<String, Object> params = new HashMap<>();
  1421. params = this.saveParams(insPlyIncomeVo, params);
  1422. InsPlyIncome result= baseMapper.queryInvoicing(params); //总金额
  1423. params.put("handlingFeesStatus","0");
  1424. InsPlyIncome noResult= baseMapper.queryInvoicing(params); //未结算金额
  1425. result.setReadyCommissionFeevalue(noResult.getCommissionFeevalue());
  1426. return HttpResult.ok(result);
  1427. }
  1428. @Override
  1429. public HttpResult<Object> batchBxBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1430. // 表内总金额
  1431. BigDecimal invoicCommissionFeevalue = insPlyIncomeVo.getInvoicCommissionFeevalue();
  1432. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  1433. HashMap<String, Object> params = new HashMap<>();
  1434. params = this.saveParams(insPlyIncomeVo,params);
  1435. params.put("handlingFeesStatus",insPlyIncomeVo.getHandlingFeesStatus());
  1436. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1437. for (InsPlyIncome item : insPlyIncomes){
  1438. if(settlementAmount.compareTo(invoicCommissionFeevalue) ==0){
  1439. item.setHandlingFeesStatus("1");
  1440. baseMapper.updateById(item);
  1441. }
  1442. }
  1443. // 分批结算
  1444. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  1445. String id = String.valueOf(new SnowFlakeUtil().nextId());
  1446. settlementDocumentaryFeesVo.setId(id);
  1447. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId()); //开票号
  1448. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1449. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1450. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId()); // 保险公司id
  1451. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1452. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1453. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1454. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1455. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1456. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1457. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
  1458. settlementDocumentaryFeesVo.setHandlingFeesStatus("0");
  1459. settlementDocumentaryFeesVo.setParentId(id);
  1460. settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1461. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1462. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1463. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1464. return HttpResult.ok();
  1465. }
  1466. private void changeHandStatus(String ids, InsPlyIncomeVo insPlyIncomeVo) {
  1467. String[] split = ids.split(",");
  1468. SettlementDocumentaryFeesEntity byId = settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
  1469. BigDecimal totalAmount = byId.getTotalAmount(); //开票总金额
  1470. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount(); //本次结算金额
  1471. //多次结算 表中已经结算的金额
  1472. SettlementDocumentaryFeesEntity settlementAmountEntity = settlementDocumentaryFeesService.getByParentSettlementAmount(insPlyIncomeVo.getId());
  1473. if(ObjectUtils.isNotEmpty(settlementAmountEntity)){
  1474. BigDecimal all = settlementAmount.add(settlementAmountEntity.getTotalAmount());
  1475. if(all.equals(totalAmount)){
  1476. baseMapper.updateByIds(split);
  1477. }
  1478. }
  1479. }
  1480. @Override
  1481. public HttpResult<InsPlyIncome> querySettInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1482. HashMap<String, Object> params = new HashMap<>();
  1483. params = this.saveParams(insPlyIncomeVo, params);
  1484. InsPlyIncome insPlyIncome = baseMapper.queryInvoicing(params); //已经开票
  1485. return HttpResult.ok(insPlyIncome);
  1486. }
  1487. /**
  1488. *
  1489. * @param insPlyIncomeVo
  1490. * @return
  1491. */
  1492. @Override
  1493. public HttpResult<List<InsPlyIncome>> allOtherAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1494. HashMap<String, Object> params = new HashMap<>();
  1495. params = this.saveParams(insPlyIncomeVo, params);
  1496. List<InsPlyIncome> result = baseMapper.allOtherAmount(params);
  1497. return HttpResult.ok(result);
  1498. }
  1499. @Override
  1500. @Transactional
  1501. public HttpResult<Object> batchInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  1502. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  1503. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1504. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  1505. }
  1506. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getMultipleSelection())){
  1507. InsPlyIncomeVo insPlyIncomeVo1 = insPlyIncomeVo.getMultipleSelection().get(0);
  1508. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo1.getSettlementAmount());
  1509. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo1.getAllTotalOtherFeevalue());
  1510. YearMonth yearMonth = YearMonth.parse(insPlyIncomeVo1.getMonthYear());
  1511. LocalDate signingTime = yearMonth.atDay(1);
  1512. settlementDocumentaryFeesVo.setSigningTime(signingTime);
  1513. }
  1514. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1515. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  1516. }
  1517. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  1518. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  1519. }
  1520. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDay())){
  1521. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  1522. }
  1523. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  1524. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1525. settlementDocumentaryFeesVo.setAgreementId(insPlyIncomeVo.getAgreementId());
  1526. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  1527. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  1528. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  1529. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1530. settlementDocumentaryFeesVo.setSettlementStatus("1");
  1531. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1532. if(StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())){
  1533. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  1534. }
  1535. if(StringUtils.isNotEmpty(insPlyIncomeVo.getTaskId())){
  1536. settlementDocumentaryFeesVo.setTaskId(insPlyIncomeVo.getTaskId());
  1537. }
  1538. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1539. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1540. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1541. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
  1542. // 税点支出
  1543. if( "0".equals(insPlyIncomeVo.getInvoicingMethod()) && BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) !=null && insPlyIncomeVo.getTaxPoints().compareTo(BigDecimal.ZERO) != 0 && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) !=null){
  1544. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  1545. settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1546. }else {
  1547. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount());
  1548. }
  1549. return settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1550. }
  1551. @Override
  1552. public HttpResult pinHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1553. HashMap<String, Object> params = new HashMap<>();
  1554. params =this.saveParams(insPlyIncomeVo,params);
  1555. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1556. ExportParams exportParams = new ExportParams("平台手续费", null, ExcelType.HSSF);
  1557. exportParams.setStyle(ExcelStyleUtil.class);
  1558. List<SettlementFeesExcel> resultList = new ArrayList<>();
  1559. for (InsPlyIncome item :insPlyIncomes){
  1560. SettlementFeesExcel bxSettlementFeesExcel = new SettlementFeesExcel();
  1561. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1562. if("1".equals(item.getHandlingFeesStatus())){
  1563. bxSettlementFeesExcel.setHandlingFeesStatus("已结算");
  1564. }else {
  1565. bxSettlementFeesExcel.setHandlingFeesStatus("未结算");
  1566. }
  1567. resultList.add(bxSettlementFeesExcel);
  1568. }
  1569. String uploadPath = this.uploadPath + "/excel/";
  1570. Path path = Paths.get(uploadPath);
  1571. if (!Files.exists(path)) {
  1572. try {
  1573. Files.createDirectories(path);
  1574. } catch (IOException e) {
  1575. e.printStackTrace();
  1576. }
  1577. }
  1578. String fileName = EasyExcelUtils.downExcel(uploadPath, "平台手续费导出", SettlementFeesExcel.class, resultList);
  1579. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1580. }
  1581. @Override
  1582. public HttpResult bxHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1583. HashMap<String, Object> params = new HashMap<>();
  1584. params =this.saveParams(insPlyIncomeVo,params);
  1585. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1586. String filePathName ="";
  1587. List<BxSettlementFeesNorExcel> resultNoList=new ArrayList<>();
  1588. List<BxSettlementFeesExcel> resultList=new ArrayList<>();
  1589. //判断是否是非车 1 是非车
  1590. if("1".equals(insPlyIncomeVo.getIsNotCar())){
  1591. filePathName="非车手续费导出";
  1592. ExportParams exportParams = new ExportParams("非车手续费", null, ExcelType.HSSF);
  1593. exportParams.setStyle(ExcelStyleUtil.class);
  1594. for (InsPlyIncome item :insPlyIncomes){
  1595. BxSettlementFeesNorExcel bxSettlementFeesNorExcel = new BxSettlementFeesNorExcel();
  1596. LocalDateTime signDate = item.getSignDate();
  1597. BeanUtils.copyProperties(item, bxSettlementFeesNorExcel);
  1598. bxSettlementFeesNorExcel.setSigndate(signDate);
  1599. resultNoList.add(bxSettlementFeesNorExcel);
  1600. }
  1601. }else{
  1602. filePathName="车险手续费导出";
  1603. ExportParams exportParams = new ExportParams("车险手续费", null, ExcelType.HSSF);
  1604. exportParams.setStyle(ExcelStyleUtil.class);
  1605. for (InsPlyIncome item :insPlyIncomes){
  1606. BxSettlementFeesExcel bxSettlementFeesExcel = new BxSettlementFeesExcel();
  1607. LocalDateTime signDate = item.getSignDate();
  1608. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1609. bxSettlementFeesExcel.setSigndate(signDate);
  1610. resultList.add(bxSettlementFeesExcel);
  1611. }
  1612. }
  1613. String uploadPath = this.uploadPath + "/excel/";
  1614. Path path = Paths.get(uploadPath);
  1615. if (!Files.exists(path)) {
  1616. try {
  1617. Files.createDirectories(path);
  1618. } catch (IOException e) {
  1619. e.printStackTrace();
  1620. }
  1621. }
  1622. String fileName="";
  1623. if("1".equals(insPlyIncomeVo.getIsNotCar())){
  1624. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxSettlementFeesNorExcel.class, resultNoList);
  1625. }else{
  1626. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxSettlementFeesExcel.class, resultList);
  1627. }
  1628. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1629. }
  1630. @Override
  1631. public HttpResult bxOtherExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1632. HashMap<String, Object> params = new HashMap<>();
  1633. params =this.saveParams(insPlyIncomeVo,params);
  1634. params.put("agreementType","2");
  1635. params.put("isOther","1");
  1636. params.put("isNotCar","0");
  1637. List<InsPlyIncome> insPlyIncomes = baseMapper.allOtherAmount(params);
  1638. ExportParams exportParams = new ExportParams("跟单费导出", null, ExcelType.HSSF);
  1639. exportParams.setStyle(ExcelStyleUtil.class);
  1640. List<BxOtherExcel> resultList = new ArrayList<>();
  1641. for (InsPlyIncome item :insPlyIncomes){
  1642. BxOtherExcel bxSettlementFeesExcel = new BxOtherExcel();
  1643. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1644. resultList.add(bxSettlementFeesExcel);
  1645. }
  1646. String uploadPath = this.uploadPath + "/excel/";
  1647. Path path = Paths.get(uploadPath);
  1648. if (!Files.exists(path)) {
  1649. try {
  1650. Files.createDirectories(path);
  1651. } catch (IOException e) {
  1652. e.printStackTrace();
  1653. }
  1654. }
  1655. String fileName = EasyExcelUtils.downExcel(uploadPath, "跟单费导出", BxOtherExcel.class, resultList);
  1656. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1657. }
  1658. @Override
  1659. public InsPlyIncome bxTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1660. HashMap<String, Object> params = new HashMap<>();
  1661. params = this.saveParams(insPlyIncomeVo, params);
  1662. InsPlyIncome totalledAmount =baseMapper.bxTotalAmount(params); //总金额
  1663. return totalledAmount;
  1664. }
  1665. @Override
  1666. public InsPlyIncome ptTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1667. HashMap<String, Object> params = new HashMap<>();
  1668. params = this.saveParams(insPlyIncomeVo, params);
  1669. params.remove("handlingFeesStatus");
  1670. InsPlyIncome totalledAmount =baseMapper.ptTotalAmount(params); //总金额
  1671. return totalledAmount;
  1672. }
  1673. @Override
  1674. public HttpResult<List<HashMap<String,Object>>> otherTimeDetail(InsPlyIncomeVo insPlyIncomeVo) {
  1675. HashMap<String, Object> params = new HashMap<>();
  1676. this.saveParams(insPlyIncomeVo,params);
  1677. List<HashMap<String,Object>> resultMap=baseMapper.otherTimeDetail(params);
  1678. Set<String> uniqueYears = new HashSet<>();
  1679. for (Map<String, Object> map : resultMap) {
  1680. // 假设年份是以 "year" 为键的,并且它的值是 String 类型
  1681. String year = String.valueOf(map.get("year")) ;
  1682. if (year != null) { // 确保年份不是 null
  1683. uniqueYears.add(year);
  1684. }
  1685. }
  1686. this.addMonthYear(uniqueYears,resultMap);
  1687. return HttpResult.ok(resultMap);
  1688. }
  1689. /**
  1690. * uniqueYears 年份间隔 resultMap 返回结果
  1691. * @param uniqueYears
  1692. * @param resultMap 返回一到十二月数据
  1693. */
  1694. private void addMonthYear(Set<String> uniqueYears, List<HashMap<String, Object>> resultMap) {
  1695. // 存储已存在的年份-月份组合,以便快速查找
  1696. Set<String> existingYearMonths = new HashSet<>();
  1697. for (Map<String, Object> entry : resultMap) {
  1698. String year = String.valueOf(entry.get("year")) ;
  1699. int month = (Integer) entry.get("monthNumber");
  1700. existingYearMonths.add(year + "-" + month);
  1701. }
  1702. // 遍历所有年份和月份,并添加缺失的条目
  1703. for (String year : uniqueYears) {
  1704. for (int month = 1; month <= 12; month++) {
  1705. String yearMonth = year + "-" + month;
  1706. if (!existingYearMonths.contains(yearMonth)) {
  1707. // 创建一个新的条目并添加到resultMap中
  1708. HashMap<String, Object> newEntry = new HashMap<>();
  1709. newEntry.put("year", year);
  1710. newEntry.put("monthNumber", month);
  1711. newEntry.put("allTotalOtherFeevalue", 0);
  1712. newEntry.put("invoicCommissionFeevalue", 0);
  1713. newEntry.put("monthYear", yearMonth);
  1714. newEntry.put("noInvoicCommissionFeevalue", 0);
  1715. resultMap.add(newEntry);
  1716. }
  1717. }
  1718. }
  1719. // 使用自定义Comparator对resultMap进行排序
  1720. Collections.sort(resultMap, new Comparator<HashMap<String, Object>>() {
  1721. @Override
  1722. public int compare(HashMap<String, Object> o1, HashMap<String, Object> o2) {
  1723. // 比较 year
  1724. String year1 = String.valueOf(o1.get("year")) ;
  1725. String year2 =String.valueOf(o2.get("year"));
  1726. int yearComparison = year1.compareTo(year2);
  1727. if (yearComparison != 0) {
  1728. return yearComparison;
  1729. }
  1730. // 如果 year 相同,则比较 monthNumber
  1731. Integer monthNum1 = (Integer) o1.get("monthNumber");
  1732. Integer monthNum2 = (Integer) o2.get("monthNumber");
  1733. return monthNum1.compareTo(monthNum2);
  1734. }
  1735. });
  1736. }
  1737. @Override
  1738. public HttpResult<Object> singleInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  1739. // 通过ids 查出跟单非结算单
  1740. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  1741. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getMultipleSelection())) {
  1742. for (InsPlyIncomeVo insPlyIncomeVo1 : insPlyIncomeVo.getMultipleSelection()) {
  1743. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo1.getSettlementAmount());
  1744. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo1.getAllTotalOtherFeevalue());
  1745. YearMonth yearMonth = YearMonth.parse(insPlyIncomeVo1.getMonthYear());
  1746. LocalDate signingTime = yearMonth.atDay(1);
  1747. settlementDocumentaryFeesVo.setSigningTime(signingTime);
  1748. }
  1749. }
  1750. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1751. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  1752. }
  1753. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1754. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  1755. }
  1756. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  1757. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  1758. }
  1759. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDay())) {
  1760. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  1761. }
  1762. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  1763. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1764. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  1765. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  1766. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  1767. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1768. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIncomeIds());
  1769. settlementDocumentaryFeesVo.setSettlementStatus("1");
  1770. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1771. if (StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())) {
  1772. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  1773. }
  1774. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1775. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1776. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1777. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
  1778. settlementDocumentaryFeesVo.setSigningTime(insPlyIncomeVo.getSettlementTime()); //签单日期
  1779. // 税点支出
  1780. if (BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) != null && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) != null) {
  1781. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  1782. settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1783. }
  1784. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1785. return HttpResult.ok();
  1786. }
  1787. @Override
  1788. public void batchUpdate(InsPlyIncomeVo insPlyIncomeVo) {
  1789. HashMap<String, Object> params = new HashMap<>();
  1790. params= this.saveParams(insPlyIncomeVo,params);
  1791. List<InsPlyIncome> list= this.baseMapper.queryNew(params);
  1792. for ( InsPlyIncome item : list){
  1793. item.setContractFileId( insPlyIncomeVo.getContractFileId());
  1794. item.setSettleOtherStatus("1");
  1795. baseMapper.updateById(item);
  1796. }
  1797. }
  1798. @Override
  1799. @Transactional
  1800. public HashMap<String, Object> bxImportOther(MultipartFile multipartFile,String isNotCar) {
  1801. HashMap<String, Object> resultMap = new HashMap<>();
  1802. List<HashMap<String,Object>> resultList=new ArrayList<>();
  1803. HashMap<String, Object> params = new HashMap<>();
  1804. BigDecimal allAmount = BigDecimal.ZERO;
  1805. params.put("isNotCar",isNotCar);
  1806. try {
  1807. List<InsBxOtherExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxOtherExcelDto.class, 0, 1, 1);
  1808. for (InsBxOtherExcelDto item : dtoList){
  1809. if(StringUtils.isNotEmpty(item.getLicenseno())){
  1810. params.put("licenseno",item.getLicenseno());
  1811. }
  1812. if(StringUtils.isNotEmpty(item.getPolicyno())){
  1813. params.put("policyno",item.getPolicyno());
  1814. }
  1815. if(StringUtils.isNotEmpty(item.getSyPolicyno())){
  1816. params.put("syPolicyno",item.getSyPolicyno());
  1817. }
  1818. params.put("handlingFeesStatus","0");
  1819. // isOther
  1820. params.put("isOther","1");
  1821. params.put("isNotCar","0");
  1822. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  1823. if (item.getJqOtherCostsProportion() ==null){
  1824. item.setJqOtherCostsProportion(BigDecimal.ZERO);
  1825. }
  1826. if(item.getSyOtherCostsProportion() == null){
  1827. item.setSyOtherCostsProportion(BigDecimal.ZERO);
  1828. }
  1829. if(byBxLicenseno.getJqOtherCostsProportion().compareTo(item.getJqOtherCostsProportion()) !=0 || byBxLicenseno.getSyOtherCostsProportion().compareTo(item.getSyOtherCostsProportion()) != 0){
  1830. // 如果比例不相等
  1831. BigDecimal jqOtherCostsProportion = item.getJqOtherCostsProportion();
  1832. BigDecimal syOtherCostsProportion = item.getSyOtherCostsProportion();
  1833. BigDecimal divisor = new BigDecimal("1.06"); // 最好是使用字符串来避免精度损失
  1834. BigDecimal jqNoTaxPremium = byBxLicenseno.getJqPremium().divide(divisor, 5, RoundingMode.HALF_UP);//交强保费 / 1.06
  1835. BigDecimal syNoTaxPremium = byBxLicenseno.getSyPremium().divide(divisor, 5, RoundingMode.HALF_UP);// 商业 保费 /1.06
  1836. BigDecimal jqOtherAmount = jqNoTaxPremium.multiply(item.getJqOtherCostsProportion().divide(new BigDecimal(100))); //交强跟单费用
  1837. BigDecimal syOtherAmount = syNoTaxPremium.multiply(item.getSyOtherCostsProportion().divide(new BigDecimal(100)));
  1838. byBxLicenseno.setJqOtherCostsPremium(jqOtherAmount);
  1839. byBxLicenseno.setSyOtherCostsPremium(syOtherAmount);
  1840. byBxLicenseno.setJqOtherCostsProportion(jqOtherCostsProportion);
  1841. byBxLicenseno.setSyOtherCostsProportion(syOtherCostsProportion);
  1842. byBxLicenseno.setOtherFeevalue(this.calculateTotal(jqOtherAmount,syOtherAmount,null));
  1843. byBxLicenseno.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion,syOtherCostsProportion ,null));
  1844. byBxLicenseno.setAllFeeValue(this.calculateTotal(jqOtherAmount,syOtherAmount,null));
  1845. baseMapper.updateById(byBxLicenseno);
  1846. HashMap<String, Object> map = new HashMap<>();
  1847. map.put("licenseno",item.getLicenseno());
  1848. map.put("policyno",item.getPolicyno());
  1849. map.put("syPolicyno",item.getSyPolicyno());
  1850. map.put("jqOtherCostsPremium",jqOtherAmount);
  1851. map.put("syOtherCostsPremium",syOtherAmount);
  1852. map.put("otherFeevalue",byBxLicenseno.getOtherFeevalue());
  1853. map.put("otherFeerate",byBxLicenseno.getOtherFeerate());
  1854. resultList.add(map);
  1855. allAmount = allAmount.add(jqOtherAmount).add(syOtherAmount);
  1856. }
  1857. }
  1858. resultMap.put("allAmount",allAmount);
  1859. resultMap.put("resultList",resultList);
  1860. } catch (IOException e) {
  1861. throw new RuntimeException(e);
  1862. }
  1863. return resultMap;
  1864. }
  1865. @Override
  1866. @Transactional
  1867. public HashMap<String, Object> noBxImportOther(MultipartFile multipartFile, String isNotCar) {
  1868. HashMap<String, Object> resultMap = new HashMap<>();
  1869. List<HashMap<String,Object>> resultList=new ArrayList<>();
  1870. HashMap<String, Object> params = new HashMap<>();
  1871. BigDecimal allAmount = BigDecimal.ZERO;
  1872. params.put("isNotCar",isNotCar);
  1873. try {
  1874. List<InsNoBxOtherExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsNoBxOtherExcelDto.class, 0, 1, 1);
  1875. for (InsNoBxOtherExcelDto item : dtoList){
  1876. if(StringUtils.isNotEmpty(item.getLicenseno())){
  1877. params.put("licenseno",item.getLicenseno());
  1878. }
  1879. if(StringUtils.isNotEmpty(item.getNoPolicyno())){
  1880. params.put("noPolicyno",item.getNoPolicyno());
  1881. }
  1882. params.put("handlingFeesStatus","0");
  1883. params.put("isNotCar","1");
  1884. params.put("isOther","1");
  1885. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  1886. if(byBxLicenseno.getNoOtherCostsProportion().compareTo(item.getNoOtherCostsProportion()) !=0 ){
  1887. // 如果比例不相等
  1888. BigDecimal noOtherCostsProportion = item.getNoOtherCostsProportion();
  1889. BigDecimal noNoTaxPremium = byBxLicenseno.getNoNoTaxPremium();
  1890. BigDecimal noOtherAmount = noNoTaxPremium.multiply(item.getNoOtherCostsProportion().divide(new BigDecimal(100))); //交强跟单费用
  1891. byBxLicenseno.setOtherFeevalue(this.calculateTotal(noOtherAmount,null,null));
  1892. byBxLicenseno.setOtherFeerate(this.calculateTotal(noOtherCostsProportion,null ,null));
  1893. baseMapper.updateById(byBxLicenseno);
  1894. resultMap.put("licenseno",item.getLicenseno());
  1895. resultMap.put("noPolicyno",item.getNoPolicyno());
  1896. resultMap.put("noOtherCostsPremium",noOtherAmount);
  1897. resultMap.put("otherFeevalue",byBxLicenseno.getOtherFeevalue());
  1898. resultMap.put("otherFeerate",byBxLicenseno.getOtherFeerate());
  1899. resultList.add(resultMap);
  1900. allAmount = allAmount.add(noOtherAmount);
  1901. }
  1902. }
  1903. resultMap.put("allAmount",allAmount);
  1904. } catch (IOException e) {
  1905. throw new RuntimeException(e);
  1906. }
  1907. return resultMap;
  1908. }
  1909. @Override
  1910. public void batchUpdateVoucher(InsPlyIncomeVo insPlyIncomeVo) {
  1911. String s = insPlyIncomeVo.getSelectIds().get(0);
  1912. ImportResult importResult = importAsyncService.getById(s);
  1913. String[] split = importResult.getIds().split(",");
  1914. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1915. for (String id :split){
  1916. insPlyIncome.setId(id);
  1917. insPlyIncome.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1918. insPlyIncome.setSettleOtherStatus("1");
  1919. baseMapper.updateById(insPlyIncome);
  1920. }
  1921. }
  1922. /**
  1923. * 通过任务id 去查询关联表
  1924. * @param insPlyIncomeVo
  1925. * @return
  1926. */
  1927. @Override
  1928. public HttpResult<Object> reconciliation(InsPlyIncomeVo insPlyIncomeVo) {
  1929. String taskId = insPlyIncomeVo.getTaskId();
  1930. List<String> incomeIdList = incomeTaskRelationshipService.getByTaskId(taskId);
  1931. for (String incomeId :incomeIdList){
  1932. InsPlyIncome insPlyIncome = baseMapper.getById(incomeId);
  1933. insPlyIncome.setSettleOtherStatus("1");
  1934. insPlyIncome.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1935. baseMapper.updateById(insPlyIncome);
  1936. }
  1937. return HttpResult.ok();
  1938. }
  1939. }