TaxSourceServiceImpl.java 18 KB

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