TaxSourceServiceImpl.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. package com.ydtech.modules.protocol.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.ydtech.constants.sys.SystemConstant;
  8. import com.ydtech.modules.admin.constants.RoleConstants;
  9. import com.ydtech.modules.admin.model.SysUserRole;
  10. import com.ydtech.modules.admin.service.SysUserRoleService;
  11. import com.ydtech.modules.esm.model.EsmInsCompany;
  12. import com.ydtech.modules.esm.service.EsmInsCompanyService;
  13. import com.ydtech.modules.order.service.InsOrdersService;
  14. import com.ydtech.modules.protocol.constants.TaxSourceStatusConstants;
  15. import com.ydtech.modules.protocol.dao.TaxSourceMapper;
  16. import com.ydtech.modules.protocol.entity.dto.PtlAgreementDto;
  17. import com.ydtech.modules.protocol.entity.dto.PtlAgreementInsCompanyDto;
  18. import com.ydtech.modules.protocol.entity.dto.TaxSourceDto;
  19. import com.ydtech.modules.protocol.entity.dto.TaxSourceExcludeDto;
  20. import com.ydtech.modules.protocol.entity.po.PtlAgreement;
  21. import com.ydtech.modules.protocol.entity.vo.TaxSourceVo;
  22. import com.ydtech.modules.protocol.service.ITaxSourceExcludeService;
  23. import com.ydtech.modules.protocol.service.ITaxSourceService;
  24. import com.ydtech.modules.protocol.service.PtlAgreementService;
  25. import com.ydtech.utils.idgen.IdGenerate;
  26. import org.apache.poi.ss.formula.functions.T;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.stereotype.Service;
  29. import org.springframework.transaction.annotation.Transactional;
  30. import java.util.ArrayList;
  31. import java.util.Arrays;
  32. import java.util.List;
  33. import java.util.Objects;
  34. import java.util.stream.Collectors;
  35. @Service
  36. public class TaxSourceServiceImpl extends ServiceImpl<TaxSourceMapper, TaxSourceDto> implements ITaxSourceService {
  37. @Autowired
  38. PtlAgreementService ptlAgreementService;
  39. @Autowired
  40. ITaxSourceExcludeService taxSourceExcludeService;
  41. @Autowired
  42. InsOrdersService insOrdersService;
  43. @Autowired
  44. SysUserRoleService sysUserRoleService;
  45. @Autowired
  46. EsmInsCompanyService esmInsCompanyService;
  47. @Override
  48. public IPage<EsmInsCompany> getInsureCompany(Page page) {
  49. return baseMapper.getInsureCompany(page);
  50. }
  51. @Override
  52. public List<PtlAgreement> getAgreementByCompanyId(String companyId, String deptId, String userId) {
  53. List<PtlAgreementInsCompanyDto> agreementInsCompany = this.getAgreementInsCompany(deptId, userId);
  54. List<String> agreementIds = new ArrayList<>();
  55. for (PtlAgreementInsCompanyDto item : agreementInsCompany) {
  56. if (item.getId().equals(companyId)) {
  57. for (PtlAgreementDto agreementDto : item.getAgreement()) {
  58. agreementIds.add(agreementDto.getId());
  59. }
  60. }
  61. }
  62. QueryWrapper<PtlAgreement> queryWrapper = new QueryWrapper<>();
  63. queryWrapper.in("id", agreementIds);
  64. List<PtlAgreement> list = ptlAgreementService.list(queryWrapper);
  65. return list;
  66. }
  67. @Override
  68. @Transactional
  69. public boolean saveTaxSource(TaxSourceVo taxSourceVo) {
  70. //删除排除的信息
  71. taxSourceExcludeService.remove(new LambdaQueryWrapper<TaxSourceExcludeDto>().eq(TaxSourceExcludeDto::getInsCompanyId, taxSourceVo.getInsCompanyId()));
  72. //删除税源配置信息
  73. baseMapper.delete(new LambdaQueryWrapper<TaxSourceDto>().eq(TaxSourceDto::getInsCompanyId,
  74. taxSourceVo.getInsCompanyId()));
  75. //组装税源数据
  76. List<TaxSourceDto> dtos = new ArrayList<>();
  77. List<TaxSourceExcludeDto> excludeDtos = new ArrayList<>();
  78. taxSourceVo.getAgreementTaxList().forEach(agreementTax -> {
  79. TaxSourceDto dto = new TaxSourceDto();
  80. dto.setId(IdGenerate.nextId());
  81. dto.setInsCompanyId(taxSourceVo.getInsCompanyId());
  82. dto.setInsCompanyName(taxSourceVo.getInsCompanyName());
  83. dto.setAgreementId(agreementTax.getAgreementId());
  84. dto.setIsTaxSource(agreementTax.getIsTaxSource());
  85. dto.setLicense(agreementTax.getLicense());
  86. dto.setInsuranceRepertoire(agreementTax.getInsuranceRepertoire());
  87. dtos.add(dto);
  88. });
  89. //组装排除的部门信息
  90. for (String agreementTaxExclude : taxSourceVo.getAgreementTaxExcludeDeptList()) {
  91. TaxSourceExcludeDto dto = new TaxSourceExcludeDto();
  92. dto.setId(IdGenerate.nextId());
  93. dto.setType(Integer.parseInt(TaxSourceStatusConstants.EXCLUDE_TYPE_DEPT));
  94. dto.setInsCompanyId(taxSourceVo.getInsCompanyId());
  95. dto.setExcludeInfo(agreementTaxExclude);
  96. excludeDtos.add(dto);
  97. }
  98. // taxSourceVo.getAgreementTaxExcludeDeptList().forEach(agreementTaxExclude -> {
  99. // TaxSourceExcludeDto dto = new TaxSourceExcludeDto();
  100. // dto.setId(IdGenerate.nextId());
  101. // dto.setType(Integer.parseInt(TaxSourceStatusConstants.EXCLUDE_TYPE_DEPT));
  102. // dto.setInsCompanyId(taxSourceVo.getInsCompanyId());
  103. // dto.setExcludeInfo(agreementTaxExclude.getExcludeInfo());
  104. // excludeDtos.add(dto);
  105. // });
  106. //组装排除的车牌号信息
  107. for (String agreementTaxExclude : taxSourceVo.getAgreementTaxExcludeLicenseList()) {
  108. TaxSourceExcludeDto dto = new TaxSourceExcludeDto();
  109. dto.setId(IdGenerate.nextId());
  110. dto.setType(Integer.parseInt(TaxSourceStatusConstants.EXCLUDE_TYPE_LICENSE));
  111. dto.setInsCompanyId(taxSourceVo.getInsCompanyId());
  112. dto.setExcludeInfo(agreementTaxExclude);
  113. excludeDtos.add(dto);
  114. }
  115. // taxSourceVo.getAgreementTaxExcludeLicenseList().forEach(agreementTaxExclude -> {
  116. // TaxSourceExcludeDto dto = new TaxSourceExcludeDto();
  117. // dto.setId(IdGenerate.nextId());
  118. // dto.setType(Integer.parseInt(TaxSourceStatusConstants.EXCLUDE_TYPE_LICENSE));
  119. // dto.setInsCompanyId(taxSourceVo.getInsCompanyId());
  120. // dto.setExcludeInfo(agreementTaxExclude.getExcludeInfo());
  121. // excludeDtos.add(dto);
  122. // });
  123. this.saveBatch(dtos);
  124. taxSourceExcludeService.saveBatch(excludeDtos);
  125. return true;
  126. }
  127. @Override
  128. public TaxSourceVo getTaxSource(String companyId) {
  129. TaxSourceVo taxSourceVo = new TaxSourceVo();
  130. //税源信息
  131. List<TaxSourceDto> taxSourceDto =
  132. baseMapper.selectList(new LambdaQueryWrapper<TaxSourceDto>().eq(TaxSourceDto::getInsCompanyId,
  133. companyId));
  134. //排除的部门信息
  135. List<TaxSourceExcludeDto> taxSourceExcludeDepts =
  136. taxSourceExcludeService.list(new LambdaQueryWrapper<TaxSourceExcludeDto>().eq(TaxSourceExcludeDto::getInsCompanyId, companyId).eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_DEPT));
  137. //排除的车牌号信息
  138. List<TaxSourceExcludeDto> taxSourceExcludeLicense =
  139. taxSourceExcludeService.list(new LambdaQueryWrapper<TaxSourceExcludeDto>().eq(TaxSourceExcludeDto::getInsCompanyId, companyId).eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_LICENSE));
  140. taxSourceVo.setInsCompanyId(companyId);
  141. //税源信息转换
  142. List<TaxSourceVo.AgreementTax> agreementTaxList = new ArrayList<>();
  143. taxSourceDto.forEach(item -> {
  144. TaxSourceVo.AgreementTax agreementTax = new TaxSourceVo.AgreementTax();
  145. agreementTax.setAgreementId(item.getAgreementId());
  146. agreementTax.setIsTaxSource(item.getIsTaxSource());
  147. agreementTax.setLicense(item.getLicense());
  148. agreementTax.setInsuranceRepertoire(item.getInsuranceRepertoire());
  149. agreementTaxList.add(agreementTax);
  150. });
  151. taxSourceVo.setAgreementTaxList(agreementTaxList);
  152. //部门信息转换
  153. List<String> agreementTaxExcludeDepts = new ArrayList<>();
  154. taxSourceExcludeDepts.forEach(item -> {
  155. agreementTaxExcludeDepts.add(item.getExcludeInfo());
  156. });
  157. taxSourceVo.setAgreementTaxExcludeDeptList(agreementTaxExcludeDepts.toArray(new String[agreementTaxExcludeDepts.size()]));
  158. //车牌信息转换
  159. List<String> agreementTaxExcludeLicense = new ArrayList<>();
  160. taxSourceExcludeLicense.forEach(item -> {
  161. agreementTaxExcludeLicense.add(item.getExcludeInfo());
  162. });
  163. taxSourceVo.setAgreementTaxExcludeLicenseList(agreementTaxExcludeLicense.toArray(new String[agreementTaxExcludeLicense.size()]));
  164. return taxSourceVo;
  165. }
  166. public List<PtlAgreementInsCompanyDto> getAgreementInsCompany(String deptId, String userId) {
  167. // 领导标志
  168. SysUserRole userRole = sysUserRoleService.selectByUserId(userId);
  169. if (Arrays.asList(SystemConstant.getSysRoleTeamLeader()).contains(userRole.getRoleId().toString()) && !RoleConstants.R21.getCode().equals(userRole.getRoleId().toString())) { //团队长可查询下面所有人员订单
  170. deptId = null;
  171. }
  172. List<PtlAgreementInsCompanyDto> agreementCompany = ptlAgreementService.getAgreementCompany(deptId);
  173. return agreementCompany;
  174. }
  175. public PtlAgreementInsCompanyDto getAgreementInsCompany(String deptId, String userId, String companyId) {
  176. // 领导标志
  177. SysUserRole userRole = sysUserRoleService.selectByUserId(userId);
  178. if (Arrays.asList(SystemConstant.getSysRoleTeamLeader()).contains(userRole.getRoleId().toString()) && !RoleConstants.R21.getCode().equals(userRole.getRoleId().toString())) { //团队长可查询下面所有人员订单
  179. deptId = null;
  180. }
  181. PtlAgreementInsCompanyDto agreementCompany = ptlAgreementService.getAgreementCompany(deptId, companyId);
  182. return agreementCompany;
  183. }
  184. // @Override
  185. // public List<PtlAgreementInsCompanyDto> getAgreementInsCompany(String deptId, String userId, String license,
  186. // String volume) {
  187. // //查出所有协议
  188. // List<PtlAgreementInsCompanyDto> agreementInsCompany = this.getAgreementInsCompany(deptId, userId);
  189. // if(license != null && volume != null) {
  190. // //排除的部门信息
  191. // List<TaxSourceExcludeDto> excludeDepts = taxSourceExcludeService.list(new
  192. // LambdaQueryWrapper<TaxSourceExcludeDto>().eq
  193. // (TaxSourceExcludeDto::getExcludeInfo, deptId)
  194. // .eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_DEPT));
  195. //
  196. // agreementInsCompany.forEach(item ->
  197. // excludeDepts.stream()
  198. // .filter(taxSourceDto -> item.getId().equals(taxSourceDto.getInsCompanyId()) &&
  199. // taxSourceDto.getExcludeInfo
  200. // ().equals(deptId))
  201. // .findFirst()
  202. // .ifPresent(taxSourceDto -> item.setIsExclude(TaxSourceStatusConstants.TAX_SOURCE_START))
  203. // );
  204. // //查找排除的车牌号
  205. // List<TaxSourceExcludeDto> licenseExclude = taxSourceExcludeService.list(new
  206. // LambdaQueryWrapper<TaxSourceExcludeDto>().eq
  207. // (TaxSourceExcludeDto::getExcludeInfo, license)
  208. // .eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_LICENSE));
  209. // agreementInsCompany.forEach(item -> {
  210. // licenseExclude.forEach(taxSourceDto -> {
  211. // if (item.getId().equals(taxSourceDto.getInsCompanyId())) {
  212. // if (license.equals(taxSourceDto.getExcludeInfo())) {
  213. // //排除
  214. // item.setIsExclude(TaxSourceStatusConstants.TAX_SOURCE_START);
  215. // }
  216. // }
  217. // });
  218. // });
  219. //
  220. // //查找配置的默认项
  221. // List<TaxSourceDto> taxSourceDefaultDtos = baseMapper.selectList(new LambdaQueryWrapper<TaxSourceDto>()
  222. // .eq(TaxSourceDto::getLicense, license));
  223. // //设置协议的默认项
  224. // agreementInsCompany.forEach(item -> {
  225. // taxSourceDefaultDtos.forEach(taxSourceDto -> {
  226. // if (item.getId().equals(taxSourceDto.getInsCompanyId())) {
  227. // item.getAgreement().forEach(agreement -> {
  228. // if (agreement.getId().equals(taxSourceDto.getAgreementId())) {
  229. // agreement.setIsAllocation(TaxSourceStatusConstants.TAX_SOURCE_START);
  230. // }
  231. // });
  232. // }
  233. // });
  234. // });
  235. // //判断汽车排量是否大于1升
  236. // if (Float.parseFloat(volume) >= 1) {
  237. // //查找是否配置税源
  238. // List<TaxSourceDto> taxSourceDtos = baseMapper.selectList(new LambdaQueryWrapper<TaxSourceDto>().eq
  239. // (TaxSourceDto::getIsTaxSource, "1"));
  240. // //设置税源参数
  241. // agreementInsCompany.forEach(item -> {
  242. // if (!TaxSourceStatusConstants.TAX_SOURCE_START.equals(item.getIsExclude())) {
  243. // taxSourceDtos.forEach(taxSourceDto -> {
  244. // if (item.getId().equals(taxSourceDto.getInsCompanyId())) {
  245. // item.getAgreement().forEach(agreement -> {
  246. // if (agreement.getId().equals(taxSourceDto.getAgreementId())) {
  247. // agreement.setIsTaxSource(TaxSourceStatusConstants.TAX_SOURCE_START);
  248. // item.setIsTaxSource(TaxSourceStatusConstants.TAX_SOURCE_START);
  249. // item.setTaxSourceAgreementId(taxSourceDto.getAgreementId());
  250. // }
  251. // });
  252. // }
  253. // });
  254. // }
  255. // });
  256. // }
  257. // }
  258. // return agreementInsCompany;
  259. // }
  260. /**
  261. * 返回是否是税源
  262. *
  263. * @param deptId
  264. * @param userId
  265. * @return
  266. */
  267. @Override
  268. public List<PtlAgreementInsCompanyDto> getAllAgreement(String deptId, String userId) {
  269. //查出所有协议
  270. List<PtlAgreementInsCompanyDto> agreementInsCompany = this.getAgreementInsCompany(deptId, userId);
  271. //查找是否配置税源
  272. List<TaxSourceDto> taxSourceDtos =
  273. baseMapper.selectList(new LambdaQueryWrapper<TaxSourceDto>().eq(TaxSourceDto::getIsTaxSource, "1"));
  274. //设置税源参数
  275. agreementInsCompany.forEach(item -> {
  276. if (!TaxSourceStatusConstants.TAX_SOURCE_START.equals(item.getIsExclude())) {
  277. taxSourceDtos.forEach(taxSourceDto -> {
  278. if (item.getId().equals(taxSourceDto.getInsCompanyId())) {
  279. item.getAgreement().forEach(agreement -> {
  280. if (agreement.getId().equals(taxSourceDto.getAgreementId())) {
  281. agreement.setIsTaxSource(TaxSourceStatusConstants.TAX_SOURCE_START);
  282. item.setIsTaxSource(TaxSourceStatusConstants.TAX_SOURCE_START);
  283. item.setTaxSourceAgreementId(taxSourceDto.getAgreementId());
  284. }
  285. });
  286. }
  287. });
  288. }
  289. });
  290. return agreementInsCompany;
  291. }
  292. /**
  293. * 根据税源获取协议id
  294. *
  295. * @param deptId
  296. * @param userId
  297. * @param companyId
  298. * @param license
  299. * @param volume
  300. * @return
  301. */
  302. @Override
  303. public String getAgreementId(String deptId, String userId, String companyId, String license, String volume,
  304. String productid) {
  305. // 车牌前两位
  306. String firstTwoPlates = license.substring(0, 2);
  307. String resultId = "";
  308. //查找配置的默认项
  309. List<TaxSourceDto> taxSourceDtoList =
  310. baseMapper.selectList(new LambdaQueryWrapper<TaxSourceDto>().eq(TaxSourceDto::getInsCompanyId,
  311. companyId));
  312. List<TaxSourceDto> taxSource =
  313. taxSourceDtoList.stream().filter(x -> x.getLicense().equals(firstTwoPlates)).collect(Collectors.toList());
  314. if (!taxSource.isEmpty()) {
  315. resultId = taxSource.get(0).getAgreementId();
  316. }
  317. boolean isExclude = false;
  318. //排除的部门信息
  319. List<TaxSourceExcludeDto> excludeDepts =
  320. taxSourceExcludeService.list(new LambdaQueryWrapper<TaxSourceExcludeDto>().eq(TaxSourceExcludeDto::getExcludeInfo, deptId).eq(TaxSourceExcludeDto::getInsCompanyId, companyId).eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_DEPT));
  321. //部门排除
  322. if (excludeDepts.stream().anyMatch(taxSourceDto -> taxSourceDto.getExcludeInfo().equals(deptId))) {
  323. isExclude = true;
  324. }
  325. //查找排除的车牌号
  326. List<TaxSourceExcludeDto> licenseExclude =
  327. taxSourceExcludeService.list(new LambdaQueryWrapper<TaxSourceExcludeDto>().eq(TaxSourceExcludeDto::getExcludeInfo, firstTwoPlates).eq(TaxSourceExcludeDto::getType, TaxSourceStatusConstants.EXCLUDE_TYPE_LICENSE));
  328. //车牌排除
  329. if (licenseExclude.stream().anyMatch(taxSourceDto -> taxSourceDto.getExcludeInfo().equals(firstTwoPlates))) {
  330. isExclude = true;
  331. }
  332. // 税源
  333. TaxSourceDto taxSourceDtos =
  334. taxSourceDtoList.stream().filter(x -> x.getIsTaxSource().equals("1")).collect(Collectors.toList()).get(0);
  335. if (!isExclude && (Float.parseFloat(volume) >= 1) && (taxSourceDtos != null)) {
  336. resultId = taxSourceDtos.getAgreementId();
  337. }
  338. // 不包含险种 随机其他保险公司
  339. if (taxSourceDtos != null && taxSourceDtos.getAgreementId().equals(resultId) && taxSourceDtos.getInsuranceRepertoire().contains(productid+",")) {
  340. resultId = taxSourceDtos.getBanishAgreementId();
  341. }
  342. return resultId;
  343. }
  344. }