InsPlyIncomeServiceImpl.java 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499
  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 cn.hutool.core.bean.BeanUtil;
  5. import cn.hutool.core.text.StrBuilder;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.fasterxml.jackson.core.JsonProcessingException;
  9. import com.fasterxml.jackson.databind.JsonNode;
  10. import com.fasterxml.jackson.databind.ObjectMapper;
  11. import com.github.pagehelper.PageHelper;
  12. import com.github.pagehelper.PageInfo;
  13. import com.ydtech.constants.enums.dict.agreement.ProductsType;
  14. import com.ydtech.core.page.HttpResult;
  15. import com.ydtech.exception.SystemException;
  16. import com.ydtech.modules.esm.model.EsmInsCompany;
  17. import com.ydtech.modules.esm.service.EsmInsCompanyService;
  18. import com.ydtech.modules.fnc.entity.InsAreaCompany;
  19. import com.ydtech.modules.fnc.entity.InsPlyIncome;
  20. import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
  21. import com.ydtech.modules.fnc.entity.SettlementDocumentaryFeesEntity;
  22. import com.ydtech.modules.fnc.entity.SettlementDocumentaryLogEntity;
  23. import com.ydtech.modules.fnc.service.InsPlyIncomeService;
  24. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  25. import com.ydtech.modules.fnc.service.SettlementDocumentaryFeesService;
  26. import com.ydtech.modules.fnc.service.SettlementDocumentaryLogService;
  27. import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
  28. import com.ydtech.modules.fnc.vo.SettlementDocumentaryFeesVo;
  29. import com.ydtech.modules.ins.model.vo.res.*;
  30. import com.ydtech.modules.inv.model.InvChannelsExternalBillsDetails;
  31. import com.ydtech.modules.inv.model.dto.InsBxNoPlyIncomeExcelDto;
  32. import com.ydtech.modules.inv.model.dto.InsBxPlyIncomeExcelDto;
  33. import com.ydtech.modules.inv.model.dto.InsPlyIncomeExcelDto;
  34. import com.ydtech.modules.inv.model.dto.InvChannelExcelDto;
  35. import com.ydtech.modules.inv.model.excel.InvDisburseExcel;
  36. import com.ydtech.modules.inv.utils.EasyExcelUtils;
  37. import com.ydtech.modules.order.entity.BasePageResult;
  38. import com.ydtech.modules.order.entity.InsOrders;
  39. import com.ydtech.modules.order.service.InsAreaCompanyService;
  40. import com.ydtech.modules.order.service.InsOrdersService;
  41. import com.ydtech.modules.protocol.entity.po.PtlAgreement;
  42. import com.ydtech.modules.protocol.entity.vo.PtlAgreementQueryVo;
  43. import com.ydtech.modules.protocol.service.PtlAgreementService;
  44. import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
  45. import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
  46. import com.ydtech.utils.SnowFlakeUtil;
  47. import com.ydtech.utils.excel.ExcelEasypoiUtils;
  48. import com.ydtech.utils.excel.ExcelStyleUtil;
  49. import com.ydtech.utils.excel.ExcelUtils2;
  50. import lombok.extern.slf4j.Slf4j;
  51. import org.apache.commons.lang3.ObjectUtils;
  52. import org.apache.commons.lang3.StringUtils;
  53. import org.apache.poi.ss.formula.functions.Now;
  54. import org.springframework.beans.BeanUtils;
  55. import org.springframework.beans.factory.annotation.Autowired;
  56. import org.springframework.beans.factory.annotation.Value;
  57. import org.springframework.context.annotation.Lazy;
  58. import org.springframework.stereotype.Service;
  59. import org.springframework.transaction.annotation.Transactional;
  60. import org.springframework.util.CollectionUtils;
  61. import org.springframework.web.multipart.MultipartFile;
  62. import redis.clients.jedis.params.Params;
  63. import javax.servlet.http.HttpServletRequest;
  64. import javax.servlet.http.HttpServletResponse;
  65. import java.awt.image.BandedSampleModel;
  66. import java.io.IOException;
  67. import java.math.BigDecimal;
  68. import java.nio.file.Files;
  69. import java.nio.file.Path;
  70. import java.nio.file.Paths;
  71. import java.time.LocalDate;
  72. import java.time.LocalDateTime;
  73. import java.util.*;
  74. import java.util.stream.Collectors;
  75. /**
  76. * <p>
  77. * 保司结算手续费 服务实现类
  78. * </p>
  79. *
  80. * @author gws
  81. * @since 2024-01-05
  82. */
  83. @Slf4j
  84. @Service
  85. public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, InsPlyIncome> implements InsPlyIncomeService {
  86. @Autowired
  87. @Lazy
  88. private InsOrdersService insOrdersService;
  89. @Autowired
  90. private InsAreaCompanyService insAreaCompanyService;
  91. @Autowired
  92. private InsFeeOrderNewService insFeeOrderNewService;
  93. @Autowired
  94. private SettlementDocumentaryFeesService settlementDocumentaryFeesService;
  95. @Autowired
  96. private SettlementDocumentaryLogService settlementDocumentaryLogService;
  97. @Autowired
  98. private PtlAgreementService ptlAgreementService;
  99. @Autowired
  100. private EsmInsCompanyService EsmInsCompanyService;
  101. @Value("${upload.file.path}")
  102. private String uploadPath;
  103. @Value("${upload.file.url}")
  104. private String uploadUrl;
  105. public HttpResult<BasePageResult<InsPlyIncome>> queryplyIncome(InsPlyIncomeVo insPlyIncomeVo){
  106. try{
  107. Page<InsOrders> page = new Page<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  108. PageInfo<List<InsPlyIncome>> pageHelper = null;
  109. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  110. List<InsPlyIncome> list= this.baseMapper.selectByCondition(insPlyIncomeVo);
  111. pageHelper=new PageInfo(list);
  112. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  113. return HttpResult.ok(pageResult);
  114. }catch (Exception e){
  115. e.printStackTrace();
  116. return HttpResult.error("查询异常");
  117. }
  118. }
  119. @Override
  120. public void saveBalanceNew(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  121. if (ObjectUtils.isEmpty(order) || ObjectUtils.isEmpty(insFeeOrderNew) || ObjectUtils.isEmpty(insAreaCompany)) {
  122. return;
  123. }
  124. String agreeType = this.judgeAgreeType(insAreaCompany.getAgreementId());
  125. if (StringUtils.isNotEmpty(agreeType)) {
  126. // 判断协议类型 平台 保险
  127. if ("1".equals(agreeType)) {
  128. this.savePinTai(order,insFeeOrderNew,insAreaCompany); //手续费不分非车不非车 跟单也不分
  129. }else { // 保险 逻辑: 手续费生成一条 跟单费生成一条 非车手续费一条 非车跟单费一条
  130. if (((insFeeOrderNew.getJqSuperviseCostsPremiums() != null && insFeeOrderNew.getJqSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0)) || (insFeeOrderNew.getSySuperviseCostsPremiums() != null && insFeeOrderNew.getSySuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0)) { //手续费
  131. this.saveInsuranceProcedures(order,insFeeOrderNew,insAreaCompany);
  132. }
  133. if(insFeeOrderNew.getJqOtherCostsPremiums()!=null && insFeeOrderNew.getJqOtherCostsPremiums().compareTo(BigDecimal.ZERO) != 0){ //跟单费
  134. this.saveOtherAmount(order,insFeeOrderNew,insAreaCompany);
  135. }
  136. if(insFeeOrderNew.getNoSuperviseCostsPremiums() !=null && insFeeOrderNew.getNoSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { // 非车手续费
  137. this.saveNoSupervise(order,insFeeOrderNew,insAreaCompany);
  138. }
  139. if(insFeeOrderNew.getNoOtherCostsPremiums() !=null && insFeeOrderNew.getNoOtherCostsPremiums().compareTo(BigDecimal.ZERO) != 0){ // 非车跟单费
  140. this.saveNoOtherAmount(order,insFeeOrderNew,insAreaCompany);
  141. }
  142. }
  143. }
  144. }
  145. private void saveNoOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  146. InsPlyIncome insPlyIncome = new InsPlyIncome();
  147. insPlyIncome.setOrderno(insFeeOrderNew.getId()); // 子订单号
  148. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  149. if(StringUtils.isNotEmpty(noPolicyno)){
  150. insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
  151. }
  152. insPlyIncome.setOtherFeevalue(insFeeOrderNew.getNoOtherCostsPremiums()); //非车跟单费
  153. insPlyIncome.setOtherFeerate(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费用比例
  154. insPlyIncome.setDeptId(insFeeOrderNew.getDeptId());
  155. this.saveRiskCode(order.getProductid(),insPlyIncome);
  156. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  157. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  158. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  159. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  160. insPlyIncome.setLicenseno(order.getLicenseno());
  161. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  162. insPlyIncome.setCreateTime(LocalDate.now());
  163. insPlyIncome.setDocumentaryFeesStatus("0");
  164. insPlyIncome.setHandlingFeesStatus("0");
  165. insPlyIncome.setNoNoTaxPremium(insPlyIncome.getNoNoTaxPremium());
  166. insPlyIncome.setNoPremium(insPlyIncome.getNoPremium());
  167. insPlyIncome.setIsNotCar("1");
  168. insPlyIncome.setIsNotDocumentary("1");
  169. insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoOtherCostsPremiums());
  170. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  171. baseMapper.insert(insPlyIncome);
  172. }
  173. private void saveNoSupervise(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  174. InsPlyIncome insPlyIncome = new InsPlyIncome();
  175. insPlyIncome.setOrderno(insFeeOrderNew.getId()); // 子订单号
  176. insPlyIncome.setCommissionFeevalue(insFeeOrderNew.getNoSuperviseCostsPremiums());// 非车手续费
  177. insPlyIncome.setCommissionFeerate(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费比例
  178. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  179. if(StringUtils.isNotEmpty(noPolicyno)){
  180. insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
  181. }
  182. insPlyIncome.setDeptId(insFeeOrderNew.getDeptId());
  183. this.saveRiskCode(order.getProductid(),insPlyIncome);
  184. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  185. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  186. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  187. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  188. insPlyIncome.setLicenseno(order.getLicenseno());
  189. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  190. insPlyIncome.setCreateTime(LocalDate.now());
  191. insPlyIncome.setDocumentaryFeesStatus("0");
  192. insPlyIncome.setHandlingFeesStatus("0");
  193. insPlyIncome.setIsNotCar("1");
  194. insPlyIncome.setIsNotDocumentary("0");
  195. insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoSuperviseCostsPremiums());
  196. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  197. insPlyIncome.setInsuredName(order.getInsuredname());
  198. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium()); //非车保费
  199. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium()); //非车不含税保费
  200. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  201. baseMapper.insert(insPlyIncome);
  202. }
  203. private void saveRiskCode(String productid,InsPlyIncome insPlyIncome) {
  204. if(ProductsType.PT_0330.getCode().equals(productid)){
  205. insPlyIncome.setRiskcode(ProductsType.PT_0330.getDesc());
  206. }
  207. if(ProductsType.PT_034001.getCode().equals(productid)){
  208. insPlyIncome.setRiskcode(ProductsType.PT_034001.getDesc());
  209. }
  210. if(ProductsType.PT_034002.getCode().equals(productid)){
  211. insPlyIncome.setRiskcode(ProductsType.PT_034002.getDesc());
  212. }
  213. if(ProductsType.PT_0330034002.getCode().equals(productid)){
  214. insPlyIncome.setRiskcode(ProductsType.PT_0330034002.getDesc());
  215. }
  216. if(ProductsType.PT_0330034001.getCode().equals(productid)){
  217. insPlyIncome.setRiskcode(ProductsType.PT_0330034001.getDesc());
  218. }
  219. }
  220. private void saveOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  221. BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),null);
  222. BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(), insFeeOrderNew.getJqOtherCostsProportion(),null);
  223. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null); //交强不含税保费
  224. BigDecimal allPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);// 总保费
  225. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getId(),insAreaCompany.getJqpolicyno(),insAreaCompany.getSypolicyno(),null,null,insFeeOrderNew.getDeptId(),null,order.getProductid(),insAreaCompany.getPayDate(),insAreaCompany.getSigningTime(),insAreaCompany.getCompanyId(),null,insFeeOrderNew.getAgreementId(),order.getLicenseno(),insAreaCompany.getTaxamount(),
  226. allNoTaxPremium,null,otherProportion,null,otherAmount,otherAmount,null,null,LocalDate.now(),null,null,null,"0","0","0","1");
  227. this.saveRiskCode(order.getProductid(),insPlyIncome);
  228. insPlyIncome.setTaxPremium(allPremium);
  229. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  230. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  231. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  232. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  233. insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
  234. insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
  235. insPlyIncome.setSyOtherCostsPremium(insFeeOrderNew.getSyOtherCostsPremiums());
  236. insPlyIncome.setJqOtherCostsPremium(insFeeOrderNew.getJqOtherCostsPremiums());
  237. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  238. insPlyIncome.setInsuredName(order.getInsuredname());
  239. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  240. baseMapper.insert(insPlyIncome);
  241. }
  242. private void saveInsuranceProcedures(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  243. // 保险手续费
  244. BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(), insFeeOrderNew.getSySuperviseCostsPremiums(),null);
  245. BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(), insFeeOrderNew.getSySuperviseCostsProportion(),null);
  246. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null);//不含税保费
  247. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getId(),insAreaCompany.getJqpolicyno(),insAreaCompany.getSypolicyno(),null,null,insFeeOrderNew.getDeptId(),null,order.getProductid(),insAreaCompany.getPayDate(),insAreaCompany.getSigningTime(),insAreaCompany.getCompanyId(),null,insFeeOrderNew.getAgreementId(),order.getLicenseno(),insAreaCompany.getTaxamount()
  248. ,allNoTaxPremium,handlingProportion,null,handlingAmount,null,handlingAmount,null,null,LocalDate.now(),null,null,null,"0","0","0","0");
  249. BigDecimal allTaxPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);
  250. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  251. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  252. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  253. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  254. insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion());
  255. insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums());
  256. insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion());
  257. insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums());
  258. this.saveRiskCode(order.getProductid(),insPlyIncome);
  259. insPlyIncome.setTaxPremium(allTaxPremium);
  260. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  261. insPlyIncome.setInsuredName(order.getInsuredname());
  262. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  263. baseMapper.insert(insPlyIncome);
  264. }
  265. private String setNoPolicyno(com.ydtech.modules.fnc.entity.InsAreaCompany insAreaCompany) {
  266. String crossInsurance = insAreaCompany.getCrossInsurance();
  267. if (StringUtils.isEmpty(crossInsurance)) {
  268. return null;
  269. }
  270. try {
  271. ObjectMapper objJson = new ObjectMapper();
  272. JsonNode jsonArryNode = objJson.readTree(crossInsurance);
  273. if (jsonArryNode.isArray() && jsonArryNode.size() > 0) {
  274. JsonNode firstNode = jsonArryNode.get(0);
  275. JsonNode policyNumberNode = firstNode.get("policyNumber");
  276. if (policyNumberNode != null) {
  277. return policyNumberNode.asText();
  278. } else {
  279. return firstNode.get("policy").asText();
  280. }
  281. }
  282. } catch (IOException e) {
  283. e.printStackTrace(); // 可以打印异常信息
  284. }
  285. return null;
  286. }
  287. private void savePinTai(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  288. BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(), insFeeOrderNew.getSySuperviseCostsPremiums(),insFeeOrderNew.getNoSuperviseCostsPremiums()); //手续费
  289. BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(), insFeeOrderNew.getSySuperviseCostsProportion(),insFeeOrderNew.getNoSuperviseCostsProportion());//手续费比例
  290. BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),insFeeOrderNew.getNoOtherCostsPremiums());//跟单费
  291. BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(), insFeeOrderNew.getJqOtherCostsProportion(),insFeeOrderNew.getNoOtherCostsProportion()); //跟单费比例
  292. // 不含税保费
  293. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), insFeeOrderNew.getNoNoTaxPremium());
  294. BigDecimal allAmount = this.calculateTotal(otherAmount, handlingAmount, null);
  295. BigDecimal jqReceivableProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(), insFeeOrderNew.getNoSuperviseCostsProportion(), null);// 交强应收 比例
  296. BigDecimal syReceivableProportion = this.calculateTotal(insFeeOrderNew.getSySuperviseCostsProportion(), insFeeOrderNew.getSyOtherCostsProportion(), null);//商业应收比例
  297. BigDecimal noReceivableProportion = this.calculateTotal(insFeeOrderNew.getNoSuperviseCostsProportion(), insFeeOrderNew.getNoOtherCostsProportion(), null);
  298. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  299. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getId(),insAreaCompany.getJqpolicyno(),insAreaCompany.getSypolicyno(),
  300. noPolicyno,null,insFeeOrderNew.getDeptId(), null,order.getProductid(),insAreaCompany.getPayDate(),insAreaCompany.getSigningTime(),insAreaCompany.getCompanyId(),
  301. null,insFeeOrderNew.getAgreementId(),order.getLicenseno(),insAreaCompany.getTaxamount(),allNoTaxPremium,handlingProportion,
  302. otherProportion,handlingAmount,otherAmount,allAmount,null,null,LocalDate.now(),null,null,null,"0","0","0","0");
  303. insPlyIncome.setJqReceivableProportion(jqReceivableProportion);
  304. insPlyIncome.setSyReceivableProportion(syReceivableProportion);
  305. insPlyIncome.setNoReceivableProportion(noReceivableProportion);
  306. // 应收金额 = 商业手续费+商业跟单 + 交强手续费 +交强跟单费 + 非车手续费 + 非车跟单费 = allAmount
  307. insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums()); // 交强手续费
  308. insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums()); // 商业手续费
  309. insPlyIncome.setNoSuperviseCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums()); // 非车手续费
  310. insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion()); //交强手续费 比例
  311. insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion()); // 商业手续费 比例
  312. insPlyIncome.setNoSuperviseCostsProportion(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费 比例
  313. insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
  314. insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
  315. insPlyIncome.setNoOtherCostsProportion(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费比例
  316. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  317. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  318. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium());
  319. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  320. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  321. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  322. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  323. this.saveRiskCode(order.getProductid(),insPlyIncome);
  324. insPlyIncome.setInsuredName(order.getInsuredname());
  325. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  326. baseMapper.insert(insPlyIncome);
  327. }
  328. private void saveByCompanyId(InsFeeOrderNew insFeeOrderNew,String companyId, InsPlyIncome insPlyIncome) {
  329. PtlAgreement ptlAgreementQueryVo = this.ptlAgreementService.getByAgreementIdNew(insFeeOrderNew.getAgreementId());
  330. if(ObjectUtils.isNotEmpty(ptlAgreementQueryVo)){
  331. if(StringUtils.isNotEmpty(ptlAgreementQueryVo.getPartnerCompaniesId())){
  332. // 合作公司id
  333. String partnerCompaniesId = ptlAgreementQueryVo.getPartnerCompaniesId();
  334. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  335. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  336. String name = esmInsCompany.getName(); //合作名称
  337. insPlyIncome.setPartnerCompaniesName(name);
  338. insPlyIncome.setPartnerCompaniesId(ptlAgreementQueryVo.getPartnerCompaniesId());
  339. }
  340. if(StringUtils.isNotEmpty(ptlAgreementQueryVo.getInsuranceCompanyId())){
  341. String insuranceCompanyId = ptlAgreementQueryVo.getInsuranceCompanyId();
  342. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(insuranceCompanyId);
  343. String name = esmInsCompany.getNamesimple(); //保险公司名称 简称
  344. insPlyIncome.setCompanyName(name);
  345. }
  346. }
  347. }
  348. private BigDecimal calculateTotal(BigDecimal value1, BigDecimal value2, BigDecimal value3) {
  349. BigDecimal total = BigDecimal.ZERO;
  350. if (value1 != null) {
  351. total = total.add(value1);
  352. }
  353. if (value2 != null) {
  354. total = total.add(value2);
  355. }
  356. if (value3 != null) {
  357. total = total.add(value3);
  358. }
  359. return total;
  360. }
  361. private String judgeAgreeType(Long agreementId) {
  362. if (agreementId == null) {
  363. return null;
  364. }
  365. HttpResult<PtlAgreementQueryVo> byAgreementId = ptlAgreementService.getByAgreementId(agreementId.toString());
  366. if (byAgreementId != null && ObjectUtils.isNotEmpty(byAgreementId.getData())) {
  367. PtlAgreement agreement = byAgreementId.getData().getAgreement();
  368. String agreementType = agreement.getAgreementType();
  369. if (StringUtils.isNotEmpty(agreementType)) {
  370. return agreementType;
  371. }
  372. }
  373. return null;
  374. }
  375. public HttpResult<BasePageResult<InsPlyIncome>> queryNew(InsPlyIncomeVo insPlyIncomeVo){
  376. try{
  377. HashMap<String, Object> params = new HashMap<>();
  378. PageInfo<List<InsPlyIncome>> pageHelper = null;
  379. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  380. params.put("pageNum",insPlyIncomeVo.getPageNum());
  381. params.put("pageSize",insPlyIncomeVo.getPageSize());
  382. params =this.saveParams(insPlyIncomeVo,params);
  383. List<InsPlyIncome> list= this.baseMapper.queryNew(params);
  384. pageHelper=new PageInfo(list);
  385. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  386. return HttpResult.ok(pageResult);
  387. }catch (Exception e){
  388. e.printStackTrace();
  389. return HttpResult.error("查询异常");
  390. }
  391. }
  392. @Override
  393. public HashMap<String,Object> totalAmount(List<String> selectIds) {
  394. HashMap<String, Object> params = new HashMap<>();
  395. params.put("selectIds",selectIds);
  396. HashMap<String,Object> resultMap =baseMapper.totalAmount(params);
  397. return resultMap;
  398. }
  399. @Override
  400. @Transactional
  401. public HttpResult<Object> batchPinBalance(InsPlyIncomeVo insPlyIncomeVo) {
  402. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())){
  403. List<String> selectIds = insPlyIncomeVo.getSelectIds();
  404. for(String id: selectIds){
  405. InsPlyIncome insPlyIncome = new InsPlyIncome();
  406. insPlyIncome.setHandlingFeesStatus("1");
  407. insPlyIncome.setSettlementTime(LocalDate.now());
  408. insPlyIncome.setId(id);
  409. baseMapper.updateById(insPlyIncome);
  410. }
  411. }
  412. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  413. settlementDocumentaryLogEntity.setIds(insPlyIncomeVo.getIds());
  414. // settlementDocumentaryLogEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  415. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); //跟单费金额
  416. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); //手续费金额
  417. settlementDocumentaryLogEntity.setCreateTime(new Date());
  418. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  419. return HttpResult.ok();
  420. }
  421. @Override
  422. public List<InsPlyIncome> totalPinAmount(InsPlyIncomeVo insPlyIncomeVo) {
  423. HashMap<String, Object> params = new HashMap<>();
  424. params = this.saveParams(insPlyIncomeVo,params);
  425. List<InsPlyIncome> result=baseMapper.totalPinAmount(params);
  426. return result;
  427. }
  428. private HashMap<String, Object> saveParams(InsPlyIncomeVo insPlyIncomeVo, HashMap<String, Object> params) {
  429. if(ObjectUtils.isNotEmpty(insPlyIncomeVo.getStartDate())){
  430. params.put("startDate",insPlyIncomeVo.getStartDate().toString());
  431. }
  432. if(ObjectUtils.isNotEmpty(insPlyIncomeVo.getEndDate())){
  433. params.put("endDate",insPlyIncomeVo.getEndDate().toString());
  434. }
  435. if(StringUtils.isNotEmpty(insPlyIncomeVo.getOrderno())){
  436. params.put("orderno",insPlyIncomeVo.getOrderno());
  437. }
  438. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  439. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  440. }
  441. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  442. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  443. }
  444. if(StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType())){
  445. params.put("agreementType",insPlyIncomeVo.getAgreementType());
  446. }
  447. if(StringUtils.isNotEmpty(insPlyIncomeVo.getLicenseno())){
  448. params.put("licenseno", insPlyIncomeVo.getLicenseno());
  449. }
  450. if(StringUtils.isNotEmpty(insPlyIncomeVo.getUserId())){
  451. params.put("userId",insPlyIncomeVo.getUserId());
  452. }
  453. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  454. params.put("companyId",insPlyIncomeVo.getCompanyId());
  455. }
  456. if(StringUtils.isNotEmpty(insPlyIncomeVo.getRiskcode())){
  457. params.put("riskcode",insPlyIncomeVo.getRiskcode());
  458. }
  459. if(StringUtils.isNotEmpty(insPlyIncomeVo.getPolicyno())){
  460. params.put("policyno",insPlyIncomeVo.getPolicyno());
  461. }
  462. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSyPolicyno())){
  463. params.put("syPolicyno",insPlyIncomeVo.getSyPolicyno());
  464. }
  465. if(StringUtils.isNotEmpty(insPlyIncomeVo.getNoPolicyno())){
  466. params.put("noPolicyno",insPlyIncomeVo.getNoPolicyno());
  467. }
  468. if(insPlyIncomeVo.getCreateTime()!=null){
  469. params.put("createTime",insPlyIncomeVo.getCreateTime().toString());
  470. }
  471. if(insPlyIncomeVo.getSettlementTime()!=null){
  472. params.put("settlementTime",insPlyIncomeVo.getSettlementTime().toString());
  473. }
  474. if(StringUtils.isNotEmpty(insPlyIncomeVo.getHandlingFeesStatus())){
  475. params.put("handlingFeesStatus",insPlyIncomeVo.getHandlingFeesStatus());
  476. }
  477. if(StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesId())){
  478. params.put("partnerCompaniesId",insPlyIncomeVo.getPartnerCompaniesId());
  479. }
  480. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  481. params.put("year",insPlyIncomeVo.getYear());
  482. }
  483. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  484. params.put("month",insPlyIncomeVo.getMonth());
  485. }
  486. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDay())){
  487. params.put("day",insPlyIncomeVo.getDay());
  488. }
  489. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateEnd())){
  490. params.put("signDateEnd",insPlyIncomeVo.getSignDateEnd());
  491. }
  492. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateStart())){
  493. params.put("signDateStart",insPlyIncomeVo.getSignDateStart());
  494. }
  495. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyName())){
  496. params.put("companyName",insPlyIncomeVo.getCompanyName());
  497. }
  498. if(StringUtils.isNotEmpty(insPlyIncomeVo.getInsuredName())){
  499. params.put("insuredName",insPlyIncomeVo.getInsuredName());
  500. }
  501. if(StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesName())){
  502. params.put("partnerCompaniesName",insPlyIncomeVo.getPartnerCompaniesName());
  503. }
  504. return params;
  505. }
  506. @Override
  507. public HttpResult<BasePageResult<InsPlyIncome>> nonSettlementQuery(InsPlyIncomeVo insPlyIncomeVo) {
  508. try{
  509. HashMap<String, Object> params = new HashMap<>();
  510. PageInfo<List<InsPlyIncome>> pageHelper = null;
  511. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  512. params.put("pageNum",insPlyIncomeVo.getPageNum());
  513. params.put("pageSize",insPlyIncomeVo.getPageSize());
  514. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  515. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  516. }
  517. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  518. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  519. }
  520. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  521. params.put("year",insPlyIncomeVo.getYear());
  522. }
  523. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  524. params.put("month",insPlyIncomeVo.getMonth());
  525. }
  526. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())){
  527. params.put("documentaryFeesStatus",insPlyIncomeVo.getDocumentaryFeesStatus());
  528. }
  529. List<InsPlyIncome> list= this.baseMapper.NonSettlementQuery(params);
  530. pageHelper=new PageInfo(list);
  531. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  532. return HttpResult.ok(pageResult);
  533. }catch (Exception e){
  534. e.printStackTrace();
  535. return HttpResult.error("查询异常");
  536. }
  537. }
  538. @Override
  539. public HttpResult<List<InsPlyIncome>> nonSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  540. try {
  541. String ids = insPlyIncomeVo.getIds();
  542. ArrayList<InsPlyIncome> resultList = new ArrayList<>();
  543. if (ObjectUtils.isNotEmpty(ids)) {
  544. String[] split = ids.split(",");
  545. for (int i =0; i <split.length ; i++) {
  546. String id = split[i];
  547. resultList.add(this.baseMapper.getById(id));
  548. }
  549. }
  550. return HttpResult.ok(resultList);
  551. } catch (Exception e) {
  552. e.printStackTrace();
  553. return HttpResult.error("查询异常");
  554. }
  555. }
  556. /**
  557. *
  558. * @param multipartFile
  559. * @return totalAmount 总金额
  560. * totalHandingAmount 总手续费金额
  561. * totalOtherAmount 总跟单费金额
  562. * resultHashMap 返回 ids 已经上面的金额
  563. * resultNoSelect 未匹配的车牌号
  564. */
  565. @Override
  566. public HashMap<String, Object> importData(MultipartFile multipartFile) {
  567. BigDecimal totalAmount=BigDecimal.ZERO;
  568. BigDecimal totalHandingAmount=BigDecimal.ZERO;
  569. BigDecimal totalOtherAmount=BigDecimal.ZERO;
  570. HashMap<String, Object> params = new HashMap<>();
  571. HashMap<String, Object> resultHashMap = new HashMap<>();
  572. ArrayList<HashMap<String,Object>> resultNoSelect = new ArrayList<>();
  573. StringBuffer strBuilder = new StringBuffer();
  574. try {
  575. List<InsPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsPlyIncomeExcelDto.class, 0, 1, 1);
  576. for (InsPlyIncomeExcelDto excelItem : dtoList) {
  577. params.clear();
  578. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  579. params.put("licenseno",excelItem.getLicenseno());//车牌号
  580. }
  581. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  582. params.put("policyno",excelItem.getPolicyno()); //交强保单号
  583. }
  584. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  585. params.put("syPolicyno", excelItem.getSyPolicyno());//商业保单号
  586. }
  587. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  588. params.put("noPolicyno",excelItem.getNoPolicyno()); //非车保单号
  589. }
  590. InsPlyIncome insPlyIncome=baseMapper.findByLicenseno(params);
  591. if(ObjectUtils.isNotEmpty(insPlyIncome)){
  592. strBuilder.append(insPlyIncome.getId()).append(",");
  593. if(insPlyIncome.getAllFeeValue()!=null && insPlyIncome.getAllFeeValue().compareTo(BigDecimal.ZERO)!=0){
  594. totalAmount = totalAmount.add(insPlyIncome.getAllFeeValue()); //总金额
  595. }
  596. if(insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  597. totalHandingAmount=totalHandingAmount.add(insPlyIncome.getCommissionFeevalue()); //总手续费
  598. }
  599. if(insPlyIncome.getOtherFeevalue()!=null && insPlyIncome.getOtherFeevalue().compareTo(BigDecimal.ZERO)!=0){
  600. totalOtherAmount=totalOtherAmount.add(insPlyIncome.getOtherFeevalue()); //总跟单费
  601. }
  602. }else {
  603. resultNoSelect.add(params); // 添加未匹配的车牌号
  604. }
  605. }
  606. if(strBuilder.length() >0){
  607. String ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  608. resultHashMap.put("ids",ids);
  609. }
  610. resultHashMap.put("totalAmount",totalAmount);
  611. resultHashMap.put("totalHandingAmount",totalHandingAmount);
  612. resultHashMap.put("totalOtherAmount",totalOtherAmount);
  613. resultHashMap.put("resultList",resultNoSelect);
  614. return resultHashMap;
  615. } catch (IOException e) {
  616. throw new SystemException("导入失败!");
  617. }
  618. }
  619. /**
  620. *
  621. * @param multipartFile
  622. * @return resultList 包含总金额 还有 未匹配表中的数据
  623. */
  624. @Override
  625. public HashMap<String, Object> bxImportData(MultipartFile multipartFile,String isNotCar) {
  626. BigDecimal totalAmount=BigDecimal.ZERO;
  627. HashMap<String, Object> params = new HashMap<>();
  628. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  629. HashMap<String, Object> resultMap = new HashMap<>();
  630. StringBuffer strBuilder = new StringBuffer();
  631. String ids="";
  632. try {
  633. List<InsBxPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxPlyIncomeExcelDto.class, 0, 1, 1);
  634. if(!CollectionUtils.isEmpty(dtoList)){
  635. for (InsBxPlyIncomeExcelDto excelItem : dtoList) {
  636. params.clear();
  637. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  638. String licenseno = excelItem.getLicenseno();//车牌号
  639. params.put("licenseno",licenseno);
  640. }
  641. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  642. String policyno = excelItem.getPolicyno(); //交强保单号
  643. params.put("policyno",policyno);
  644. }
  645. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  646. String syPolicyno = excelItem.getSyPolicyno(); //商业保单号
  647. params.put("syPolicyno",syPolicyno);
  648. }
  649. // 只查手续费
  650. params.put("isOther","0");
  651. params.put("isNotCar",isNotCar);
  652. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  653. if(ObjectUtils.isNotEmpty(insPlyIncome)){ // 比配上汇总金额 未匹配则返回到数据当中
  654. strBuilder.append(insPlyIncome.getId()).append(",");
  655. if( insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  656. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  657. }
  658. }else {
  659. HashMap<String, Object> noMatching = new HashMap<>();
  660. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  661. noMatching.put("licenseno",excelItem.getLicenseno());
  662. }
  663. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  664. noMatching.put("policyno",excelItem.getPolicyno());
  665. }
  666. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  667. noMatching.put("syPolicyno",excelItem.getSyPolicyno());
  668. }
  669. resultList.add(noMatching);
  670. }
  671. }
  672. }
  673. if(strBuilder.length() >0){
  674. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  675. }
  676. resultMap.put("ids",ids);
  677. resultMap.put("totalAmount",totalAmount);
  678. resultMap.put("resultList",resultList);
  679. return resultMap;
  680. } catch (IOException e) {
  681. throw new SystemException("导入失败!");
  682. }
  683. }
  684. @Override
  685. public HashMap<String, Object> bxImportNoData(MultipartFile multipartFile,String isNotCar) {
  686. BigDecimal totalAmount=BigDecimal.ZERO;
  687. HashMap<String, Object> params = new HashMap<>();
  688. HashMap<String, Object> resultMap = new HashMap<>();
  689. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  690. StringBuffer strBuilder = new StringBuffer();
  691. String ids="";
  692. try {
  693. List<InsBxNoPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxNoPlyIncomeExcelDto.class, 0, 1, 1);
  694. if(!CollectionUtils.isEmpty(dtoList)){
  695. for (InsBxNoPlyIncomeExcelDto excelItem : dtoList) {
  696. params.clear();
  697. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  698. String licenseno = excelItem.getLicenseno();//车牌号
  699. params.put("licenseno",licenseno);
  700. }
  701. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  702. String policyno = excelItem.getNoPolicyno(); //非车保单号
  703. params.put("NoPolicyno",policyno);
  704. }
  705. // 只查手续费
  706. params.put("isOther","0");
  707. params.put("isNotCar",isNotCar);
  708. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  709. if(ObjectUtils.isNotEmpty(insPlyIncome)){ // 比配上汇总金额 未匹配则返回到数据当中
  710. strBuilder.append(insPlyIncome.getId()).append(",");
  711. if( insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  712. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  713. }
  714. }else {
  715. HashMap<String, Object> noMatching = new HashMap<>();
  716. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  717. noMatching.put("licenseno",excelItem.getLicenseno());
  718. }
  719. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  720. noMatching.put("NoPolicyno",excelItem.getNoPolicyno());
  721. }
  722. resultList.add(noMatching);
  723. }
  724. }
  725. if(strBuilder.length() >0){
  726. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  727. }
  728. resultMap.put("ids",ids);
  729. resultMap.put("totalAmount",totalAmount);
  730. resultMap.put("resultList",resultList);
  731. }
  732. return resultMap;
  733. } catch (IOException e) {
  734. throw new SystemException("导入失败!");
  735. }
  736. }
  737. @Override
  738. public HttpResult bxOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  739. HashMap<String, Object> params = new HashMap<>();
  740. params =this.saveParams(insPlyIncomeVo,params);
  741. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  742. ExportParams exportParams = new ExportParams("保险跟单明细导出", null, ExcelType.HSSF);
  743. exportParams.setStyle(ExcelStyleUtil.class);
  744. List<BxOtherDetailsExcel> resultList = new ArrayList<>();
  745. for (InsPlyIncome item :insPlyIncomes){
  746. BxOtherDetailsExcel bxOtherDetailsExcel = new BxOtherDetailsExcel();
  747. BeanUtils.copyProperties(item, bxOtherDetailsExcel);
  748. resultList.add(bxOtherDetailsExcel);
  749. }
  750. String uploadPath = this.uploadPath + "/excel/";
  751. Path path = Paths.get(uploadPath);
  752. if (!Files.exists(path)) {
  753. try {
  754. Files.createDirectories(path);
  755. } catch (IOException e) {
  756. e.printStackTrace();
  757. }
  758. }
  759. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险跟单明细导出", BxOtherDetailsExcel.class, resultList);
  760. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  761. }
  762. /**
  763. *
  764. * @param insPlyIncomeVo 传参字段
  765. * ids 通过ids中的id进行开票分组
  766. *
  767. * @return
  768. */
  769. @Override
  770. public HttpResult<List<HashMap<String,Object>>> invicdetail(InsPlyIncomeVo insPlyIncomeVo) {
  771. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){
  772. String ids = insPlyIncomeVo.getIds();
  773. String[] idArr = ids.split(",");
  774. List<HashMap<String,Object>> result= this.baseMapper.groupByInvoic(idArr);
  775. return HttpResult.ok(result);
  776. }
  777. return HttpResult.ok();
  778. }
  779. /***
  780. *
  781. * @param insPlyIncomeVo
  782. * @param request
  783. * @param response
  784. * @return 保险非车跟单明细导出
  785. */
  786. @Override
  787. public HttpResult bxNoOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  788. HashMap<String, Object> params = new HashMap<>();
  789. params =this.saveParams(insPlyIncomeVo,params);
  790. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  791. ExportParams exportParams = new ExportParams("保险非车跟单明细导出", null, ExcelType.HSSF);
  792. exportParams.setStyle(ExcelStyleUtil.class);
  793. List<BxNoOtherDetailsExcel> resultList = new ArrayList<>();
  794. for (InsPlyIncome item :insPlyIncomes){
  795. BxNoOtherDetailsExcel bxNoOtherDetailsExcel = new BxNoOtherDetailsExcel();
  796. BeanUtils.copyProperties(item, bxNoOtherDetailsExcel);
  797. resultList.add(bxNoOtherDetailsExcel);
  798. }
  799. String uploadPath = this.uploadPath + "/excel/";
  800. Path path = Paths.get(uploadPath);
  801. if (!Files.exists(path)) {
  802. try {
  803. Files.createDirectories(path);
  804. } catch (IOException e) {
  805. e.printStackTrace();
  806. }
  807. }
  808. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险非车跟单明细导出", BxNoOtherDetailsExcel.class, resultList);
  809. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  810. }
  811. /**
  812. *
  813. * @param insPlyIncomeVo 开票ids
  814. * @return 返回开票号 开票金额 开票时间
  815. */
  816. @Override
  817. public HttpResult<List<HashMap<String, Object>>> otherSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  818. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIncomeIds())) {
  819. String incomeIds = insPlyIncomeVo.getIncomeIds();
  820. List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(incomeIds);
  821. if (resultList.size() > 0) {
  822. return HttpResult.ok(resultList);
  823. }
  824. }
  825. return HttpResult.ok();
  826. }
  827. @Override
  828. public InsPlyIncome getEntityById(String id) {
  829. return baseMapper.getEntityById(id);
  830. }
  831. @Override
  832. @Transactional
  833. public void updateByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  834. // 根据协议 如果是含增值税结算 用保费 * 如果是 不含税保费
  835. InsPlyIncome insPlyIncome = new InsPlyIncome();
  836. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  837. this.amountCalculate(insPlyIncomeVo,insPlyIncome);
  838. baseMapper.updateById(insPlyIncome);
  839. insPlyIncomeVo.setCrudStatus("2");
  840. this.saveLog(insPlyIncomeVo);
  841. }
  842. /**
  843. *
  844. * @param insPlyIncomeVo
  845. * @param insPlyIncome
  846. *
  847. * 重新计算金额 通过比例
  848. * 计算逻辑 交强不含税保费* 交强跟单比例 = 交强跟单金额
  849. */
  850. private void amountCalculate(InsPlyIncomeVo insPlyIncomeVo,InsPlyIncome insPlyIncome) {
  851. if("1".equals(insPlyIncomeVo.getAgreementType())){ //平台
  852. // 平台 手续费 +跟单费 = 应收 手续费 = 手续费比例*保费 应收比例=手续费比例 + 跟单比例
  853. BigDecimal jqSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqSuperviseCostsProportion());//交强手续费比例
  854. BigDecimal sySuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSySuperviseCostsProportion()); //商业手续费比例
  855. BigDecimal noSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoSuperviseCostsProportion()); //非车手续费比例
  856. BigDecimal jqOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqOtherCostsProportion()); //交强跟单比例
  857. BigDecimal syOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSyOtherCostsProportion()); //商业跟单比例
  858. BigDecimal noOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoOtherCostsProportion()); //非车跟单比例
  859. BigDecimal jqPremium = initializationBigdecimal(insPlyIncomeVo.getJqPremium()); //交强保费
  860. BigDecimal syPremium = initializationBigdecimal(insPlyIncomeVo.getSyPremium()); //商业保费
  861. BigDecimal noPremium = initializationBigdecimal(insPlyIncomeVo.getNoPremium()); //非车保费
  862. //手续费比例
  863. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion,sySuperviseCostsProportion,noSuperviseCostsProportion)); //手续费比例 = 商业手续费比例 + 交强手续费比例 + 非车手续费比例
  864. if(jqSuperviseCostsProportion !=null && jqPremium!=null ){
  865. insPlyIncome.setJqSuperviseCostsPremiums(this.algorithmAmount(jqPremium,jqSuperviseCostsProportion)); //交强手续费
  866. }
  867. if(sySuperviseCostsProportion !=null && syPremium !=null){
  868. insPlyIncome.setSySuperviseCostsPremiums(this.algorithmAmount(syPremium,sySuperviseCostsProportion)); //商业手续费
  869. }
  870. if(noSuperviseCostsProportion !=null && noPremium!=null){
  871. insPlyIncome.setNoSuperviseCostsPremiums(this.algorithmAmount(noPremium,noSuperviseCostsProportion)); //非车手续费
  872. }
  873. if(jqOtherCostsProportion !=null && jqPremium!=null ){
  874. insPlyIncome.setJqOtherCostsPremium(this.algorithmAmount(jqPremium,jqOtherCostsProportion)); //交强跟单费
  875. }
  876. if(syOtherCostsProportion !=null && syPremium !=null ){
  877. insPlyIncome.setSyOtherCostsPremium(this.algorithmAmount(syPremium,syOtherCostsProportion)); //商业跟单费
  878. }
  879. if(noOtherCostsProportion !=null && noPremium !=null){
  880. insPlyIncome.setNoOtherCostsPremium(this.algorithmAmount(noPremium,noOtherCostsProportion)); //非车跟单费
  881. }
  882. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),insPlyIncome.getNoSuperviseCostsPremiums())); //手续费
  883. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion,sySuperviseCostsProportion,noSuperviseCostsProportion)); //手续费比例
  884. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),insPlyIncome.getNoOtherCostsPremium())); //跟单费金额
  885. insPlyIncome.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion,syOtherCostsProportion,noOtherCostsProportion)); //跟单费比例
  886. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),insPlyIncome.getOtherFeevalue(),null)); // 总费用 = 手续费+跟单费
  887. //应收比例 交强应收比例=交强手续费比例+交强非跟单比例
  888. insPlyIncome.setJqReceivableProportion(this.calculateTotal(jqSuperviseCostsProportion,jqOtherCostsProportion,null)); //交强应收
  889. insPlyIncome.setSyReceivableProportion(this.calculateTotal(sySuperviseCostsProportion,syOtherCostsProportion,null)); //商业应收
  890. insPlyIncome.setNoReceivableProportion(this.calculateTotal(noSuperviseCostsProportion,noOtherCostsProportion,null)); //非车应收
  891. }else {
  892. BigDecimal jqNoTaxPremium = insPlyIncomeVo.getJqNoTaxPremium();// 交强手续费 按照思路 交强不含税保费* 交强手续费比例 =交强手续费
  893. BigDecimal syNoTaxPremium = insPlyIncomeVo.getSyNoTaxPremium();// 商业手续费 按照思路 商业不含税保费* 商业手续费比例 =商业手续费
  894. BigDecimal noNoTaxPremium = insPlyIncomeVo.getNoNoTaxPremium();// 非车手续费 按照思路 非车不含税保费* 非车手续费比例 =非车手续费
  895. if(insPlyIncomeVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  896. BigDecimal jqhandingFee = jqNoTaxPremium.multiply(insPlyIncomeVo.getJqSuperviseCostsProportion().divide(new BigDecimal(100)));
  897. insPlyIncome.setJqSuperviseCostsPremiums(jqhandingFee);
  898. }
  899. if(insPlyIncomeVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  900. BigDecimal syhandingFee = syNoTaxPremium.multiply(insPlyIncomeVo.getSySuperviseCostsProportion().divide(new BigDecimal(100)));
  901. insPlyIncome.setSySuperviseCostsPremiums(syhandingFee);
  902. }
  903. if(insPlyIncomeVo.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  904. BigDecimal nohandingFee = noNoTaxPremium.multiply(insPlyIncomeVo.getNoSuperviseCostsProportion().divide(new BigDecimal(100)));
  905. insPlyIncome.setNoSuperviseCostsPremiums(nohandingFee);
  906. }
  907. if(insPlyIncomeVo.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  908. BigDecimal jqother = jqNoTaxPremium.multiply(insPlyIncomeVo.getJqOtherCostsProportion().divide(new BigDecimal(100)));//交强跟单费 按照思路 交强不含税保费* 交强跟单比例 = 交强跟单金额
  909. insPlyIncome.setJqOtherCostsPremium(jqother);
  910. }
  911. if(insPlyIncomeVo.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  912. BigDecimal syother = syNoTaxPremium.multiply(insPlyIncomeVo.getSyOtherCostsProportion().divide(new BigDecimal(100)));//交强跟单费 按照思路 交强不含税保费* 交强跟单比例 = 交强跟单金额
  913. insPlyIncome.setSyOtherCostsPremium(syother);
  914. }
  915. if(insPlyIncomeVo.getNoOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  916. BigDecimal syother = syNoTaxPremium.multiply(insPlyIncomeVo.getNoOtherCostsProportion().divide(new BigDecimal(100)));//非车跟单费 按照思路 非车不含税保费* 非车跟单比例 = 非车跟单金额
  917. insPlyIncome.setNoOtherCostsPremium(syother);
  918. }
  919. if("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())){ //保险 手续费 =不含税保费* 手续费比例
  920. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),null)); // 手续费
  921. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(),insPlyIncome.getSySuperviseCostsProportion(),null));//手续费比例
  922. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),null,null));//总金额
  923. }else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())){ //保险跟单费 交强跟单+商业跟单
  924. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),null));
  925. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getJqOtherCostsProportion(),insPlyIncome.getSyOtherCostsProportion(),null));
  926. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(),null,null));//总金额
  927. }
  928. if("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())){// 非车
  929. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getNoSuperviseCostsPremiums(),null,null)); // 非车手续费
  930. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getNoSuperviseCostsProportion(),null,null)); //非车比例
  931. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),null,null));//总金额
  932. }else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())){ //非车跟单
  933. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getNoOtherCostsPremium(),null,null)); //非车跟单金额
  934. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getNoOtherCostsProportion(),null,null)); // 非车跟单比例
  935. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(),null,null));//总金额
  936. }
  937. }
  938. }
  939. /**
  940. *
  941. * @param value1 保费
  942. * @param value2 比例
  943. * @return 费用
  944. */
  945. private BigDecimal algorithmAmount(BigDecimal value1, BigDecimal value2) {
  946. return value1.multiply(value2.divide(new BigDecimal(100)));
  947. }
  948. private BigDecimal initializationBigdecimal(BigDecimal value) {
  949. return value != null ? value : BigDecimal.ZERO;
  950. }
  951. private void saveLog(InsPlyIncomeVo insPlyIncomeVo) {
  952. // 添加记录
  953. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  954. settlementDocumentaryLogEntity.setCrudStatus(insPlyIncomeVo.getCrudStatus());
  955. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue());
  956. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId());
  957. settlementDocumentaryLogEntity.setAmountType("2");
  958. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  959. }
  960. @Override
  961. @Transactional
  962. public HttpResult<InsPlyIncome> insertByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  963. Long id = new SnowFlakeUtil().nextId();
  964. InsPlyIncome insPlyIncome = new InsPlyIncome();
  965. insPlyIncomeVo.setOrderno(id.toString());
  966. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  967. insPlyIncome.setDocumentaryFeesStatus("0");
  968. insPlyIncome.setHandlingFeesStatus("0");
  969. insPlyIncome.setIsNotCar("0");
  970. insPlyIncome.setIsNotDocumentary("1");
  971. baseMapper.insert(insPlyIncome);
  972. insPlyIncomeVo.setId(insPlyIncome.getId());
  973. insPlyIncomeVo.setCrudStatus("1");
  974. this.saveLog(insPlyIncomeVo); //添加日志
  975. HashMap<String, Object> params = new HashMap<>();
  976. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  977. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  978. }
  979. params.put("isOther","1");
  980. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  981. params.put("year",insPlyIncomeVo.getYear());
  982. }
  983. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  984. params.put("companyId",insPlyIncomeVo.getCompanyId());
  985. }
  986. List<InsPlyIncome> list= this.baseMapper.NonSettlementQuery(params);
  987. if(!CollectionUtils.isEmpty(list)){
  988. for (InsPlyIncome item :list){
  989. return HttpResult.ok(item.getIds());
  990. }
  991. }
  992. return null;
  993. }
  994. @Override
  995. @Transactional
  996. public HttpResult<InsPlyIncome> deleteById(InsPlyIncomeVo insPlyIncomeVo) {
  997. HashMap<String, Object> params = new HashMap<>();
  998. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  999. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  1000. }
  1001. params.put("isOther","1");
  1002. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1003. params.put("year",insPlyIncomeVo.getYear());
  1004. }
  1005. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1006. params.put("companyId",insPlyIncomeVo.getCompanyId());
  1007. }
  1008. baseMapper.deleteById(insPlyIncomeVo.getId());
  1009. insPlyIncomeVo.setCrudStatus("3");
  1010. this.saveLog(insPlyIncomeVo);
  1011. List<InsPlyIncome> list = this.baseMapper.NonSettlementQuery(params);
  1012. if (!CollectionUtils.isEmpty(list)) {
  1013. for (InsPlyIncome item : list) {
  1014. return HttpResult.ok(item.getIds());
  1015. }
  1016. } else {
  1017. return HttpResult.ok(null);
  1018. }
  1019. return HttpResult.ok("删除成功");
  1020. }
  1021. @Override
  1022. @Transactional
  1023. public void uodateBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1024. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1025. insPlyIncomeVo.setHandlingFeesStatus("1");
  1026. insPlyIncomeVo.setSettlementTime(LocalDate.now());
  1027. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1028. baseMapper.updateById(insPlyIncome);
  1029. // 生成记录
  1030. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1031. if(StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType()) && "1".equals(insPlyIncomeVo.getAgreementType())){
  1032. // 只有平台协议 才会跟单费一笔结算
  1033. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); // 跟单费金额
  1034. }
  1035. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); // 手续费金额
  1036. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId()); // 关联id
  1037. settlementDocumentaryLogEntity.setAmountType("1"); //手续费结算
  1038. settlementDocumentaryLogEntity.setCreateTime(new Date());
  1039. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1040. }
  1041. @Override
  1042. @Transactional
  1043. public HttpResult<BasePageResult<InsPlyIncome>> totalQuery(InsPlyIncomeVo insPlyIncomeVo) {
  1044. HashMap<String, Object> params = new HashMap<>();
  1045. PageInfo<List<InsPlyIncome>> pageHelper = null;
  1046. if(insPlyIncomeVo.getStartDate()!=null){
  1047. params.put("startDate",insPlyIncomeVo.getStartDate().toString());
  1048. }
  1049. if(insPlyIncomeVo.getEndDate()!=null){
  1050. params.put("endDate",insPlyIncomeVo.getEndDate().toString());
  1051. }
  1052. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1053. params.put("year",insPlyIncomeVo.getYear());
  1054. }
  1055. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  1056. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  1057. }
  1058. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  1059. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  1060. }
  1061. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())){
  1062. params.put("documentaryFeesStatus",insPlyIncomeVo.getDocumentaryFeesStatus());
  1063. }
  1064. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1065. params.put("companyId",insPlyIncomeVo.getCompanyId());
  1066. }
  1067. params.put("pageNum",insPlyIncomeVo.getPageNum());
  1068. params.put("pageSize",insPlyIncomeVo.getPageSize());
  1069. List<InsPlyIncome> list= this.baseMapper.totalQuery(params);
  1070. pageHelper=new PageInfo(list);
  1071. return HttpResult.ok(new BasePageResult<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list));
  1072. }
  1073. /**
  1074. *
  1075. * @param insPlyIncomeVo ids ins_ply_income 这个表的ids incomeIds settlement_documentary_fees 这个表的ids
  1076. * @return
  1077. */
  1078. @Override
  1079. @Transactional
  1080. public HttpResult batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1081. // 通过ids 查出跟单非结算单
  1082. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){
  1083. settlementDocumentaryFeesService.batchByInvoice(insPlyIncomeVo.getIds());
  1084. }
  1085. return HttpResult.ok();
  1086. }
  1087. /**
  1088. *
  1089. * @param insPlyIncomeVo
  1090. * @return
  1091. */
  1092. @Override
  1093. public List<InsPlyIncome> totalBxAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1094. HashMap<String, Object> params = new HashMap<>();
  1095. params=this.saveParams(insPlyIncomeVo,params);
  1096. params.remove("handlingFeesStatus");
  1097. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  1098. // 数据库数据太多是 用sql拼接id会丢失 所以只能逻辑拼接
  1099. List<InsPlyIncome> idList=baseMapper.getIncomeIdList(params);
  1100. if(!CollectionUtils.isEmpty(idList) && !ObjectUtils.isNotEmpty(resultList)){
  1101. this.splicingIds(idList,resultList);
  1102. }
  1103. return resultList;
  1104. }
  1105. /**
  1106. *
  1107. * @param idList 要开票的数据集合
  1108. * @param resultList 总返回数据
  1109. */
  1110. private void splicingIds(List<InsPlyIncome> idList, List<InsPlyIncome> resultList) {
  1111. // 使用Map来存储agreementId到其id列表的映射
  1112. Map<String, List<String>> idMap = new HashMap<>();
  1113. for (InsPlyIncome idItem : idList) {
  1114. String agreementId = idItem.getAgreementId();
  1115. idMap.computeIfAbsent(agreementId, k -> new ArrayList<>()).add(idItem.getId());
  1116. }
  1117. for (InsPlyIncome resultItem : resultList) {
  1118. List<String> ids = idMap.getOrDefault(resultItem.getAgreementId(), Collections.emptyList());
  1119. String idsString = String.join(",", ids);
  1120. resultItem.setIds(idsString);
  1121. }
  1122. }
  1123. @Override
  1124. @Transactional
  1125. public HttpResult<Object> batchInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1126. // 开票时生成 记录 用来合计已经开票数据
  1127. String ids = insPlyIncomeVo.getIds();
  1128. if(StringUtils.isNotEmpty(ids)){
  1129. String[] split = ids.split(",");
  1130. for (String id : split){
  1131. InsPlyIncome insPlyIncome = baseMapper.selectById(id);
  1132. insPlyIncome.setInvoicTime(LocalDate.now()); //开票时间
  1133. insPlyIncome.setInvoicId(insPlyIncomeVo.getInvoicId()); //开票号
  1134. insPlyIncome.setHandlingFeesStatus("2"); //2为开票
  1135. baseMapper.updateById(insPlyIncome);
  1136. }
  1137. }
  1138. return HttpResult.ok();
  1139. }
  1140. @Override
  1141. public HttpResult<InsPlyIncome> queryInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1142. HashMap<String, Object> params = new HashMap<>();
  1143. params = this.saveParams(insPlyIncomeVo, params);
  1144. InsPlyIncome result= baseMapper.queryInvoicing(params); //总金额
  1145. params.put("handlingFeesStatus","0");
  1146. InsPlyIncome noResult= baseMapper.queryInvoicing(params); //未结算金额
  1147. result.setReadyCommissionFeevalue(noResult.getCommissionFeevalue());
  1148. return HttpResult.ok(result);
  1149. }
  1150. @Override
  1151. public HttpResult<Object> batchBxBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1152. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1153. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){
  1154. String[] split = insPlyIncomeVo.getIds().split(",");
  1155. for(String id : split){
  1156. insPlyIncome.setId(id);
  1157. insPlyIncome.setHandlingFeesStatus("1");
  1158. insPlyIncome.setSettlementTime(LocalDate.now());
  1159. baseMapper.updateById(insPlyIncome);
  1160. }
  1161. }
  1162. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1163. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getReadyCommissionFeevalue());
  1164. settlementDocumentaryLogEntity.setIds(insPlyIncomeVo.getIds());
  1165. settlementDocumentaryLogEntity.setCreateTime(new Date());
  1166. settlementDocumentaryLogEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  1167. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1168. return HttpResult.ok();
  1169. }
  1170. @Override
  1171. public HttpResult<InsPlyIncome> querySettInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1172. HashMap<String, Object> params = new HashMap<>();
  1173. params = this.saveParams(insPlyIncomeVo, params);
  1174. InsPlyIncome insPlyIncome = baseMapper.queryInvoicing(params); //已经开票
  1175. return HttpResult.ok(insPlyIncome);
  1176. }
  1177. /**
  1178. *
  1179. * @param insPlyIncomeVo
  1180. * @return
  1181. */
  1182. @Override
  1183. public HttpResult<List<InsPlyIncome>> allOtherAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1184. HashMap<String, Object> params = new HashMap<>();
  1185. params = this.saveParams(insPlyIncomeVo, params);
  1186. List<InsPlyIncome> result = baseMapper.allOtherAmount(params);
  1187. List<HashMap<String, Object>> otherIds = baseMapper.getOtherIds(params);
  1188. List<HashMap<String, Object>> invoicIds = settlementDocumentaryFeesService.getInvoicIds(params);
  1189. this.splicingOtherIds(result,otherIds,invoicIds);
  1190. return HttpResult.ok(result);
  1191. }
  1192. /**
  1193. *
  1194. * @param result 返回的数据
  1195. * @param otherIds ins_ply_income 跟单费
  1196. * @param invoicIds settlement_documentary_fees 开票ids
  1197. */
  1198. private void splicingOtherIds(List<InsPlyIncome> result, List<HashMap<String, Object>> otherIds, List<HashMap<String, Object>> invoicIds) {
  1199. // 创建两个映射来分别存储companyId到ids和setIncomeIds的映射
  1200. Map<String, List<String>> companyIdToIdsMap = new HashMap<>();
  1201. Map<String, List<String>> companyIdToSetIncomeIdsMap = new HashMap<>();
  1202. // 处理otherIds,填充companyId到ids的映射
  1203. for (HashMap<String, Object> idMap : otherIds) {
  1204. String companyId = (String) idMap.get("companyId");
  1205. String id = idMap.get("id").toString(); // 假设id是一个String,而不是List<String>
  1206. if (companyId != null && id != null) {
  1207. companyIdToIdsMap.computeIfAbsent(companyId, k -> new ArrayList<>()).add(id); // 将id添加到列表中
  1208. }
  1209. }
  1210. // 处理invoicIds,填充companyId到setIncomeIds的映射(假设结构相同)
  1211. for (HashMap<String, Object> idMap : invoicIds) {
  1212. String companyId = (String) idMap.get("companyId");
  1213. String setIncomeId = idMap.get("id").toString(); // 假设这里也是单个id,键名可能不同,例如"setIncomeId"
  1214. if (companyId != null && setIncomeId != null) {
  1215. companyIdToSetIncomeIdsMap.computeIfAbsent(companyId, k -> new ArrayList<>()).add(setIncomeId);
  1216. }
  1217. }
  1218. // 遍历result列表,为每个InsPlyIncome对象设置拼接后的ids和incomeIds
  1219. for (InsPlyIncome resultItem : result) {
  1220. String companyId = resultItem.getCompanyId();
  1221. List<String> ids = companyIdToIdsMap.getOrDefault(companyId, Collections.emptyList());
  1222. List<String> setIncomeIds = companyIdToSetIncomeIdsMap.getOrDefault(companyId, Collections.emptyList());
  1223. // 合并ids和setIncomeIds(如果需要,可以先去重),但在此处我们直接拼接
  1224. String idsString = String.join(",", ids);
  1225. String incomeIdsString = String.join(",", setIncomeIds);
  1226. // 设置拼接后的ids和incomeIds到InsPlyIncome对象中
  1227. resultItem.setIds(idsString);
  1228. resultItem.setIncomeIds(incomeIdsString); // 假设InsPlyIncome有这个方法
  1229. }
  1230. }
  1231. @Override
  1232. @Transactional
  1233. public HttpResult<Object> batchInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  1234. // 通过ids 查出跟单非结算单
  1235. String ids = insPlyIncomeVo.getIds();
  1236. if(StringUtils.isNotEmpty(ids)){
  1237. String[] split = ids.split(",");
  1238. for (int i =0; i <split.length ; i++) {
  1239. String id = split[i];
  1240. InsPlyIncome insPlyIncome = baseMapper.selectById(id);
  1241. insPlyIncome.setInvoicId(insPlyIncomeVo.getContractId()); // 开票号
  1242. insPlyIncome.setContractFileId(insPlyIncomeVo.getContractFileId());
  1243. insPlyIncome.setVoucherNumber(insPlyIncomeVo.getVoucherNumber());
  1244. insPlyIncome.setSettlementTime(LocalDate.now());
  1245. baseMapper.updateById(insPlyIncome);
  1246. }
  1247. }
  1248. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  1249. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1250. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  1251. }
  1252. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1253. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  1254. }
  1255. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  1256. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  1257. }
  1258. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDay())){
  1259. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  1260. }
  1261. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  1262. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  1263. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  1264. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  1265. settlementDocumentaryFeesVo.setCreateTime(LocalDate.now());
  1266. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIncomeIds());
  1267. settlementDocumentaryFeesVo.setSettlementStatus("1");
  1268. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1269. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId());
  1270. return settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1271. }
  1272. @Override
  1273. public HttpResult pinHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1274. HashMap<String, Object> params = new HashMap<>();
  1275. params =this.saveParams(insPlyIncomeVo,params);
  1276. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1277. ExportParams exportParams = new ExportParams("平台手续费", null, ExcelType.HSSF);
  1278. exportParams.setStyle(ExcelStyleUtil.class);
  1279. List<SettlementFeesExcel> resultList = new ArrayList<>();
  1280. for (InsPlyIncome item :insPlyIncomes){
  1281. SettlementFeesExcel bxSettlementFeesExcel = new SettlementFeesExcel();
  1282. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1283. if("1".equals(item.getHandlingFeesStatus())){
  1284. bxSettlementFeesExcel.setHandlingFeesStatus("已结算");
  1285. }else {
  1286. bxSettlementFeesExcel.setHandlingFeesStatus("未结算");
  1287. }
  1288. resultList.add(bxSettlementFeesExcel);
  1289. }
  1290. String uploadPath = this.uploadPath + "/excel/";
  1291. Path path = Paths.get(uploadPath);
  1292. if (!Files.exists(path)) {
  1293. try {
  1294. Files.createDirectories(path);
  1295. } catch (IOException e) {
  1296. e.printStackTrace();
  1297. }
  1298. }
  1299. String fileName = EasyExcelUtils.downExcel(uploadPath, "平台手续费导出", SettlementFeesExcel.class, resultList);
  1300. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1301. }
  1302. @Override
  1303. public HttpResult bxHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1304. HashMap<String, Object> params = new HashMap<>();
  1305. params =this.saveParams(insPlyIncomeVo,params);
  1306. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1307. ExportParams exportParams = new ExportParams("保险手续费", null, ExcelType.HSSF);
  1308. exportParams.setStyle(ExcelStyleUtil.class);
  1309. List<BxSettlementFeesExcel> resultList = new ArrayList<>();
  1310. for (InsPlyIncome item :insPlyIncomes){
  1311. BxSettlementFeesExcel bxSettlementFeesExcel = new BxSettlementFeesExcel();
  1312. LocalDateTime signDate = item.getSignDate();
  1313. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1314. resultList.add(bxSettlementFeesExcel);
  1315. }
  1316. String uploadPath = this.uploadPath + "/excel/";
  1317. Path path = Paths.get(uploadPath);
  1318. if (!Files.exists(path)) {
  1319. try {
  1320. Files.createDirectories(path);
  1321. } catch (IOException e) {
  1322. e.printStackTrace();
  1323. }
  1324. }
  1325. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险手续费导出", BxSettlementFeesExcel.class, resultList);
  1326. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1327. }
  1328. @Override
  1329. public HttpResult bxOtherExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1330. HashMap<String, Object> params = new HashMap<>();
  1331. params =this.saveParams(insPlyIncomeVo,params);
  1332. params.put("agreementType","2");
  1333. params.put("isOther","1");
  1334. params.put("isNotCar","0");
  1335. List<InsPlyIncome> insPlyIncomes = baseMapper.allOtherAmount(params);
  1336. ExportParams exportParams = new ExportParams("跟单费导出", null, ExcelType.HSSF);
  1337. exportParams.setStyle(ExcelStyleUtil.class);
  1338. List<BxOtherExcel> resultList = new ArrayList<>();
  1339. for (InsPlyIncome item :insPlyIncomes){
  1340. BxOtherExcel bxSettlementFeesExcel = new BxOtherExcel();
  1341. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1342. resultList.add(bxSettlementFeesExcel);
  1343. }
  1344. String uploadPath = this.uploadPath + "/excel/";
  1345. Path path = Paths.get(uploadPath);
  1346. if (!Files.exists(path)) {
  1347. try {
  1348. Files.createDirectories(path);
  1349. } catch (IOException e) {
  1350. e.printStackTrace();
  1351. }
  1352. }
  1353. String fileName = EasyExcelUtils.downExcel(uploadPath, "跟单费导出", BxOtherExcel.class, resultList);
  1354. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1355. }
  1356. @Override
  1357. public InsPlyIncome bxTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1358. HashMap<String, Object> params = new HashMap<>();
  1359. params = this.saveParams(insPlyIncomeVo, params);
  1360. InsPlyIncome totalledAmount =baseMapper.bxTotalAmount(params); //总金额
  1361. return totalledAmount;
  1362. }
  1363. }