TaxSourceServiceImpl.java 18 KB

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