InsPlyIncomeServiceImpl.java 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  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.setUserId(insFeeOrderNew.getUserId());
  317. insPlyIncome.setInsuredName(order.getInsuredname());
  318. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  319. baseMapper.insert(insPlyIncome);
  320. }
  321. private void saveByCompanyId(InsFeeOrderNew insFeeOrderNew,String companyId, InsPlyIncome insPlyIncome) {
  322. PtlAgreement ptlAgreementQueryVo = this.ptlAgreementService.getByAgreementIdNew(insFeeOrderNew.getAgreementId());
  323. if(ObjectUtils.isNotEmpty(ptlAgreementQueryVo)){
  324. if(StringUtils.isNotEmpty(ptlAgreementQueryVo.getPartnerCompaniesId())){
  325. // 合作公司id
  326. String partnerCompaniesId = ptlAgreementQueryVo.getPartnerCompaniesId();
  327. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  328. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  329. String name = esmInsCompany.getName(); //合作名称
  330. insPlyIncome.setPartnerCompaniesName(name);
  331. insPlyIncome.setPartnerCompaniesId(ptlAgreementQueryVo.getPartnerCompaniesId());
  332. }
  333. if(StringUtils.isNotEmpty(ptlAgreementQueryVo.getInsuranceCompanyId())){
  334. String insuranceCompanyId = ptlAgreementQueryVo.getInsuranceCompanyId();
  335. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(insuranceCompanyId);
  336. String name = esmInsCompany.getName(); //保险公司名称
  337. insPlyIncome.setCompanyName(name);
  338. }
  339. }
  340. }
  341. private BigDecimal calculateTotal(BigDecimal value1, BigDecimal value2, BigDecimal value3) {
  342. BigDecimal total = BigDecimal.ZERO;
  343. if (value1 != null) {
  344. total = total.add(value1);
  345. }
  346. if (value2 != null) {
  347. total = total.add(value2);
  348. }
  349. if (value3 != null) {
  350. total = total.add(value3);
  351. }
  352. return total;
  353. }
  354. private String judgeAgreeType(Long agreementId) {
  355. if (agreementId == null) {
  356. return null;
  357. }
  358. HttpResult<PtlAgreementQueryVo> byAgreementId = ptlAgreementService.getByAgreementId(agreementId.toString());
  359. if (byAgreementId != null && ObjectUtils.isNotEmpty(byAgreementId.getData())) {
  360. PtlAgreement agreement = byAgreementId.getData().getAgreement();
  361. String agreementType = agreement.getAgreementType();
  362. if (StringUtils.isNotEmpty(agreementType)) {
  363. return agreementType;
  364. }
  365. }
  366. return null;
  367. }
  368. public HttpResult<BasePageResult<InsPlyIncome>> queryNew(InsPlyIncomeVo insPlyIncomeVo){
  369. try{
  370. HashMap<String, Object> params = new HashMap<>();
  371. PageInfo<List<InsPlyIncome>> pageHelper = null;
  372. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  373. params.put("pageNum",insPlyIncomeVo.getPageNum());
  374. params.put("pageSize",insPlyIncomeVo.getPageSize());
  375. params =this.saveParams(insPlyIncomeVo,params);
  376. List<InsPlyIncome> list= this.baseMapper.queryNew(params);
  377. pageHelper=new PageInfo(list);
  378. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  379. return HttpResult.ok(pageResult);
  380. }catch (Exception e){
  381. e.printStackTrace();
  382. return HttpResult.error("查询异常");
  383. }
  384. }
  385. @Override
  386. public HashMap<String,Object> totalAmount(List<String> selectIds) {
  387. HashMap<String, Object> params = new HashMap<>();
  388. params.put("selectIds",selectIds);
  389. HashMap<String,Object> resultMap =baseMapper.totalAmount(params);
  390. return resultMap;
  391. }
  392. @Override
  393. @Transactional
  394. public HttpResult<Object> batchPinBalance(InsPlyIncomeVo insPlyIncomeVo) {
  395. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())){
  396. List<String> selectIds = insPlyIncomeVo.getSelectIds();
  397. for(String id: selectIds){
  398. InsPlyIncome insPlyIncome = new InsPlyIncome();
  399. insPlyIncome.setHandlingFeesStatus("1");
  400. insPlyIncome.setSettlementTime(LocalDate.now());
  401. insPlyIncome.setId(id);
  402. baseMapper.updateById(insPlyIncome);
  403. }
  404. }
  405. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  406. settlementDocumentaryLogEntity.setIds(insPlyIncomeVo.getIds());
  407. // settlementDocumentaryLogEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  408. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); //跟单费金额
  409. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); //手续费金额
  410. settlementDocumentaryLogEntity.setCreateTime(new Date());
  411. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  412. return HttpResult.ok();
  413. }
  414. @Override
  415. public List<InsPlyIncome> totalPinAmount(InsPlyIncomeVo insPlyIncomeVo) {
  416. HashMap<String, Object> params = new HashMap<>();
  417. params = this.saveParams(insPlyIncomeVo,params);
  418. List<InsPlyIncome> result=baseMapper.totalPinAmount(params);
  419. return result;
  420. }
  421. private HashMap<String, Object> saveParams(InsPlyIncomeVo insPlyIncomeVo, HashMap<String, Object> params) {
  422. if(ObjectUtils.isNotEmpty(insPlyIncomeVo.getStartDate())){
  423. params.put("startDate",insPlyIncomeVo.getStartDate().toString());
  424. }
  425. if(ObjectUtils.isNotEmpty(insPlyIncomeVo.getEndDate())){
  426. params.put("endDate",insPlyIncomeVo.getEndDate().toString());
  427. }
  428. if(StringUtils.isNotEmpty(insPlyIncomeVo.getOrderno())){
  429. params.put("orderno",insPlyIncomeVo.getOrderno());
  430. }
  431. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  432. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  433. }
  434. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  435. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  436. }
  437. if(StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType())){
  438. params.put("agreementType",insPlyIncomeVo.getAgreementType());
  439. }
  440. if(StringUtils.isNotEmpty(insPlyIncomeVo.getLicenseno())){
  441. params.put("licenseno", insPlyIncomeVo.getLicenseno());
  442. }
  443. if(StringUtils.isNotEmpty(insPlyIncomeVo.getUserId())){
  444. params.put("userId",insPlyIncomeVo.getUserId());
  445. }
  446. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  447. params.put("companyId",insPlyIncomeVo.getCompanyId());
  448. }
  449. if(StringUtils.isNotEmpty(insPlyIncomeVo.getRiskcode())){
  450. params.put("riskcode",insPlyIncomeVo.getRiskcode());
  451. }
  452. if(StringUtils.isNotEmpty(insPlyIncomeVo.getPolicyno())){
  453. params.put("policyno",insPlyIncomeVo.getPolicyno().split(","));
  454. }
  455. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSyPolicyno())){
  456. params.put("syPolicyno",insPlyIncomeVo.getSyPolicyno().split(","));
  457. }
  458. if(StringUtils.isNotEmpty(insPlyIncomeVo.getNoPolicyno())){
  459. params.put("noPolicyno",insPlyIncomeVo.getNoPolicyno().split(","));
  460. }
  461. if(insPlyIncomeVo.getCreateTime()!=null){
  462. params.put("createTime",insPlyIncomeVo.getCreateTime());
  463. }
  464. if(insPlyIncomeVo.getSettlementTime()!=null){
  465. params.put("settlementTime",insPlyIncomeVo.getSettlementTime());
  466. }
  467. if(StringUtils.isNotEmpty(insPlyIncomeVo.getHandlingFeesStatus())){
  468. params.put("handlingFeesStatus",insPlyIncomeVo.getHandlingFeesStatus());
  469. }
  470. if(StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesId())){
  471. params.put("partnerCompaniesId",insPlyIncomeVo.getPartnerCompaniesId());
  472. }
  473. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  474. params.put("year",insPlyIncomeVo.getYear());
  475. }
  476. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  477. params.put("month",insPlyIncomeVo.getMonth());
  478. }
  479. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDay())){
  480. params.put("day",insPlyIncomeVo.getDay());
  481. }
  482. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateEnd())){
  483. params.put("signDateEnd",insPlyIncomeVo.getSignDateEnd());
  484. }
  485. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateStart())){
  486. params.put("signDateStart",insPlyIncomeVo.getSignDateStart());
  487. }
  488. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyName())){
  489. params.put("companyName",insPlyIncomeVo.getCompanyName());
  490. }
  491. if(StringUtils.isNotEmpty(insPlyIncomeVo.getInsuredName())){
  492. params.put("insuredName",insPlyIncomeVo.getInsuredName());
  493. }
  494. return params;
  495. }
  496. @Override
  497. public HttpResult<BasePageResult<InsPlyIncome>> nonSettlementQuery(InsPlyIncomeVo insPlyIncomeVo) {
  498. try{
  499. HashMap<String, Object> params = new HashMap<>();
  500. PageInfo<List<InsPlyIncome>> pageHelper = null;
  501. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  502. params.put("pageNum",insPlyIncomeVo.getPageNum());
  503. params.put("pageSize",insPlyIncomeVo.getPageSize());
  504. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  505. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  506. }
  507. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  508. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  509. }
  510. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  511. params.put("year",insPlyIncomeVo.getYear());
  512. }
  513. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  514. params.put("month",insPlyIncomeVo.getMonth());
  515. }
  516. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())){
  517. params.put("documentaryFeesStatus",insPlyIncomeVo.getDocumentaryFeesStatus());
  518. }
  519. List<InsPlyIncome> list= this.baseMapper.NonSettlementQuery(params);
  520. pageHelper=new PageInfo(list);
  521. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  522. return HttpResult.ok(pageResult);
  523. }catch (Exception e){
  524. e.printStackTrace();
  525. return HttpResult.error("查询异常");
  526. }
  527. }
  528. @Override
  529. public HttpResult<List<InsPlyIncome>> nonSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  530. try {
  531. String ids = insPlyIncomeVo.getIds();
  532. ArrayList<InsPlyIncome> resultList = new ArrayList<>();
  533. if (ObjectUtils.isNotEmpty(ids)) {
  534. String[] split = ids.split(",");
  535. for (int i =0; i <split.length ; i++) {
  536. String id = split[i];
  537. resultList.add(this.baseMapper.getById(id));
  538. }
  539. }
  540. return HttpResult.ok(resultList);
  541. } catch (Exception e) {
  542. e.printStackTrace();
  543. return HttpResult.error("查询异常");
  544. }
  545. }
  546. @Override
  547. public void importData(MultipartFile multipartFile) {
  548. List<InsPlyIncome> list = null;
  549. HashMap<String, Object> params = new HashMap<>();
  550. try {
  551. List<InsPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsPlyIncomeExcelDto.class, 0, 1, 1);
  552. for (InsPlyIncomeExcelDto excelItem : dtoList) {
  553. params.clear();
  554. String licenseno = excelItem.getLicenseno();//车牌号
  555. params.put("licenseno",licenseno);
  556. String policyno = excelItem.getPolicyno(); //交强保单号
  557. params.put("policyno",policyno);
  558. String syPolicyno = excelItem.getSyPolicyno(); //商业保单号
  559. params.put("syPolicyno",syPolicyno);
  560. String noPolicyno = excelItem.getNoPolicyno(); //非车保单号
  561. params.put("noPolicyno",noPolicyno);
  562. if(ObjectUtils.isNotEmpty(licenseno)){
  563. List<InsPlyIncome> insPlyIncome=baseMapper.findByLicenseno(params);
  564. for (InsPlyIncome item : insPlyIncome) {
  565. if(ObjectUtils.isNotEmpty(item)){
  566. item.setHandlingFeesStatus("1"); //已结算
  567. baseMapper.updateById(item);
  568. }
  569. }
  570. }
  571. }
  572. } catch (IOException e) {
  573. throw new SystemException("导入失败!");
  574. }
  575. }
  576. /**
  577. *
  578. * @param multipartFile
  579. * @return resultList 包含总金额 还有 未匹配表中的数据
  580. */
  581. @Override
  582. public HashMap<String, Object> bxImportData(MultipartFile multipartFile,String isNotCar) {
  583. BigDecimal totalAmount=BigDecimal.ZERO;
  584. HashMap<String, Object> params = new HashMap<>();
  585. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  586. HashMap<String, Object> resultMap = new HashMap<>();
  587. StringBuffer strBuilder = new StringBuffer();
  588. String ids="";
  589. try {
  590. List<InsBxPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxPlyIncomeExcelDto.class, 0, 1, 1);
  591. if(!CollectionUtils.isEmpty(dtoList)){
  592. for (InsBxPlyIncomeExcelDto excelItem : dtoList) {
  593. params.clear();
  594. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  595. String licenseno = excelItem.getLicenseno();//车牌号
  596. params.put("licenseno",licenseno);
  597. }
  598. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  599. String policyno = excelItem.getPolicyno(); //交强保单号
  600. params.put("policyno",policyno);
  601. }
  602. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  603. String syPolicyno = excelItem.getSyPolicyno(); //商业保单号
  604. params.put("syPolicyno",syPolicyno);
  605. }
  606. // 只查手续费
  607. params.put("isOther","0");
  608. params.put("isNotCar",isNotCar);
  609. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  610. if(ObjectUtils.isNotEmpty(insPlyIncome)){ // 比配上汇总金额 未匹配则返回到数据当中
  611. strBuilder.append(insPlyIncome.getId()).append(",");
  612. if( insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  613. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  614. }
  615. }else {
  616. HashMap<String, Object> noMatching = new HashMap<>();
  617. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  618. noMatching.put("licenseno",excelItem.getLicenseno());
  619. }
  620. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  621. noMatching.put("policyno",excelItem.getPolicyno());
  622. }
  623. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  624. noMatching.put("syPolicyno",excelItem.getSyPolicyno());
  625. }
  626. resultList.add(noMatching);
  627. }
  628. }
  629. }
  630. if(strBuilder.length() >0){
  631. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  632. }
  633. resultMap.put("ids",ids);
  634. resultMap.put("totalAmount",totalAmount);
  635. resultMap.put("resultList",resultList);
  636. return resultMap;
  637. } catch (IOException e) {
  638. throw new SystemException("导入失败!");
  639. }
  640. }
  641. @Override
  642. public HashMap<String, Object> bxImportNoData(MultipartFile multipartFile,String isNotCar) {
  643. BigDecimal totalAmount=BigDecimal.ZERO;
  644. HashMap<String, Object> params = new HashMap<>();
  645. HashMap<String, Object> resultMap = new HashMap<>();
  646. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  647. StringBuffer strBuilder = new StringBuffer();
  648. String ids="";
  649. try {
  650. List<InsBxNoPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxNoPlyIncomeExcelDto.class, 0, 1, 1);
  651. if(!CollectionUtils.isEmpty(dtoList)){
  652. for (InsBxNoPlyIncomeExcelDto excelItem : dtoList) {
  653. params.clear();
  654. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  655. String licenseno = excelItem.getLicenseno();//车牌号
  656. params.put("licenseno",licenseno);
  657. }
  658. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  659. String policyno = excelItem.getNoPolicyno(); //非车保单号
  660. params.put("NoPolicyno",policyno);
  661. }
  662. // 只查手续费
  663. params.put("isOther","0");
  664. params.put("isNotCar",isNotCar);
  665. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  666. if(ObjectUtils.isNotEmpty(insPlyIncome)){ // 比配上汇总金额 未匹配则返回到数据当中
  667. strBuilder.append(insPlyIncome.getId()).append(",");
  668. if( insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  669. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  670. }
  671. }else {
  672. HashMap<String, Object> noMatching = new HashMap<>();
  673. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  674. noMatching.put("licenseno",excelItem.getLicenseno());
  675. }
  676. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  677. noMatching.put("NoPolicyno",excelItem.getNoPolicyno());
  678. }
  679. resultList.add(noMatching);
  680. }
  681. }
  682. if(strBuilder.length() >0){
  683. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  684. }
  685. resultMap.put("ids",ids);
  686. resultMap.put("totalAmount",totalAmount);
  687. resultMap.put("resultList",resultList);
  688. }
  689. return resultMap;
  690. } catch (IOException e) {
  691. throw new SystemException("导入失败!");
  692. }
  693. }
  694. @Override
  695. public HttpResult bxOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  696. HashMap<String, Object> params = new HashMap<>();
  697. params =this.saveParams(insPlyIncomeVo,params);
  698. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  699. ExportParams exportParams = new ExportParams("保险跟单明细导出", null, ExcelType.HSSF);
  700. exportParams.setStyle(ExcelStyleUtil.class);
  701. List<BxOtherDetailsExcel> resultList = new ArrayList<>();
  702. for (InsPlyIncome item :insPlyIncomes){
  703. BxOtherDetailsExcel bxOtherDetailsExcel = new BxOtherDetailsExcel();
  704. BeanUtils.copyProperties(item, bxOtherDetailsExcel);
  705. resultList.add(bxOtherDetailsExcel);
  706. }
  707. String uploadPath = this.uploadPath + "/excel/";
  708. Path path = Paths.get(uploadPath);
  709. if (!Files.exists(path)) {
  710. try {
  711. Files.createDirectories(path);
  712. } catch (IOException e) {
  713. e.printStackTrace();
  714. }
  715. }
  716. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险跟单明细导出", BxOtherDetailsExcel.class, resultList);
  717. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  718. }
  719. /**
  720. *
  721. * @param insPlyIncomeVo 传参字段
  722. * ids 通过ids中的id进行开票分组
  723. *
  724. * @return
  725. */
  726. @Override
  727. public HttpResult<List<HashMap<String,Object>>> invicdetail(InsPlyIncomeVo insPlyIncomeVo) {
  728. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){
  729. String ids = insPlyIncomeVo.getIds();
  730. String[] idArr = ids.split(",");
  731. List<HashMap<String,Object>> result= this.baseMapper.groupByInvoic(idArr);
  732. return HttpResult.ok(result);
  733. }
  734. return HttpResult.ok();
  735. }
  736. /***
  737. *
  738. * @param insPlyIncomeVo
  739. * @param request
  740. * @param response
  741. * @return 保险非车跟单明细导出
  742. */
  743. @Override
  744. public HttpResult bxNoOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  745. HashMap<String, Object> params = new HashMap<>();
  746. params =this.saveParams(insPlyIncomeVo,params);
  747. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  748. ExportParams exportParams = new ExportParams("保险非车跟单明细导出", null, ExcelType.HSSF);
  749. exportParams.setStyle(ExcelStyleUtil.class);
  750. List<BxNoOtherDetailsExcel> resultList = new ArrayList<>();
  751. for (InsPlyIncome item :insPlyIncomes){
  752. BxNoOtherDetailsExcel bxNoOtherDetailsExcel = new BxNoOtherDetailsExcel();
  753. BeanUtils.copyProperties(item, bxNoOtherDetailsExcel);
  754. resultList.add(bxNoOtherDetailsExcel);
  755. }
  756. String uploadPath = this.uploadPath + "/excel/";
  757. Path path = Paths.get(uploadPath);
  758. if (!Files.exists(path)) {
  759. try {
  760. Files.createDirectories(path);
  761. } catch (IOException e) {
  762. e.printStackTrace();
  763. }
  764. }
  765. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险非车跟单明细导出", BxNoOtherDetailsExcel.class, resultList);
  766. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  767. }
  768. /**
  769. *
  770. * @param insPlyIncomeVo 开票ids
  771. * @return 返回开票号 开票金额 开票时间
  772. */
  773. @Override
  774. public HttpResult<List<HashMap<String, Object>>> otherSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  775. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIncomeIds())) {
  776. String incomeIds = insPlyIncomeVo.getIncomeIds();
  777. List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(incomeIds);
  778. if (resultList.size() > 0) {
  779. return HttpResult.ok(resultList);
  780. }
  781. }
  782. return HttpResult.ok();
  783. }
  784. @Override
  785. @Transactional
  786. public void updateByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  787. // 根据协议 如果是含增值税结算 用保费 * 如果是 不含税保费
  788. InsPlyIncome insPlyIncome = new InsPlyIncome();
  789. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  790. this.amountCalculate(insPlyIncomeVo,insPlyIncome);
  791. baseMapper.updateById(insPlyIncome);
  792. insPlyIncomeVo.setCrudStatus("2");
  793. this.saveLog(insPlyIncomeVo);
  794. }
  795. /**
  796. *
  797. * @param insPlyIncomeVo
  798. * @param insPlyIncome
  799. *
  800. * 重新计算金额 通过比例
  801. * 计算逻辑 交强不含税保费* 交强跟单比例 = 交强跟单金额
  802. */
  803. private void amountCalculate(InsPlyIncomeVo insPlyIncomeVo,InsPlyIncome insPlyIncome) {
  804. BigDecimal jqNoTaxPremium = insPlyIncomeVo.getJqNoTaxPremium();// 交强手续费 按照思路 交强不含税保费* 交强手续费比例 =交强手续费
  805. BigDecimal syNoTaxPremium = insPlyIncomeVo.getSyNoTaxPremium();// 商业手续费 按照思路 商业不含税保费* 商业手续费比例 =商业手续费
  806. BigDecimal noNoTaxPremium = insPlyIncomeVo.getNoNoTaxPremium();// 非车手续费 按照思路 非车不含税保费* 非车手续费比例 =非车手续费
  807. if(insPlyIncomeVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  808. BigDecimal jqhandingFee = jqNoTaxPremium.multiply(insPlyIncomeVo.getJqSuperviseCostsProportion().divide(new BigDecimal(100)));
  809. insPlyIncome.setJqSuperviseCostsPremiums(jqhandingFee);
  810. }
  811. if(insPlyIncomeVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  812. BigDecimal syhandingFee = syNoTaxPremium.multiply(insPlyIncomeVo.getSySuperviseCostsProportion().divide(new BigDecimal(100)));
  813. insPlyIncome.setSySuperviseCostsPremiums(syhandingFee);
  814. }
  815. if(insPlyIncomeVo.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  816. BigDecimal nohandingFee = noNoTaxPremium.multiply(insPlyIncomeVo.getSySuperviseCostsProportion().divide(new BigDecimal(100)));
  817. insPlyIncome.setNoSuperviseCostsPremiums(nohandingFee);
  818. }
  819. if(insPlyIncomeVo.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  820. BigDecimal jqother = jqNoTaxPremium.multiply(insPlyIncomeVo.getJqOtherCostsProportion().divide(new BigDecimal(100)));//交强跟单费 按照思路 交强不含税保费* 交强跟单比例 = 交强跟单金额
  821. insPlyIncome.setJqOtherCostsPremium(jqother);
  822. }
  823. if(insPlyIncomeVo.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  824. BigDecimal syother = syNoTaxPremium.multiply(insPlyIncomeVo.getSyOtherCostsProportion().divide(new BigDecimal(100)));//交强跟单费 按照思路 交强不含税保费* 交强跟单比例 = 交强跟单金额
  825. insPlyIncome.setJqOtherCostsPremium(syother);
  826. }
  827. if(insPlyIncomeVo.getNoOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  828. BigDecimal syother = syNoTaxPremium.multiply(insPlyIncomeVo.getNoOtherCostsProportion().divide(new BigDecimal(100)));//非车跟单费 按照思路 非车不含税保费* 非车跟单比例 = 非车跟单金额
  829. insPlyIncome.setNoOtherCostsPremium(syother);
  830. }
  831. /**
  832. 判断是否是平台 如果是平台则 手续费= 交强手续费+ 商业手续费+非车手续费 费单非= 交强跟单费+ 商业跟单费 +非车跟单费费
  833. * 如果是保险 保险手续费= 交强手续费+商业跟单费 跟单费为null
  834. * 保险跟单 手续费为null 跟单费= 交强跟单费+商业跟单费
  835. * 非车手续费 =非车手续费
  836. * 非车跟单 = 非车跟单费
  837. */
  838. if("1".equals(insPlyIncomeVo.getAgreementType())){//保险手续费
  839. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(),insPlyIncome.getSySuperviseCostsProportion(),insPlyIncome.getNoSuperviseCostsProportion())); //手续费比例
  840. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),insPlyIncome.getNoSuperviseCostsPremiums())); //手续费金额
  841. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getJqOtherCostsProportion(),insPlyIncome.getSyOtherCostsProportion(),insPlyIncome.getNoOtherCostsProportion())); //跟单比例
  842. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),insPlyIncome.getNoOtherCostsPremium()));//跟单费金额
  843. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),insPlyIncome.getOtherFeevalue(),null)); // 总费用 = 手续费+跟单费
  844. }else {
  845. if("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())){ //保险手续费
  846. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),null)); // 手续费
  847. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(),insPlyIncome.getSySuperviseCostsProportion(),null));//手续费比例
  848. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),null,null));//总金额
  849. }else { //保险跟单费 交强跟单+商业跟单
  850. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),null));
  851. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getJqOtherCostsProportion(),insPlyIncome.getSyOtherCostsProportion(),null));
  852. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(),null,null));//总金额
  853. }
  854. if("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())){// 非车
  855. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getNoSuperviseCostsPremiums(),null,null)); // 非车手续费
  856. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getNoSuperviseCostsProportion(),null,null)); //非车比例
  857. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),null,null));//总金额
  858. }else { //非车跟单
  859. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getNoOtherCostsPremium(),null,null)); //非车跟单金额
  860. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getNoOtherCostsProportion(),null,null)); // 非车跟单比例
  861. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(),null,null));//总金额
  862. }
  863. }
  864. }
  865. private void saveLog(InsPlyIncomeVo insPlyIncomeVo) {
  866. // 添加记录
  867. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  868. settlementDocumentaryLogEntity.setCrudStatus(insPlyIncomeVo.getCrudStatus());
  869. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue());
  870. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId());
  871. settlementDocumentaryLogEntity.setAmountType("2");
  872. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  873. }
  874. @Override
  875. @Transactional
  876. public HttpResult<InsPlyIncome> insertByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  877. Long id = new SnowFlakeUtil().nextId();
  878. InsPlyIncome insPlyIncome = new InsPlyIncome();
  879. insPlyIncomeVo.setOrderno(id.toString());
  880. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  881. insPlyIncome.setDocumentaryFeesStatus("0");
  882. insPlyIncome.setHandlingFeesStatus("0");
  883. insPlyIncome.setIsNotCar("0");
  884. insPlyIncome.setIsNotDocumentary("1");
  885. baseMapper.insert(insPlyIncome);
  886. insPlyIncomeVo.setId(insPlyIncome.getId());
  887. insPlyIncomeVo.setCrudStatus("1");
  888. this.saveLog(insPlyIncomeVo); //添加日志
  889. HashMap<String, Object> params = new HashMap<>();
  890. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  891. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  892. }
  893. params.put("isOther","1");
  894. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  895. params.put("year",insPlyIncomeVo.getYear());
  896. }
  897. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  898. params.put("companyId",insPlyIncomeVo.getCompanyId());
  899. }
  900. List<InsPlyIncome> list= this.baseMapper.NonSettlementQuery(params);
  901. if(!CollectionUtils.isEmpty(list)){
  902. for (InsPlyIncome item :list){
  903. return HttpResult.ok(item.getIds());
  904. }
  905. }
  906. return null;
  907. }
  908. @Override
  909. @Transactional
  910. public HttpResult<InsPlyIncome> deleteById(InsPlyIncomeVo insPlyIncomeVo) {
  911. HashMap<String, Object> params = new HashMap<>();
  912. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  913. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  914. }
  915. params.put("isOther","1");
  916. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  917. params.put("year",insPlyIncomeVo.getYear());
  918. }
  919. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  920. params.put("companyId",insPlyIncomeVo.getCompanyId());
  921. }
  922. baseMapper.deleteById(insPlyIncomeVo.getId());
  923. insPlyIncomeVo.setCrudStatus("3");
  924. this.saveLog(insPlyIncomeVo);
  925. List<InsPlyIncome> list = this.baseMapper.NonSettlementQuery(params);
  926. if (!CollectionUtils.isEmpty(list)) {
  927. for (InsPlyIncome item : list) {
  928. return HttpResult.ok(item.getIds());
  929. }
  930. } else {
  931. return HttpResult.ok(null);
  932. }
  933. return HttpResult.ok("删除成功");
  934. }
  935. @Override
  936. @Transactional
  937. public void uodateBalance(InsPlyIncomeVo insPlyIncomeVo) {
  938. InsPlyIncome insPlyIncome = new InsPlyIncome();
  939. insPlyIncomeVo.setHandlingFeesStatus("1");
  940. insPlyIncomeVo.setSettlementTime(LocalDate.now());
  941. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  942. baseMapper.updateById(insPlyIncome);
  943. // 生成记录
  944. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  945. if(StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType()) && "1".equals(insPlyIncomeVo.getAgreementType())){
  946. // 只有平台协议 才会跟单费一笔结算
  947. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); // 跟单费金额
  948. }
  949. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); // 手续费金额
  950. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId()); // 关联id
  951. settlementDocumentaryLogEntity.setAmountType("1"); //手续费结算
  952. settlementDocumentaryLogEntity.setCreateTime(new Date());
  953. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  954. }
  955. @Override
  956. @Transactional
  957. public HttpResult<BasePageResult<InsPlyIncome>> totalQuery(InsPlyIncomeVo insPlyIncomeVo) {
  958. HashMap<String, Object> params = new HashMap<>();
  959. PageInfo<List<InsPlyIncome>> pageHelper = null;
  960. if(insPlyIncomeVo.getStartDate()!=null){
  961. params.put("startDate",insPlyIncomeVo.getStartDate().toString());
  962. }
  963. if(insPlyIncomeVo.getEndDate()!=null){
  964. params.put("endDate",insPlyIncomeVo.getEndDate().toString());
  965. }
  966. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  967. params.put("year",insPlyIncomeVo.getYear());
  968. }
  969. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  970. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  971. }
  972. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  973. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  974. }
  975. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())){
  976. params.put("documentaryFeesStatus",insPlyIncomeVo.getDocumentaryFeesStatus());
  977. }
  978. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  979. params.put("companyId",insPlyIncomeVo.getCompanyId());
  980. }
  981. params.put("pageNum",insPlyIncomeVo.getPageNum());
  982. params.put("pageSize",insPlyIncomeVo.getPageSize());
  983. List<InsPlyIncome> list= this.baseMapper.totalQuery(params);
  984. pageHelper=new PageInfo(list);
  985. return HttpResult.ok(new BasePageResult<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list));
  986. }
  987. @Override
  988. @Transactional
  989. public HttpResult batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
  990. // 通过ids 查出跟单非结算单
  991. String ids = insPlyIncomeVo.getIds();
  992. if(StringUtils.isNotEmpty(ids)){
  993. String[] split = ids.split(",");
  994. for (int i =0; i <split.length ; i++) {
  995. String id = split[i];
  996. InsPlyIncome insPlyIncome = baseMapper.selectById(id);
  997. insPlyIncome.setDocumentaryFeesStatus("1"); //1 为跟单费已经结算
  998. insPlyIncome.setSettlementTime(LocalDate.now());
  999. baseMapper.updateById(insPlyIncome);
  1000. }
  1001. }
  1002. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  1003. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1004. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  1005. }
  1006. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  1007. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  1008. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getOtherFeevalue().subtract(insPlyIncomeVo.getInvoicCommissionFeevalue())); //未开票金额
  1009. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());//已开票金额
  1010. settlementDocumentaryFeesVo.setSettlementStatus("2");
  1011. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1012. settlementDocumentaryFeesVo.setCreateTime(LocalDate.now());
  1013. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIncomeIds());
  1014. return settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1015. }
  1016. @Override
  1017. public List<InsPlyIncome> totalBxAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1018. HashMap<String, Object> params = new HashMap<>();
  1019. params=this.saveParams(insPlyIncomeVo,params);
  1020. params.remove("handlingFeesStatus");
  1021. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  1022. return resultList;
  1023. }
  1024. @Override
  1025. @Transactional
  1026. public HttpResult<Object> batchInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1027. // 开票时生成 记录 用来合计已经开票数据
  1028. String ids = insPlyIncomeVo.getIds();
  1029. if(StringUtils.isNotEmpty(ids)){
  1030. String[] split = ids.split(",");
  1031. for (String id : split){
  1032. InsPlyIncome insPlyIncome = baseMapper.selectById(id);
  1033. insPlyIncome.setInvoicTime(LocalDate.now()); //开票时间
  1034. insPlyIncome.setInvoicId(insPlyIncomeVo.getInvoicId()); //开票号
  1035. insPlyIncome.setHandlingFeesStatus("2"); //2为开票
  1036. baseMapper.updateById(insPlyIncome);
  1037. }
  1038. }
  1039. return HttpResult.ok();
  1040. }
  1041. @Override
  1042. public HttpResult<InsPlyIncome> queryInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1043. HashMap<String, Object> params = new HashMap<>();
  1044. params = this.saveParams(insPlyIncomeVo, params);
  1045. InsPlyIncome result= baseMapper.queryInvoicing(params); //总金额
  1046. params.put("handlingFeesStatus","0");
  1047. InsPlyIncome noResult= baseMapper.queryInvoicing(params); //未结算金额
  1048. result.setReadyCommissionFeevalue(noResult.getCommissionFeevalue());
  1049. return HttpResult.ok(result);
  1050. }
  1051. @Override
  1052. public HttpResult<Object> batchBxBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1053. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1054. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){
  1055. String[] split = insPlyIncomeVo.getIds().split(",");
  1056. for(String id : split){
  1057. insPlyIncome.setId(id);
  1058. insPlyIncome.setHandlingFeesStatus("1");
  1059. insPlyIncome.setSettlementTime(LocalDate.now());
  1060. baseMapper.updateById(insPlyIncome);
  1061. }
  1062. }
  1063. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1064. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getReadyCommissionFeevalue());
  1065. settlementDocumentaryLogEntity.setIds(insPlyIncomeVo.getIds());
  1066. settlementDocumentaryLogEntity.setCreateTime(new Date());
  1067. settlementDocumentaryLogEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  1068. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1069. return HttpResult.ok();
  1070. }
  1071. @Override
  1072. public HttpResult<InsPlyIncome> querySettInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1073. HashMap<String, Object> params = new HashMap<>();
  1074. params = this.saveParams(insPlyIncomeVo, params);
  1075. InsPlyIncome insPlyIncome = baseMapper.queryInvoicing(params); //已经开票
  1076. return HttpResult.ok(insPlyIncome);
  1077. }
  1078. @Override
  1079. public HttpResult<List<InsPlyIncome>> allOtherAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1080. HashMap<String, Object> params = new HashMap<>();
  1081. params=this.saveParams(insPlyIncomeVo,params);
  1082. List<InsPlyIncome> result= baseMapper.allOtherAmount(params);
  1083. return HttpResult.ok(result);
  1084. }
  1085. @Override
  1086. @Transactional
  1087. public HttpResult<Object> batchInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  1088. // 通过ids 查出跟单非结算单
  1089. String ids = insPlyIncomeVo.getIds();
  1090. if(StringUtils.isNotEmpty(ids)){
  1091. String[] split = ids.split(",");
  1092. for (int i =0; i <split.length ; i++) {
  1093. String id = split[i];
  1094. InsPlyIncome insPlyIncome = baseMapper.selectById(id);
  1095. insPlyIncome.setInvoicId(insPlyIncomeVo.getContractId()); // 开票号
  1096. insPlyIncome.setContractFileId(insPlyIncomeVo.getContractFileId());
  1097. insPlyIncome.setVoucherNumber(insPlyIncomeVo.getVoucherNumber());
  1098. insPlyIncome.setSettlementTime(LocalDate.now());
  1099. baseMapper.updateById(insPlyIncome);
  1100. }
  1101. }
  1102. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  1103. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1104. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  1105. }
  1106. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1107. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  1108. }
  1109. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  1110. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  1111. }
  1112. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDay())){
  1113. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  1114. }
  1115. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  1116. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  1117. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  1118. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  1119. settlementDocumentaryFeesVo.setCreateTime(LocalDate.now());
  1120. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIncomeIds());
  1121. settlementDocumentaryFeesVo.setSettlementStatus("1");
  1122. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1123. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId());
  1124. return settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1125. }
  1126. @Override
  1127. public HttpResult pinHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1128. HashMap<String, Object> params = new HashMap<>();
  1129. params =this.saveParams(insPlyIncomeVo,params);
  1130. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1131. ExportParams exportParams = new ExportParams("平台手续费", null, ExcelType.HSSF);
  1132. exportParams.setStyle(ExcelStyleUtil.class);
  1133. List<SettlementFeesExcel> resultList = new ArrayList<>();
  1134. for (InsPlyIncome item :insPlyIncomes){
  1135. SettlementFeesExcel bxSettlementFeesExcel = new SettlementFeesExcel();
  1136. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1137. resultList.add(bxSettlementFeesExcel);
  1138. }
  1139. String uploadPath = this.uploadPath + "/excel/";
  1140. Path path = Paths.get(uploadPath);
  1141. if (!Files.exists(path)) {
  1142. try {
  1143. Files.createDirectories(path);
  1144. } catch (IOException e) {
  1145. e.printStackTrace();
  1146. }
  1147. }
  1148. String fileName = EasyExcelUtils.downExcel(uploadPath, "平台手续费导出", SettlementFeesExcel.class, resultList);
  1149. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1150. }
  1151. @Override
  1152. public HttpResult bxHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1153. HashMap<String, Object> params = new HashMap<>();
  1154. params =this.saveParams(insPlyIncomeVo,params);
  1155. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1156. ExportParams exportParams = new ExportParams("保险手续费", null, ExcelType.HSSF);
  1157. exportParams.setStyle(ExcelStyleUtil.class);
  1158. List<BxSettlementFeesExcel> resultList = new ArrayList<>();
  1159. for (InsPlyIncome item :insPlyIncomes){
  1160. BxSettlementFeesExcel bxSettlementFeesExcel = new BxSettlementFeesExcel();
  1161. LocalDateTime signDate = item.getSignDate();
  1162. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1163. resultList.add(bxSettlementFeesExcel);
  1164. }
  1165. String uploadPath = this.uploadPath + "/excel/";
  1166. Path path = Paths.get(uploadPath);
  1167. if (!Files.exists(path)) {
  1168. try {
  1169. Files.createDirectories(path);
  1170. } catch (IOException e) {
  1171. e.printStackTrace();
  1172. }
  1173. }
  1174. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险手续费导出", BxSettlementFeesExcel.class, resultList);
  1175. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1176. }
  1177. @Override
  1178. public HttpResult bxOtherExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1179. HashMap<String, Object> params = new HashMap<>();
  1180. params =this.saveParams(insPlyIncomeVo,params);
  1181. params.put("agreementType","2");
  1182. params.put("isOther","1");
  1183. params.put("isNotCar","0");
  1184. List<InsPlyIncome> insPlyIncomes = baseMapper.allOtherAmount(params);
  1185. ExportParams exportParams = new ExportParams("跟单费导出", null, ExcelType.HSSF);
  1186. exportParams.setStyle(ExcelStyleUtil.class);
  1187. List<BxOtherExcel> resultList = new ArrayList<>();
  1188. for (InsPlyIncome item :insPlyIncomes){
  1189. BxOtherExcel bxSettlementFeesExcel = new BxOtherExcel();
  1190. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1191. resultList.add(bxSettlementFeesExcel);
  1192. }
  1193. String uploadPath = this.uploadPath + "/excel/";
  1194. Path path = Paths.get(uploadPath);
  1195. if (!Files.exists(path)) {
  1196. try {
  1197. Files.createDirectories(path);
  1198. } catch (IOException e) {
  1199. e.printStackTrace();
  1200. }
  1201. }
  1202. String fileName = EasyExcelUtils.downExcel(uploadPath, "跟单费导出", BxOtherExcel.class, resultList);
  1203. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1204. }
  1205. @Override
  1206. public InsPlyIncome bxTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1207. HashMap<String, Object> params = new HashMap<>();
  1208. params = this.saveParams(insPlyIncomeVo, params);
  1209. InsPlyIncome totalledAmount =baseMapper.bxTotalAmount(params); //总金额
  1210. return totalledAmount;
  1211. }
  1212. }