From 8de09297dcc5393cc8542f29318b17f5696d4f8d Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期五, 17 七月 2026 09:28:46 +0800
Subject: [PATCH] feat:单点登录 首页及首页跳转
---
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ProductServiceImpl.java | 203 +++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 180 insertions(+), 23 deletions(-)
diff --git a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ProductServiceImpl.java b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ProductServiceImpl.java
index 75b1d87..7e8d4a8 100644
--- a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ProductServiceImpl.java
+++ b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ProductServiceImpl.java
@@ -1,23 +1,37 @@
package com.by4cloud.platformx.business.service.impl;
+import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.by4cloud.platformx.admin.api.entity.SysDept;
+import com.by4cloud.platformx.business.dto.ProductAddDTO;
+import com.by4cloud.platformx.business.dto.ProductQueryDTO;
import com.by4cloud.platformx.business.entity.Product;
+import com.by4cloud.platformx.business.entity.TaxCode;
import com.by4cloud.platformx.business.mapper.ProductMapper;
+import com.by4cloud.platformx.business.mapper.TaxCodeMapper;
import com.by4cloud.platformx.business.service.ProductService;
+import com.by4cloud.platformx.business.vo.ProductExcelVO;
+import com.by4cloud.platformx.business.vo.ProductSelectVo;
+import com.by4cloud.platformx.common.core.util.R;
+import com.by4cloud.platformx.common.data.datascope.DataScope;
+import com.by4cloud.platformx.common.excel.vo.ErrorMessage;
import jakarta.validation.constraints.NotNull;
-import org.springframework.beans.BeanUtils;
+import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
+import org.springframework.validation.BindingResult;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+
+import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
+import java.util.stream.IntStream;
/**
* 浜у搧淇℃伅
@@ -26,31 +40,42 @@
* @date 2026-05-07 10:17:52
*/
@Service
+@RequiredArgsConstructor
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
- @Override
- public List<Tree<Long>> treeList(Long parentId, String productName) {
- Long parent = parentId == null ? 0l : parentId;
+ private final TaxCodeMapper taxCodeMapper;
+
+ @Override
+ public List<Tree<Long>> treeList() {
List<TreeNode<Long>> collect = baseMapper
- .selectList(Wrappers.<Product>lambdaQuery()
- .like(StrUtil.isNotBlank(productName), Product::getProductName, productName)
- .orderByAsc(Product::getCreateTime))
+ .selectListByScope(Wrappers.<Product>lambdaQuery()
+ .orderByAsc(Product::getCreateTime), DataScope.of("comp_id"))
.stream().map(getNodeFunction()).collect(Collectors.toList());
// 妯$硦鏌ヨ 涓嶇粍瑁呮爲缁撴瀯 鐩存帴杩斿洖 琛ㄦ牸鏂逛究缂栬緫
- if (StrUtil.isNotBlank(productName)) {
- return collect.stream().map(node -> {
- Tree<Long> tree = new Tree<>();
- tree.putAll(node.getExtra());
- BeanUtils.copyProperties(node, tree);
- return tree;
- }).collect(Collectors.toList());
- }
-
- return TreeUtil.build(collect, parent);
+// if (StrUtil.isNotBlank(productName)) {
+// return collect.stream().map(node -> {
+// Tree<Long> tree = new Tree<>();
+// tree.putAll(node.getExtra());
+// BeanUtils.copyProperties(node, tree);
+// return tree;
+// }).collect(Collectors.toList());
+// }
+ TreeNode<Long> parent = new TreeNode<>();
+ parent.setId(0L);
+ parent.setName("鐩綍");
+ parent.setParentId(-1L);
+ collect.add(parent);
+ return TreeUtil.build(collect, 0L);
}
- @NotNull
+ @Override
+ public List<ProductSelectVo> getProductList(Product product) {
+ return baseMapper.getProductListByScope(product,DataScope.of("comp_id"));
+ }
+
+
+ @NotNull
private Function<Product, TreeNode<Long>> getNodeFunction() {
return product -> {
TreeNode<Long> node = new TreeNode<>();
@@ -59,7 +84,7 @@
node.setParentId(product.getParentId());
//node.setWeight(product.getParentId());
// 鎵╁睍灞炴��
- Map<String, Object> extra = new HashMap<>();
+// Map<String, Object> extra = new HashMap<>();
// extra.put("picPath", category.getPicPath());
// extra.put("Type", category.getType());
// extra.put("isShow", category.getIsShow());
@@ -67,7 +92,7 @@
// extra.put("status", category.getStatus());
// 閫傞厤 vue3
- Map<String, Object> meta = new HashMap<>();
+// Map<String, Object> meta = new HashMap<>();
/* meta.put("title", product.getProductName());
meta.put("icon", product.getPrice());*/
@@ -76,4 +101,136 @@
return node;
};
}
+
+ @Override
+ public R getProductListByParentId(ProductQueryDTO queryDTO) {
+ String[] erpCodes = new String[]{"house_rental","electricity_bill","water_bill"};
+// MPJLambdaWrapper<Product> wrapper = new MPJLambdaWrapper<Product>()
+// .selectAs("( SELECT count(1) FROM product t1 WHERE t1.parent_id = t.id )",Product::getChildNum)
+// .selectAll(Product.class)
+// .like(StrUtil.isNotEmpty(queryDTO.getProductName()),Product::getProductName,queryDTO.getProductName())
+// .eq(StrUtil.isNotEmpty(queryDTO.getParentId()),Product::getParentId,queryDTO.getParentId())
+// .in(StrUtil.isNotEmpty(queryDTO.getContractCategory())&&StrUtil.equals(queryDTO.getContractCategory(), "water_house"),
+// Product::getErpCode,erpCodes);
+ List<ProductSelectVo> selectVos = baseMapper.getProductListByParentId(queryDTO, Arrays.asList(erpCodes),DataScope.of("comp_id"));
+ if (selectVos.size()>2000){
+ return R.ok(selectVos.subList(0,1999));
+ }
+ return R.ok(selectVos);
+ }
+
+ @Override
+ public R saveErpProduct(List<ProductAddDTO> addDTOS) {
+ if (ArrayUtil.isNotEmpty(addDTOS.toArray())){
+ for (ProductAddDTO addDTO:addDTOS
+ ) {
+ List<Product> classPro = baseMapper.selectListByScope(Wrappers.<Product>lambdaQuery()
+ .eq(StrUtil.isNotEmpty(addDTO.getErpTypeCode()),Product::getErpCode,addDTO.getErpTypeCode())
+ .eq(StrUtil.isNotEmpty(addDTO.getErpTypeName()),Product::getProductName,addDTO.getErpTypeName())
+ , DataScope.of("comp_id"));
+ if (ArrayUtil.isEmpty(classPro.toArray())){
+ Product product = new Product();
+ product.setProductName(addDTO.getErpTypeName());
+ product.setProductType(addDTO.getSpecification());
+ product.setParentId(0L);
+ product.setParentName("鏍圭骇浜у搧");
+ product.setErpCode(addDTO.getErpTypeCode());
+ TaxCode taxCode = taxCodeMapper.selectOne(Wrappers.<TaxCode>lambdaQuery().eq(TaxCode::getBm,addDTO.getTaxCode()).last("limit 1"));
+ if (ObjUtil.isNotNull(taxCode)){
+ product.setTaxClass(taxCode.getMc());
+ product.setTaxRate(Double.valueOf(taxCode.getSl().replace("%","")));
+ }
+ baseMapper.insert(product);
+ classPro.add(product);
+ }
+ Product product = new Product();
+ product.setProductName(addDTO.getErpName());
+ product.setProductType(addDTO.getSpecification());
+ product.setParentId(classPro.get(0).getId());
+ product.setParentName(classPro.get(0).getProductName());
+ product.setErpCode(addDTO.getErpCode());
+ TaxCode taxCode = taxCodeMapper.selectOne(Wrappers.<TaxCode>lambdaQuery().eq(TaxCode::getBm,addDTO.getTaxCode()).last("limit 1"));
+ if (ObjUtil.isNotNull(taxCode)){
+ product.setTaxClass(taxCode.getMc());
+ product.setTaxRate(Double.valueOf(taxCode.getSl().replace("%","")));
+ }
+ baseMapper.insert(product);
+ }
+ }
+ return R.ok();
+ }
+
+ @Override
+ public R importProduct(List<ProductExcelVO> excelVOList, BindingResult bindingResult) {
+ List<ErrorMessage> errorMessageList = (List<ErrorMessage>) bindingResult.getTarget();
+ if (ArrayUtil.isNotEmpty(excelVOList.toArray())) {
+ List<List<ProductExcelVO>> groups = splitList(excelVOList, 5000);
+ groups.stream().forEach(group->{
+ for (ProductExcelVO addDTO:group
+ ) {
+ Set<String> errorMsg = new HashSet<>();
+
+ if (StrUtil.isEmpty(addDTO.getErpTypeCode())&&StrUtil.isEmpty(addDTO.getErpTypeName())) {
+ errorMsg.add("浜у搧鍒嗙被淇℃伅娌℃湁");
+ }
+ List<Product> one = this.listByScope(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, addDTO.getErpCode()));
+ if (ArrayUtil.isNotEmpty(one.toArray())){
+ errorMsg.add("浜у搧erp缂栫爜宸插瓨鍦�");
+ }
+ if (CollUtil.isEmpty(errorMsg)){
+ List<Product> classPro = baseMapper.selectListByScope(Wrappers.<Product>lambdaQuery()
+ .eq(StrUtil.isNotEmpty(addDTO.getErpTypeCode()),Product::getErpCode,addDTO.getErpTypeCode())
+ .eq(StrUtil.isNotEmpty(addDTO.getErpTypeName()),Product::getProductName,addDTO.getErpTypeName())
+ , DataScope.of("comp_id"));
+ if (ArrayUtil.isEmpty(classPro.toArray())){
+ Product product = new Product();
+ product.setProductName(addDTO.getErpTypeName());
+ product.setProductType(addDTO.getSpecification());
+ product.setParentId(0L);
+ product.setParentName("鏍圭骇浜у搧");
+ product.setErpCode(addDTO.getErpTypeCode());
+ TaxCode taxCode = taxCodeMapper.selectOne(Wrappers.<TaxCode>lambdaQuery().eq(TaxCode::getBm,addDTO.getTaxCode()).last("limit 1"));
+ if (ObjUtil.isNotNull(taxCode)){
+ product.setTaxClass(taxCode.getMc());
+ product.setTaxRate(Double.valueOf(taxCode.getSl().replace("%","")));
+ }
+ baseMapper.insert(product);
+ classPro.add(product);
+ }
+ Product product = new Product();
+ product.setProductName(addDTO.getErpName());
+ product.setProductType(addDTO.getSpecification());
+ product.setParentId(classPro.get(0).getId());
+ product.setParentName(classPro.get(0).getProductName());
+ product.setErpCode(addDTO.getErpCode());
+ TaxCode taxCode = taxCodeMapper.selectOne(Wrappers.<TaxCode>lambdaQuery().eq(TaxCode::getBm,addDTO.getTaxCode()).last("limit 1"));
+ if (ObjUtil.isNotNull(taxCode)){
+ product.setTaxClass(taxCode.getMc());
+ product.setTaxRate(Double.valueOf(taxCode.getSl().replace("%","")));
+ }
+ baseMapper.insert(product);
+ }
+ }
+ });
+ }
+ if (CollUtil.isNotEmpty(errorMessageList)) {
+ return R.failed(errorMessageList);
+ }
+ return R.ok();
+ }
+
+ public static <T> List<List<T>> splitList(List<T> list, int batchSize) {
+ if (list == null || list.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ int totalSize = list.size();
+ // 璁$畻闇�瑕佸垎鎴愬灏戠粍
+ int batchCount = (totalSize + batchSize - 1) / batchSize;
+
+ return IntStream.range(0, batchCount)
+ .mapToObj(i -> list.subList(i * batchSize,
+ Math.min((i + 1) * batchSize, totalSize)))
+ .collect(Collectors.toList());
+ }
}
\ No newline at end of file
--
Gitblit v1.9.1