FirmAccountLogServiceImpl.java 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package com.zsElectric.boot.business.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.zsElectric.boot.business.mapper.FirmAccountLogMapper;
  7. import com.zsElectric.boot.business.model.entity.FirmAccountLog;
  8. import com.zsElectric.boot.business.model.entity.FirmInfo;
  9. import com.zsElectric.boot.business.model.query.FirmAccountLogQuery;
  10. import com.zsElectric.boot.business.model.vo.FirmAccountLogVO;
  11. import com.zsElectric.boot.business.service.FirmAccountLogService;
  12. import com.zsElectric.boot.business.service.FirmInfoService;
  13. import lombok.RequiredArgsConstructor;
  14. import org.springframework.stereotype.Service;
  15. import cn.hutool.core.util.StrUtil;
  16. import java.util.Arrays;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.stream.Collectors;
  20. /**
  21. * 企业资金流水服务实现类
  22. *
  23. * @author zsElectric
  24. * @since 2025-12-26
  25. */
  26. @Service
  27. @RequiredArgsConstructor
  28. public class FirmAccountLogServiceImpl extends ServiceImpl<FirmAccountLogMapper, FirmAccountLog> implements FirmAccountLogService {
  29. private final FirmInfoService firmInfoService;
  30. @Override
  31. public IPage<FirmAccountLogVO> getFirmAccountLogPage(FirmAccountLogQuery queryParams) {
  32. Page<FirmAccountLog> page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize());
  33. LambdaQueryWrapper<FirmAccountLog> queryWrapper = new LambdaQueryWrapper<>();
  34. queryWrapper.eq(queryParams.getFirmId() != null, FirmAccountLog::getFirmId, queryParams.getFirmId())
  35. .eq(queryParams.getFirmType() != null, FirmAccountLog::getFirmType, queryParams.getFirmType())
  36. .eq(queryParams.getIncomeType() != null, FirmAccountLog::getIncomeType, queryParams.getIncomeType())
  37. .eq(queryParams.getChangeType() != null, FirmAccountLog::getChangeType, queryParams.getChangeType())
  38. .like(StrUtil.isNotBlank(queryParams.getSerialNo()), FirmAccountLog::getSerialNo, queryParams.getSerialNo())
  39. .like(StrUtil.isNotBlank(queryParams.getName()), FirmAccountLog::getName, queryParams.getName())
  40. .orderByDesc(FirmAccountLog::getCreateTime);
  41. IPage<FirmAccountLog> entityPage = this.page(page, queryWrapper);
  42. // 转换为VO
  43. IPage<FirmAccountLogVO> voPage = entityPage.convert(entity -> {
  44. FirmAccountLogVO vo = new FirmAccountLogVO();
  45. vo.setId(entity.getId());
  46. vo.setFirmId(entity.getFirmId());
  47. vo.setProjectName(entity.getProjectName());
  48. vo.setName(entity.getName());
  49. vo.setSerialNo(entity.getSerialNo());
  50. vo.setIncomeType(entity.getIncomeType());
  51. vo.setBeforeChange(entity.getBeforeChange());
  52. vo.setAfterChange(entity.getAfterChange());
  53. vo.setMoneyChange(entity.getMoneyChange());
  54. vo.setChangeType(entity.getChangeType());
  55. vo.setChildId(entity.getChildId());
  56. vo.setRemark(entity.getRemark());
  57. vo.setCreateTime(entity.getCreateTime());
  58. return vo;
  59. });
  60. // 填充企业名称和类型
  61. List<Long> firmIds = voPage.getRecords().stream()
  62. .map(FirmAccountLogVO::getFirmId)
  63. .distinct()
  64. .collect(Collectors.toList());
  65. if (!firmIds.isEmpty()) {
  66. Map<Long, FirmInfo> firmInfoMap = firmInfoService.listByIds(firmIds).stream()
  67. .collect(Collectors.toMap(FirmInfo::getId, firm -> firm));
  68. voPage.getRecords().forEach(vo -> {
  69. FirmInfo firmInfo = firmInfoMap.get(vo.getFirmId());
  70. if (firmInfo != null) {
  71. vo.setFirmName(firmInfo.getName());
  72. vo.setFirmType(firmInfo.getFirmType() != null ? firmInfo.getFirmType() : 1);
  73. }
  74. });
  75. }
  76. return voPage;
  77. }
  78. @Override
  79. public boolean deleteFirmAccountLogs(String ids) {
  80. List<Long> idList = Arrays.stream(ids.split(","))
  81. .map(Long::valueOf)
  82. .collect(Collectors.toList());
  83. return this.removeByIds(idList);
  84. }
  85. }