InvInsExternalBillsDetailsServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. package com.ydtech.modules.inv.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.ydtech.exception.SystemException;
  6. import com.ydtech.modules.inv.dao.InvInsExternalBillsDetailsMapper;
  7. import com.ydtech.modules.inv.model.InvExternalBills;
  8. import com.ydtech.modules.inv.model.InvInsExternalBillsDetails;
  9. import com.ydtech.modules.inv.model.dto.InvInsChinaCoalExcelDto;
  10. import com.ydtech.modules.inv.model.dto.InvInsImportDto;
  11. import com.ydtech.modules.inv.model.dto.InvInsSimpleSysExcelDto;
  12. import com.ydtech.modules.inv.model.dto.InvInsStandardExcelDto;
  13. import com.ydtech.modules.inv.service.InvExternalBillsService;
  14. import com.ydtech.modules.inv.service.InvInsExternalBillsDetailsService;
  15. import com.ydtech.modules.protocol.entity.po.PtlAgreementProductCosts;
  16. import com.ydtech.modules.protocol.service.PtlAgreementProductCostsService;
  17. import com.ydtech.utils.BigDecimalUtils;
  18. import com.ydtech.utils.StringUtils;
  19. import com.ydtech.utils.excel.ExcelUtils2;
  20. import org.springframework.beans.BeanUtils;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.web.multipart.MultipartFile;
  24. import javax.annotation.Resource;
  25. import java.io.IOException;
  26. import java.math.BigDecimal;
  27. import java.util.ArrayList;
  28. import java.util.HashMap;
  29. import java.util.List;
  30. import java.util.Map;
  31. import java.util.function.Function;
  32. import java.util.stream.Collectors;
  33. /**
  34. * @author Administrator
  35. * @description 针对表【inv_ins_external_bills_details(财务 - 保险公司 - 外部票据 - 详情)】的数据库操作Service实现
  36. * @createDate 2023-06-06 11:08:53
  37. */
  38. @Service
  39. public class InvInsExternalBillsDetailsServiceImpl extends ServiceImpl<InvInsExternalBillsDetailsMapper, InvInsExternalBillsDetails>
  40. implements InvInsExternalBillsDetailsService {
  41. @Resource
  42. InvExternalBillsService invExternalBillsService;
  43. @Resource
  44. PtlAgreementProductCostsService ptlAgreementProductCostsService;
  45. @Override
  46. public boolean deleteByBatchNum(String batchNum) {
  47. LambdaQueryWrapper<InvInsExternalBillsDetails> lqw = new LambdaQueryWrapper();
  48. lqw.eq(InvInsExternalBillsDetails::getBatchNum, batchNum);
  49. return remove(lqw);
  50. }
  51. @Override
  52. public InvExternalBills importData(InvInsImportDto importDto, MultipartFile file, InvExternalBills iieb) throws Exception {
  53. List<InvInsExternalBillsDetails> list = buildImportExcel(importDto, file, iieb);
  54. iieb = InvExternalBills.buildImportInvExternalBills(iieb, list);
  55. boolean boo = saveBatch(list);
  56. if (!boo) {
  57. iieb.setImportStatus("0");
  58. iieb.setErrorMsg("保存数据出错");
  59. }
  60. return iieb;
  61. }
  62. /**
  63. * 构造导入excel数据
  64. *
  65. * @author: lig
  66. * @date: 2023年07月06日 0006
  67. */
  68. private List<InvInsExternalBillsDetails> buildImportExcel(InvInsImportDto importDto, MultipartFile file, InvExternalBills iieb) throws Exception {
  69. List<InvInsExternalBillsDetails> list;
  70. Map<String, InvInsExternalBillsDetails> m = new HashMap();
  71. List<InvInsStandardExcelDto> standardList = ExcelUtils2.importExcel(file, InvInsStandardExcelDto.class, 0, 1, 1);
  72. standardList.stream().forEach(a -> {
  73. List<String> filedList = new ArrayList<>();
  74. filedList.add(a.getInsuranceCompanyUser());
  75. //获取费用
  76. List<PtlAgreementProductCosts> costList = ptlAgreementProductCostsService.selectByCompanyId(iieb.getInsCompanyId(),filedList);
  77. Map<String,String> costMap = new HashMap();
  78. costList.stream().forEach(cost ->{
  79. costMap.put(cost.getProductName(),cost.getCostsProportion());
  80. });
  81. InvInsExternalBillsDetails iiebd = new InvInsExternalBillsDetails();
  82. if (m.containsKey(a.getPlateNum())) {
  83. iiebd = m.get(a.getPlateNum());
  84. } else {
  85. BeanUtil.copyProperties(a, iiebd);
  86. }
  87. //产品匹配 添加费用
  88. if(costMap.containsKey(a.getProductName())){
  89. if(a.getProductName().equals("单交")){
  90. iiebd.setMliftaCost(new BigDecimal(costMap.get(a.getProductName())));
  91. }
  92. }
  93. buildStandardDtoParam(a, iiebd);
  94. m.put(a.getPlateNum(), iiebd);
  95. });
  96. // //标准模板
  97. // if (importDto.isStandard()) {
  98. // List<InvInsStandardExcelDto> standardList = ExcelUtils2.importExcel(file, InvInsStandardExcelDto.class, 0, 1, 1);
  99. // standardList.stream().forEach(a -> {
  100. //
  101. //
  102. // List<String> filedList = new ArrayList<>();
  103. // filedList.add(a.getInsuranceCompanyUser());
  104. // //获取费用
  105. // List<PtlAgreementProductCosts> costList = ptlAgreementProductCostsService.selectByCompanyId(iieb.getInsCompanyId(),filedList);
  106. // Map<String,String> costMap = new HashMap();
  107. // costList.stream().forEach(cost ->{
  108. // costMap.put(cost.getProductName(),cost.getCostsProportion());
  109. // });
  110. //
  111. // InvInsExternalBillsDetails iiebd = new InvInsExternalBillsDetails();
  112. // if (m.containsKey(a.getPlateNum())) {
  113. // iiebd = m.get(a.getPlateNum());
  114. //
  115. // } else {
  116. // BeanUtil.copyProperties(a, iiebd);
  117. // }
  118. //
  119. //
  120. // //产品匹配 添加费用
  121. // if(costMap.containsKey(a.getProductName())){
  122. // if(a.getProductName().equals("单交")){
  123. // iiebd.setMliftaCost(new BigDecimal(costMap.get(a.getProductName())));
  124. // }
  125. //
  126. // }
  127. //
  128. // buildStandardDtoParam(a, iiebd);
  129. // m.put(a.getPlateNum(), iiebd);
  130. // });
  131. //
  132. // } else if (iieb.getInsCompanyId().equals("000019")) {
  133. // //中煤
  134. // List<InvInsChinaCoalExcelDto> zmlist = ExcelUtils2.importExcel(file, InvInsChinaCoalExcelDto.class, 0, 1, 1);
  135. // zmlist.stream().forEach(a -> {
  136. //
  137. // InvInsExternalBillsDetails iiebd = new InvInsExternalBillsDetails();
  138. // if (m.containsKey(a.getPlateNum())) {
  139. // iiebd = m.get(a.getPlateNum());
  140. //
  141. // } else {
  142. // BeanUtil.copyProperties(a, iiebd);
  143. // }
  144. // buildChinaCoalDtoParam(a, iiebd);
  145. // m.put(a.getPlateNum(), iiebd);
  146. // });
  147. //
  148. // } else {
  149. // //万家模板
  150. // List<InvInsSimpleSysExcelDto> wjlist = ExcelUtils2.importExcel(file, InvInsSimpleSysExcelDto.class, 0, 1, 1);
  151. // wjlist.stream().forEach(b -> {
  152. //
  153. // InvInsExternalBillsDetails iiebd = new InvInsExternalBillsDetails();
  154. // if (m.containsKey(b.getPlateNum())) {
  155. // iiebd = m.get(b.getPlateNum());
  156. //
  157. // } else {
  158. // BeanUtil.copyProperties(b, iiebd);
  159. // }
  160. //
  161. // buildSimpleSysDtoParam(b, iiebd);
  162. //
  163. //
  164. // m.put(b.getPlateNum(), iiebd);
  165. //
  166. //
  167. // });
  168. // }
  169. //判断车牌号是否存在 保司
  170. List<String> listKey = m.keySet().stream().collect(Collectors.toList());
  171. LambdaQueryWrapper<InvInsExternalBillsDetails> lqw = new LambdaQueryWrapper();
  172. lqw.select(InvInsExternalBillsDetails::getPlateNum);
  173. lqw.in(InvInsExternalBillsDetails::getPlateNum, listKey);
  174. //查询获取对象具体字段的集合
  175. List<String> longs = listObjs(lqw, new Function<Object, String>() {
  176. @Override
  177. public String apply(Object id) {
  178. return id.toString();
  179. }
  180. });
  181. List<InvInsExternalBillsDetails> plateNumRepetitionList = list(lqw);
  182. if (plateNumRepetitionList.size() > 0 && plateNumRepetitionList.size() < 5) {
  183. throw new SystemException("车牌号已经存在:" + longs);
  184. } else if (plateNumRepetitionList.size() > 5) {
  185. throw new SystemException("大量车牌号已经存在");
  186. }
  187. list = new ArrayList<>(m.values());
  188. return list;
  189. }
  190. /**
  191. * 构造 中煤 dto参数
  192. *
  193. * @author: lig
  194. * @date: 2023年07月10日 0010
  195. */
  196. void buildChinaCoalDtoParam(InvInsChinaCoalExcelDto dto, InvInsExternalBillsDetails iiebd) {
  197. iiebd.setStatus("0");
  198. if (dto.getInsKindName().equals("机动车交通事故责任强制保险")) {
  199. iiebd.setMlifta(dto.getPremium());
  200. iiebd.setVavt(dto.getVavt());
  201. } else {
  202. //商业保费
  203. iiebd.setCip(dto.getPremium());
  204. //三者保额
  205. iiebd.setTpi(dto.getTpi());
  206. //三者保费
  207. iiebd.setTpiCost(dto.getTpiPremium());
  208. }
  209. }
  210. /**
  211. * 构造 简易系统(万家) dto参数
  212. *
  213. * @author: lig
  214. * @date: 2023年07月10日 0010
  215. */
  216. void buildSimpleSysDtoParam(InvInsSimpleSysExcelDto simpleSysDto, InvInsExternalBillsDetails iiebd) {
  217. iiebd.setStatus("0");
  218. if (StringUtils.isNotEmpty(simpleSysDto.getInsKindName()) && simpleSysDto.getInsKindName().equals("交强险")) {
  219. iiebd.setMlifta(simpleSysDto.getPremium());
  220. iiebd.setVavt(simpleSysDto.getVavt());
  221. } else {
  222. //商业保费
  223. iiebd.setCip(simpleSysDto.getPremium());
  224. // //三者保额
  225. // iiebd.setTpi(simpleSysDto.getTpi());
  226. // //三者保费
  227. // iiebd.setTpiCost(simpleSysDto.getTpiPremium());
  228. }
  229. }
  230. /**
  231. * 构造 标准模板 dto参数
  232. *
  233. * @author: lig
  234. * @date: 2023-07-10
  235. */
  236. void buildStandardDtoParam(InvInsStandardExcelDto simpleSysDto, InvInsExternalBillsDetails iiebd) {
  237. iiebd.setInsHabit(simpleSysDto.getProductName());
  238. iiebd.setStatus("0");
  239. }
  240. }