InsPlyIncomeServiceImpl.java 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  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. HashMap<String, Object> params = new HashMap<>();
  772. params= this.saveParams(insPlyIncomeVo,params);
  773. List<HashMap<String,Object>> result= this.baseMapper.groupByInvoic(params);
  774. return HttpResult.ok(result);
  775. }
  776. /***
  777. *
  778. * @param insPlyIncomeVo
  779. * @param request
  780. * @param response
  781. * @return 保险非车跟单明细导出
  782. */
  783. @Override
  784. public HttpResult bxNoOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  785. HashMap<String, Object> params = new HashMap<>();
  786. params =this.saveParams(insPlyIncomeVo,params);
  787. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  788. ExportParams exportParams = new ExportParams("保险非车跟单明细导出", null, ExcelType.HSSF);
  789. exportParams.setStyle(ExcelStyleUtil.class);
  790. List<BxNoOtherDetailsExcel> resultList = new ArrayList<>();
  791. for (InsPlyIncome item :insPlyIncomes){
  792. BxNoOtherDetailsExcel bxNoOtherDetailsExcel = new BxNoOtherDetailsExcel();
  793. BeanUtils.copyProperties(item, bxNoOtherDetailsExcel);
  794. resultList.add(bxNoOtherDetailsExcel);
  795. }
  796. String uploadPath = this.uploadPath + "/excel/";
  797. Path path = Paths.get(uploadPath);
  798. if (!Files.exists(path)) {
  799. try {
  800. Files.createDirectories(path);
  801. } catch (IOException e) {
  802. e.printStackTrace();
  803. }
  804. }
  805. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险非车跟单明细导出", BxNoOtherDetailsExcel.class, resultList);
  806. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  807. }
  808. /**
  809. *
  810. * @param insPlyIncomeVo 开票ids
  811. * @return 返回开票号 开票金额 开票时间
  812. */
  813. @Override
  814. public HttpResult<List<HashMap<String, Object>>> otherSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  815. HashMap<String, Object> params = new HashMap<>();
  816. params =this.saveParams(insPlyIncomeVo,params);
  817. List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(params);
  818. if (resultList.size() > 0) {
  819. return HttpResult.ok(resultList);
  820. }
  821. return HttpResult.ok();
  822. }
  823. @Override
  824. public InsPlyIncome getEntityById(String id) {
  825. return baseMapper.getEntityById(id);
  826. }
  827. @Override
  828. @Transactional
  829. public void updateByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  830. // 根据协议 如果是含增值税结算 用保费 * 如果是 不含税保费
  831. InsPlyIncome insPlyIncome = new InsPlyIncome();
  832. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  833. this.amountCalculate(insPlyIncomeVo,insPlyIncome);
  834. baseMapper.updateById(insPlyIncome);
  835. insPlyIncomeVo.setCrudStatus("2");
  836. this.saveLog(insPlyIncomeVo);
  837. }
  838. /**
  839. *
  840. * @param insPlyIncomeVo
  841. * @param insPlyIncome
  842. *
  843. * 重新计算金额 通过比例
  844. * 计算逻辑 交强不含税保费* 交强跟单比例 = 交强跟单金额
  845. */
  846. private void amountCalculate(InsPlyIncomeVo insPlyIncomeVo,InsPlyIncome insPlyIncome) {
  847. if("1".equals(insPlyIncomeVo.getAgreementType())){ //平台
  848. // 平台 手续费 +跟单费 = 应收 手续费 = 手续费比例*保费 应收比例=手续费比例 + 跟单比例
  849. BigDecimal jqSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqSuperviseCostsProportion());//交强手续费比例
  850. BigDecimal sySuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSySuperviseCostsProportion()); //商业手续费比例
  851. BigDecimal noSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoSuperviseCostsProportion()); //非车手续费比例
  852. BigDecimal jqOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqOtherCostsProportion()); //交强跟单比例
  853. BigDecimal syOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSyOtherCostsProportion()); //商业跟单比例
  854. BigDecimal noOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoOtherCostsProportion()); //非车跟单比例
  855. BigDecimal jqPremium = initializationBigdecimal(insPlyIncomeVo.getJqPremium()); //交强保费
  856. BigDecimal syPremium = initializationBigdecimal(insPlyIncomeVo.getSyPremium()); //商业保费
  857. BigDecimal noPremium = initializationBigdecimal(insPlyIncomeVo.getNoPremium()); //非车保费
  858. //手续费比例
  859. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion,sySuperviseCostsProportion,noSuperviseCostsProportion)); //手续费比例 = 商业手续费比例 + 交强手续费比例 + 非车手续费比例
  860. if(jqSuperviseCostsProportion !=null && jqPremium!=null ){
  861. insPlyIncome.setJqSuperviseCostsPremiums(this.algorithmAmount(jqPremium,jqSuperviseCostsProportion)); //交强手续费
  862. }
  863. if(sySuperviseCostsProportion !=null && syPremium !=null){
  864. insPlyIncome.setSySuperviseCostsPremiums(this.algorithmAmount(syPremium,sySuperviseCostsProportion)); //商业手续费
  865. }
  866. if(noSuperviseCostsProportion !=null && noPremium!=null){
  867. insPlyIncome.setNoSuperviseCostsPremiums(this.algorithmAmount(noPremium,noSuperviseCostsProportion)); //非车手续费
  868. }
  869. if(jqOtherCostsProportion !=null && jqPremium!=null ){
  870. insPlyIncome.setJqOtherCostsPremium(this.algorithmAmount(jqPremium,jqOtherCostsProportion)); //交强跟单费
  871. }
  872. if(syOtherCostsProportion !=null && syPremium !=null ){
  873. insPlyIncome.setSyOtherCostsPremium(this.algorithmAmount(syPremium,syOtherCostsProportion)); //商业跟单费
  874. }
  875. if(noOtherCostsProportion !=null && noPremium !=null){
  876. insPlyIncome.setNoOtherCostsPremium(this.algorithmAmount(noPremium,noOtherCostsProportion)); //非车跟单费
  877. }
  878. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),insPlyIncome.getNoSuperviseCostsPremiums())); //手续费
  879. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion,sySuperviseCostsProportion,noSuperviseCostsProportion)); //手续费比例
  880. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),insPlyIncome.getNoOtherCostsPremium())); //跟单费金额
  881. insPlyIncome.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion,syOtherCostsProportion,noOtherCostsProportion)); //跟单费比例
  882. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),insPlyIncome.getOtherFeevalue(),null)); // 总费用 = 手续费+跟单费
  883. //应收比例 交强应收比例=交强手续费比例+交强非跟单比例
  884. insPlyIncome.setJqReceivableProportion(this.calculateTotal(jqSuperviseCostsProportion,jqOtherCostsProportion,null)); //交强应收
  885. insPlyIncome.setSyReceivableProportion(this.calculateTotal(sySuperviseCostsProportion,syOtherCostsProportion,null)); //商业应收
  886. insPlyIncome.setNoReceivableProportion(this.calculateTotal(noSuperviseCostsProportion,noOtherCostsProportion,null)); //非车应收
  887. }else {
  888. BigDecimal jqNoTaxPremium = insPlyIncomeVo.getJqNoTaxPremium();// 交强手续费 按照思路 交强不含税保费* 交强手续费比例 =交强手续费
  889. BigDecimal syNoTaxPremium = insPlyIncomeVo.getSyNoTaxPremium();// 商业手续费 按照思路 商业不含税保费* 商业手续费比例 =商业手续费
  890. BigDecimal noNoTaxPremium = insPlyIncomeVo.getNoNoTaxPremium();// 非车手续费 按照思路 非车不含税保费* 非车手续费比例 =非车手续费
  891. if(insPlyIncomeVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  892. BigDecimal jqhandingFee = jqNoTaxPremium.multiply(insPlyIncomeVo.getJqSuperviseCostsProportion().divide(new BigDecimal(100)));
  893. insPlyIncome.setJqSuperviseCostsPremiums(jqhandingFee);
  894. }
  895. if(insPlyIncomeVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  896. BigDecimal syhandingFee = syNoTaxPremium.multiply(insPlyIncomeVo.getSySuperviseCostsProportion().divide(new BigDecimal(100)));
  897. insPlyIncome.setSySuperviseCostsPremiums(syhandingFee);
  898. }
  899. if(insPlyIncomeVo.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  900. BigDecimal nohandingFee = noNoTaxPremium.multiply(insPlyIncomeVo.getNoSuperviseCostsProportion().divide(new BigDecimal(100)));
  901. insPlyIncome.setNoSuperviseCostsPremiums(nohandingFee);
  902. }
  903. if(insPlyIncomeVo.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  904. BigDecimal jqother = jqNoTaxPremium.multiply(insPlyIncomeVo.getJqOtherCostsProportion().divide(new BigDecimal(100)));//交强跟单费 按照思路 交强不含税保费* 交强跟单比例 = 交强跟单金额
  905. insPlyIncome.setJqOtherCostsPremium(jqother);
  906. }
  907. if(insPlyIncomeVo.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  908. BigDecimal syother = syNoTaxPremium.multiply(insPlyIncomeVo.getSyOtherCostsProportion().divide(new BigDecimal(100)));//交强跟单费 按照思路 交强不含税保费* 交强跟单比例 = 交强跟单金额
  909. insPlyIncome.setSyOtherCostsPremium(syother);
  910. }
  911. if(insPlyIncomeVo.getNoOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  912. BigDecimal syother = syNoTaxPremium.multiply(insPlyIncomeVo.getNoOtherCostsProportion().divide(new BigDecimal(100)));//非车跟单费 按照思路 非车不含税保费* 非车跟单比例 = 非车跟单金额
  913. insPlyIncome.setNoOtherCostsPremium(syother);
  914. }
  915. if("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())){ //保险 手续费 =不含税保费* 手续费比例
  916. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),null)); // 手续费
  917. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(),insPlyIncome.getSySuperviseCostsProportion(),null));//手续费比例
  918. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),null,null));//总金额
  919. }else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())){ //保险跟单费 交强跟单+商业跟单
  920. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),null));
  921. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getJqOtherCostsProportion(),insPlyIncome.getSyOtherCostsProportion(),null));
  922. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(),null,null));//总金额
  923. }
  924. if("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())){// 非车
  925. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getNoSuperviseCostsPremiums(),null,null)); // 非车手续费
  926. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getNoSuperviseCostsProportion(),null,null)); //非车比例
  927. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),null,null));//总金额
  928. }else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())){ //非车跟单
  929. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getNoOtherCostsPremium(),null,null)); //非车跟单金额
  930. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getNoOtherCostsProportion(),null,null)); // 非车跟单比例
  931. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(),null,null));//总金额
  932. }
  933. }
  934. }
  935. /**
  936. *
  937. * @param value1 保费
  938. * @param value2 比例
  939. * @return 费用
  940. */
  941. private BigDecimal algorithmAmount(BigDecimal value1, BigDecimal value2) {
  942. return value1.multiply(value2.divide(new BigDecimal(100)));
  943. }
  944. private BigDecimal initializationBigdecimal(BigDecimal value) {
  945. return value != null ? value : BigDecimal.ZERO;
  946. }
  947. private void saveLog(InsPlyIncomeVo insPlyIncomeVo) {
  948. // 添加记录
  949. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  950. settlementDocumentaryLogEntity.setCrudStatus(insPlyIncomeVo.getCrudStatus());
  951. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue());
  952. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId());
  953. settlementDocumentaryLogEntity.setAmountType("2");
  954. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  955. }
  956. @Override
  957. @Transactional
  958. public HttpResult<InsPlyIncome> insertByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  959. Long id = new SnowFlakeUtil().nextId();
  960. InsPlyIncome insPlyIncome = new InsPlyIncome();
  961. insPlyIncomeVo.setOrderno(id.toString());
  962. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  963. insPlyIncome.setDocumentaryFeesStatus("0");
  964. insPlyIncome.setHandlingFeesStatus("0");
  965. insPlyIncome.setIsNotCar("0");
  966. insPlyIncome.setIsNotDocumentary("1");
  967. baseMapper.insert(insPlyIncome);
  968. insPlyIncomeVo.setId(insPlyIncome.getId());
  969. insPlyIncomeVo.setCrudStatus("1");
  970. this.saveLog(insPlyIncomeVo); //添加日志
  971. HashMap<String, Object> params = new HashMap<>();
  972. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  973. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  974. }
  975. params.put("isOther","1");
  976. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  977. params.put("year",insPlyIncomeVo.getYear());
  978. }
  979. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  980. params.put("companyId",insPlyIncomeVo.getCompanyId());
  981. }
  982. List<InsPlyIncome> list= this.baseMapper.NonSettlementQuery(params);
  983. if(!CollectionUtils.isEmpty(list)){
  984. for (InsPlyIncome item :list){
  985. return HttpResult.ok(item.getIds());
  986. }
  987. }
  988. return null;
  989. }
  990. @Override
  991. @Transactional
  992. public HttpResult<InsPlyIncome> deleteById(InsPlyIncomeVo insPlyIncomeVo) {
  993. HashMap<String, Object> params = new HashMap<>();
  994. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  995. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  996. }
  997. params.put("isOther","1");
  998. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  999. params.put("year",insPlyIncomeVo.getYear());
  1000. }
  1001. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1002. params.put("companyId",insPlyIncomeVo.getCompanyId());
  1003. }
  1004. baseMapper.deleteById(insPlyIncomeVo.getId());
  1005. insPlyIncomeVo.setCrudStatus("3");
  1006. this.saveLog(insPlyIncomeVo);
  1007. List<InsPlyIncome> list = this.baseMapper.NonSettlementQuery(params);
  1008. if (!CollectionUtils.isEmpty(list)) {
  1009. for (InsPlyIncome item : list) {
  1010. return HttpResult.ok(item.getIds());
  1011. }
  1012. } else {
  1013. return HttpResult.ok(null);
  1014. }
  1015. return HttpResult.ok("删除成功");
  1016. }
  1017. @Override
  1018. @Transactional
  1019. public void uodateBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1020. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1021. insPlyIncomeVo.setHandlingFeesStatus("1");
  1022. insPlyIncomeVo.setSettlementTime(LocalDate.now());
  1023. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1024. baseMapper.updateById(insPlyIncome);
  1025. // 生成记录
  1026. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1027. if(StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType()) && "1".equals(insPlyIncomeVo.getAgreementType())){
  1028. // 只有平台协议 才会跟单费一笔结算
  1029. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); // 跟单费金额
  1030. }
  1031. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); // 手续费金额
  1032. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId()); // 关联id
  1033. settlementDocumentaryLogEntity.setAmountType("1"); //手续费结算
  1034. settlementDocumentaryLogEntity.setCreateTime(new Date());
  1035. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1036. }
  1037. @Override
  1038. @Transactional
  1039. public HttpResult<BasePageResult<InsPlyIncome>> totalQuery(InsPlyIncomeVo insPlyIncomeVo) {
  1040. HashMap<String, Object> params = new HashMap<>();
  1041. PageInfo<List<InsPlyIncome>> pageHelper = null;
  1042. if(insPlyIncomeVo.getStartDate()!=null){
  1043. params.put("startDate",insPlyIncomeVo.getStartDate().toString());
  1044. }
  1045. if(insPlyIncomeVo.getEndDate()!=null){
  1046. params.put("endDate",insPlyIncomeVo.getEndDate().toString());
  1047. }
  1048. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1049. params.put("year",insPlyIncomeVo.getYear());
  1050. }
  1051. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  1052. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  1053. }
  1054. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  1055. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  1056. }
  1057. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())){
  1058. params.put("documentaryFeesStatus",insPlyIncomeVo.getDocumentaryFeesStatus());
  1059. }
  1060. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1061. params.put("companyId",insPlyIncomeVo.getCompanyId());
  1062. }
  1063. params.put("pageNum",insPlyIncomeVo.getPageNum());
  1064. params.put("pageSize",insPlyIncomeVo.getPageSize());
  1065. List<InsPlyIncome> list= this.baseMapper.totalQuery(params);
  1066. pageHelper=new PageInfo(list);
  1067. return HttpResult.ok(new BasePageResult<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list));
  1068. }
  1069. /**
  1070. *
  1071. * @param insPlyIncomeVo ids ins_ply_income 这个表的ids incomeIds settlement_documentary_fees 这个表的ids
  1072. * @return
  1073. */
  1074. @Override
  1075. @Transactional
  1076. public HttpResult batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1077. // 通过ids 查出跟单非结算单
  1078. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){
  1079. settlementDocumentaryFeesService.batchByInvoice(insPlyIncomeVo.getIds());
  1080. }
  1081. return HttpResult.ok();
  1082. }
  1083. /**
  1084. *
  1085. * @param insPlyIncomeVo
  1086. * @return
  1087. */
  1088. @Override
  1089. public List<InsPlyIncome> totalBxAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1090. HashMap<String, Object> params = new HashMap<>();
  1091. params=this.saveParams(insPlyIncomeVo,params);
  1092. params.remove("handlingFeesStatus");
  1093. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  1094. // 数据库数据太多是 用sql拼接id会丢失 所以只能逻辑拼接
  1095. List<InsPlyIncome> idList=baseMapper.getIncomeIdList(params);
  1096. if(!CollectionUtils.isEmpty(idList) && !CollectionUtils.isEmpty(resultList)){
  1097. this.splicingIds(idList,resultList);
  1098. }
  1099. return resultList;
  1100. }
  1101. /**
  1102. *
  1103. * @param idList 要开票的数据集合
  1104. * @param resultList 总返回数据
  1105. */
  1106. private void splicingIds(List<InsPlyIncome> idList, List<InsPlyIncome> resultList) {
  1107. // 使用Map来存储agreementId到其id列表的映射
  1108. Map<String, List<String>> idMap = new HashMap<>();
  1109. for (InsPlyIncome idItem : idList) {
  1110. String partnerCompaniesId = idItem.getPartnerCompaniesId();
  1111. idMap.computeIfAbsent(partnerCompaniesId, k -> new ArrayList<>()).add(idItem.getId());
  1112. }
  1113. for (InsPlyIncome resultItem : resultList) {
  1114. List<String> ids = idMap.getOrDefault(resultItem.getPartnerCompaniesId(), Collections.emptyList());
  1115. String idsString = String.join(",", ids);
  1116. resultItem.setIds(idsString);
  1117. }
  1118. }
  1119. @Override
  1120. @Transactional
  1121. public HttpResult<Object> batchInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1122. // 开票时生成 记录 用来合计已经开票数据
  1123. String ids = insPlyIncomeVo.getIds();
  1124. if(StringUtils.isNotEmpty(ids)){
  1125. String[] split = ids.split(",");
  1126. for (String id : split){
  1127. InsPlyIncome insPlyIncome = baseMapper.selectById(id);
  1128. insPlyIncome.setInvoicTime(LocalDate.now()); //开票时间
  1129. insPlyIncome.setInvoicId(insPlyIncomeVo.getInvoicId()); //开票号
  1130. insPlyIncome.setHandlingFeesStatus("2"); //2为开票
  1131. baseMapper.updateById(insPlyIncome);
  1132. }
  1133. }
  1134. return HttpResult.ok();
  1135. }
  1136. @Override
  1137. public HttpResult<InsPlyIncome> queryInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1138. HashMap<String, Object> params = new HashMap<>();
  1139. params = this.saveParams(insPlyIncomeVo, params);
  1140. InsPlyIncome result= baseMapper.queryInvoicing(params); //总金额
  1141. params.put("handlingFeesStatus","0");
  1142. InsPlyIncome noResult= baseMapper.queryInvoicing(params); //未结算金额
  1143. result.setReadyCommissionFeevalue(noResult.getCommissionFeevalue());
  1144. return HttpResult.ok(result);
  1145. }
  1146. @Override
  1147. public HttpResult<Object> batchBxBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1148. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1149. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){
  1150. String[] split = insPlyIncomeVo.getIds().split(",");
  1151. for(String id : split){
  1152. insPlyIncome.setId(id);
  1153. insPlyIncome.setHandlingFeesStatus("1");
  1154. insPlyIncome.setSettlementTime(LocalDate.now());
  1155. baseMapper.updateById(insPlyIncome);
  1156. }
  1157. }
  1158. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1159. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getReadyCommissionFeevalue());
  1160. settlementDocumentaryLogEntity.setIds(insPlyIncomeVo.getIds());
  1161. settlementDocumentaryLogEntity.setCreateTime(new Date());
  1162. settlementDocumentaryLogEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  1163. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1164. return HttpResult.ok();
  1165. }
  1166. @Override
  1167. public HttpResult<InsPlyIncome> querySettInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1168. HashMap<String, Object> params = new HashMap<>();
  1169. params = this.saveParams(insPlyIncomeVo, params);
  1170. InsPlyIncome insPlyIncome = baseMapper.queryInvoicing(params); //已经开票
  1171. return HttpResult.ok(insPlyIncome);
  1172. }
  1173. /**
  1174. *
  1175. * @param insPlyIncomeVo
  1176. * @return
  1177. */
  1178. @Override
  1179. public HttpResult<List<InsPlyIncome>> allOtherAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1180. HashMap<String, Object> params = new HashMap<>();
  1181. params = this.saveParams(insPlyIncomeVo, params);
  1182. List<InsPlyIncome> result = baseMapper.allOtherAmount(params);
  1183. List<HashMap<String, Object>> otherIds = baseMapper.getOtherIds(params);
  1184. List<HashMap<String, Object>> invoicIds = settlementDocumentaryFeesService.getInvoicIds(params);
  1185. this.splicingOtherIds(result,otherIds,invoicIds);
  1186. return HttpResult.ok(result);
  1187. }
  1188. /**
  1189. *
  1190. * @param result 返回的数据
  1191. * @param otherIds ins_ply_income 跟单费
  1192. * @param invoicIds settlement_documentary_fees 开票ids
  1193. */
  1194. private void splicingOtherIds(List<InsPlyIncome> result, List<HashMap<String, Object>> otherIds, List<HashMap<String, Object>> invoicIds) {
  1195. // 创建两个映射来分别存储companyId到ids和setIncomeIds的映射
  1196. Map<String, List<String>> companyIdToIdsMap = new HashMap<>();
  1197. Map<String, List<String>> companyIdToSetIncomeIdsMap = new HashMap<>();
  1198. // 处理otherIds,填充companyId到ids的映射
  1199. for (HashMap<String, Object> idMap : otherIds) {
  1200. String partnerCompaniesId = (String) idMap.get("partnerCompaniesId");
  1201. String id = idMap.get("id").toString(); // 假设id是一个String,而不是List<String>
  1202. if (partnerCompaniesId != null && id != null) {
  1203. companyIdToIdsMap.computeIfAbsent(partnerCompaniesId, k -> new ArrayList<>()).add(id); // 将id添加到列表中
  1204. }
  1205. }
  1206. // 处理invoicIds,填充companyId到setIncomeIds的映射(假设结构相同)
  1207. for (HashMap<String, Object> idMap : invoicIds) {
  1208. String partnerCompaniesId = (String) idMap.get("partnerCompaniesId");
  1209. String setIncomeId = idMap.get("id").toString(); // 假设这里也是单个id,键名可能不同,例如"setIncomeId"
  1210. if (partnerCompaniesId != null && setIncomeId != null) {
  1211. companyIdToSetIncomeIdsMap.computeIfAbsent(partnerCompaniesId, k -> new ArrayList<>()).add(setIncomeId);
  1212. }
  1213. }
  1214. // 遍历result列表,为每个InsPlyIncome对象设置拼接后的ids和incomeIds
  1215. for (InsPlyIncome resultItem : result) {
  1216. String partnerCompaniesId = resultItem.getPartnerCompaniesId();
  1217. List<String> ids = companyIdToIdsMap.getOrDefault(partnerCompaniesId, Collections.emptyList());
  1218. List<String> setIncomeIds = companyIdToSetIncomeIdsMap.getOrDefault(partnerCompaniesId, Collections.emptyList());
  1219. // 合并ids和setIncomeIds(如果需要,可以先去重),但在此处我们直接拼接
  1220. String idsString = String.join(",", ids);
  1221. String incomeIdsString = String.join(",", setIncomeIds);
  1222. // 设置拼接后的ids和incomeIds到InsPlyIncome对象中
  1223. resultItem.setIds(idsString);
  1224. resultItem.setIncomeIds(incomeIdsString); // 假设InsPlyIncome有这个方法
  1225. }
  1226. }
  1227. @Override
  1228. @Transactional
  1229. public HttpResult<Object> batchInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  1230. // 通过ids 查出跟单非结算单
  1231. String ids = insPlyIncomeVo.getIds();
  1232. // if(StringUtils.isNotEmpty(ids)){
  1233. // String[] split = ids.split(",");
  1234. // for (int i =0; i <split.length ; i++) {
  1235. // String id = split[i];
  1236. // InsPlyIncome insPlyIncome = baseMapper.selectById(id);
  1237. // insPlyIncome.setInvoicId(insPlyIncomeVo.getContractId()); // 开票号
  1238. // insPlyIncome.setContractFileId(insPlyIncomeVo.getContractFileId());
  1239. // insPlyIncome.setVoucherNumber(insPlyIncomeVo.getVoucherNumber());
  1240. // insPlyIncome.setSettlementTime(LocalDate.now());
  1241. // baseMapper.updateById(insPlyIncome);
  1242. // }
  1243. // }
  1244. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  1245. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1246. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  1247. }
  1248. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1249. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  1250. }
  1251. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  1252. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  1253. }
  1254. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDay())){
  1255. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  1256. }
  1257. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  1258. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());
  1259. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  1260. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  1261. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  1262. settlementDocumentaryFeesVo.setCreateTime(LocalDate.now());
  1263. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIncomeIds());
  1264. settlementDocumentaryFeesVo.setSettlementStatus("1");
  1265. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1266. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  1267. return settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1268. }
  1269. @Override
  1270. public HttpResult pinHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1271. HashMap<String, Object> params = new HashMap<>();
  1272. params =this.saveParams(insPlyIncomeVo,params);
  1273. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1274. ExportParams exportParams = new ExportParams("平台手续费", null, ExcelType.HSSF);
  1275. exportParams.setStyle(ExcelStyleUtil.class);
  1276. List<SettlementFeesExcel> resultList = new ArrayList<>();
  1277. for (InsPlyIncome item :insPlyIncomes){
  1278. SettlementFeesExcel bxSettlementFeesExcel = new SettlementFeesExcel();
  1279. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1280. if("1".equals(item.getHandlingFeesStatus())){
  1281. bxSettlementFeesExcel.setHandlingFeesStatus("已结算");
  1282. }else {
  1283. bxSettlementFeesExcel.setHandlingFeesStatus("未结算");
  1284. }
  1285. resultList.add(bxSettlementFeesExcel);
  1286. }
  1287. String uploadPath = this.uploadPath + "/excel/";
  1288. Path path = Paths.get(uploadPath);
  1289. if (!Files.exists(path)) {
  1290. try {
  1291. Files.createDirectories(path);
  1292. } catch (IOException e) {
  1293. e.printStackTrace();
  1294. }
  1295. }
  1296. String fileName = EasyExcelUtils.downExcel(uploadPath, "平台手续费导出", SettlementFeesExcel.class, resultList);
  1297. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1298. }
  1299. @Override
  1300. public HttpResult bxHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1301. HashMap<String, Object> params = new HashMap<>();
  1302. params =this.saveParams(insPlyIncomeVo,params);
  1303. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1304. ExportParams exportParams = new ExportParams("保险手续费", null, ExcelType.HSSF);
  1305. exportParams.setStyle(ExcelStyleUtil.class);
  1306. List<BxSettlementFeesExcel> resultList = new ArrayList<>();
  1307. for (InsPlyIncome item :insPlyIncomes){
  1308. BxSettlementFeesExcel bxSettlementFeesExcel = new BxSettlementFeesExcel();
  1309. LocalDateTime signDate = item.getSignDate();
  1310. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1311. resultList.add(bxSettlementFeesExcel);
  1312. }
  1313. String uploadPath = this.uploadPath + "/excel/";
  1314. Path path = Paths.get(uploadPath);
  1315. if (!Files.exists(path)) {
  1316. try {
  1317. Files.createDirectories(path);
  1318. } catch (IOException e) {
  1319. e.printStackTrace();
  1320. }
  1321. }
  1322. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险手续费导出", BxSettlementFeesExcel.class, resultList);
  1323. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1324. }
  1325. @Override
  1326. public HttpResult bxOtherExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1327. HashMap<String, Object> params = new HashMap<>();
  1328. params =this.saveParams(insPlyIncomeVo,params);
  1329. params.put("agreementType","2");
  1330. params.put("isOther","1");
  1331. params.put("isNotCar","0");
  1332. List<InsPlyIncome> insPlyIncomes = baseMapper.allOtherAmount(params);
  1333. ExportParams exportParams = new ExportParams("跟单费导出", null, ExcelType.HSSF);
  1334. exportParams.setStyle(ExcelStyleUtil.class);
  1335. List<BxOtherExcel> resultList = new ArrayList<>();
  1336. for (InsPlyIncome item :insPlyIncomes){
  1337. BxOtherExcel bxSettlementFeesExcel = new BxOtherExcel();
  1338. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1339. resultList.add(bxSettlementFeesExcel);
  1340. }
  1341. String uploadPath = this.uploadPath + "/excel/";
  1342. Path path = Paths.get(uploadPath);
  1343. if (!Files.exists(path)) {
  1344. try {
  1345. Files.createDirectories(path);
  1346. } catch (IOException e) {
  1347. e.printStackTrace();
  1348. }
  1349. }
  1350. String fileName = EasyExcelUtils.downExcel(uploadPath, "跟单费导出", BxOtherExcel.class, resultList);
  1351. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1352. }
  1353. @Override
  1354. public InsPlyIncome bxTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1355. HashMap<String, Object> params = new HashMap<>();
  1356. params = this.saveParams(insPlyIncomeVo, params);
  1357. InsPlyIncome totalledAmount =baseMapper.bxTotalAmount(params); //总金额
  1358. return totalledAmount;
  1359. }
  1360. }