Commit c7c45e8d authored by 王晓旭's avatar 王晓旭

统一修改表格搜索

parents e073c0c8 bb761626
......@@ -164,7 +164,7 @@ export default {
if (this.hideCommunity) {
return 6
}
return 4
return 3
}
},
created() {
......
......@@ -41,7 +41,6 @@
search: [
],
columns: [
{type: "selection", width: 60},
{type: "index",label: "序号",width: 50},
{label: "标签Id", prop: "labelId", formatter: this.formatter},
......@@ -67,4 +66,4 @@
};
}
};
</script>
\ No newline at end of file
</script>
......@@ -39,6 +39,8 @@
return {
config: {
search: [
],
columns: [
{type: "selection", width: 60},
......@@ -67,4 +69,4 @@
};
}
};
</script>
\ No newline at end of file
</script>
......@@ -118,7 +118,6 @@
},
],
columns: [
// {type: "selection", width: 60},
{type: "index",label: "序号",width: 50},
{label: "产品名称", prop: "productName"},
......
......@@ -19,9 +19,9 @@ public class ProductVo extends BaseEntityLong {
/** 主键ID,主键,自增长列表 */
private List <Long> idList;
//所属公司
//所属公司
private String companyId;
//所属企业
//所属企业
private String categoryId;
......
package com.mortals.xhx.module.product.service;
import com.mortals.framework.service.ICRUDCacheService;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.product.model.ProductEntity;
import com.mortals.xhx.module.product.dao.ProductDao;
......@@ -10,7 +11,7 @@ import com.mortals.xhx.module.product.dao.ProductDao;
* @author zxfei
* @date 2023-09-18
*/
public interface ProductService extends ICRUDService<ProductEntity,Long>{
public interface ProductService extends ICRUDCacheService<ProductEntity,Long> {
ProductDao getDao();
}
\ No newline at end of file
package com.mortals.xhx.module.product.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.xhx.module.category.model.CategoryEntity;
import com.mortals.xhx.module.category.model.CategoryQuery;
import com.mortals.xhx.module.category.service.CategoryService;
import com.mortals.xhx.module.company.model.CompanyEntity;
import com.mortals.xhx.module.company.model.CompanyProductEntity;
......@@ -20,9 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.mortals.xhx.module.product.service.ProductQuestionService;
import org.springframework.util.ObjectUtils;
import java.util.Date;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
......@@ -36,7 +38,7 @@ import lombok.extern.slf4j.Slf4j;
*/
@Service("productService")
@Slf4j
public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, ProductEntity, Long> implements ProductService {
public class ProductServiceImpl extends AbstractCRUDCacheServiceImpl<ProductDao, ProductEntity, Long> implements ProductService {
@Autowired
private ProductQuestionService productQuestionService;
......@@ -51,6 +53,74 @@ public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, Prod
private CompanyService companyService;
@Override
public Result<ProductEntity> find(ProductEntity entity, PageInfo pageInfo, Context context) throws AppException {
Result<ProductEntity> productEntityResult = new Result<>();
if (ObjectUtils.isEmpty(entity.getCategoryId()) && ObjectUtils.isEmpty(entity.getCompanyId())) {
return super.find(entity, pageInfo, context);
} else {
//针对不同查询返回不同结果集
if (!ObjectUtils.isEmpty(entity.getCategoryId()) && ObjectUtils.isEmpty(entity.getCompanyId())) {
Result<ProductCategoryEntity> productCategoryResult = productCategoryService.find(new ProductCategoryQuery().categoryId(Long.parseLong(entity.getCategoryId())), pageInfo, context);
List<ProductEntity> productList = getProductEntitiesByCategory(entity, productCategoryResult);
productEntityResult.setList(productList);
productEntityResult.setPageInfo(productCategoryResult.getPageInfo());
productEntityResult.setDict(productCategoryResult.getDict());
} else if (ObjectUtils.isEmpty(entity.getCategoryId()) && !ObjectUtils.isEmpty(entity.getCompanyId())) {
Result<CompanyProductEntity> companyProductEntityResult = companyProductService.find(new CompanyProductQuery().companyId(Long.parseLong(entity.getCompanyId())), pageInfo, context);
List<CompanyProductEntity> companyProducList = companyProductEntityResult.getList();
List<ProductEntity> productList = getProductEntitiesByCompanyId(entity, companyProducList);
productEntityResult.setList(productList);
productEntityResult.setPageInfo(companyProductEntityResult.getPageInfo());
productEntityResult.setDict(companyProductEntityResult.getDict());
} else {
//同时查询公司与种类
Result<ProductCategoryEntity> productCategoryResult = productCategoryService.find(new ProductCategoryQuery().categoryId(Long.parseLong(entity.getCategoryId())), pageInfo, context);
List<ProductEntity> productCategoryList = getProductEntitiesByCategory(entity, productCategoryResult);
Result<CompanyProductEntity> companyProductEntityResult = companyProductService.find(new CompanyProductQuery().companyId(Long.parseLong(entity.getCompanyId())), pageInfo, context);
List<CompanyProductEntity> companyProducList = companyProductEntityResult.getList();
List<ProductEntity> productCompanyList = getProductEntitiesByCompanyId(entity, companyProducList);
//求2个list的交集
List<ProductEntity> collect = CollUtil.intersection(productCategoryList, productCompanyList).stream().collect(Collectors.toList());
productEntityResult.setList(collect);
pageInfo.setTotalResult(collect.size());
productEntityResult.setPageInfo(pageInfo);
productEntityResult.setDict(companyProductEntityResult.getDict());
}
}
return productEntityResult;
}
private List<ProductEntity> getProductEntitiesByCompanyId(ProductEntity entity, List<CompanyProductEntity> companyProducList) {
List<ProductEntity> productList = companyProducList.stream().map(item -> {
ProductEntity productEntity = this.getCache(item.getProductId().toString());
if (!ObjectUtils.isEmpty(productEntity)) {
productEntity.setCompanyId(entity.getCompanyId());
String categoryIds = productCategoryService.find(new ProductCategoryQuery().productId(item.getId())).stream().map(i -> i.getCategoryId().toString()).collect(Collectors.joining(","));
productEntity.setCategoryId(categoryIds);
}
return productEntity;
}).collect(Collectors.toList());
return productList;
}
private List<ProductEntity> getProductEntitiesByCategory(ProductEntity entity, Result<ProductCategoryEntity> productCategoryResult) {
List<ProductEntity> productList = productCategoryResult.getList().stream().map(item -> {
ProductEntity productEntity = this.getCache(item.getProductId().toString());
if (!ObjectUtils.isEmpty(productEntity)) {
String companyIds = companyProductService.find(new CompanyProductQuery().productId(productEntity.getId())).stream().map(i -> i.getProductId().toString()).collect(Collectors.joining(","));
productEntity.setCompanyId(companyIds);
productEntity.setCategoryId(entity.getCategoryId());
}
return productEntity;
}).collect(Collectors.toList());
return productList;
}
@Override
protected void findAfter(ProductEntity params, PageInfo pageInfo, Context context, List<ProductEntity> list) throws AppException {
list.forEach(item -> {
......@@ -59,6 +129,24 @@ public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, Prod
item.setCompanyId(companyIds);
item.setCategoryId(categoryIds);
});
if (!ObjectUtils.isEmpty(params.getCategoryId())) {
//种类不为空 删除掉空的
Iterator<ProductEntity> iterator = list.iterator();
while (iterator.hasNext()) {
ProductEntity product = iterator.next();
String categoryIds = productCategoryService.find(new ProductCategoryQuery().productId(product.getId())).stream().map(i -> i.getCategoryId().toString()).collect(Collectors.joining(","));
}
}
if (!ObjectUtils.isEmpty(params.getCompanyId())) {
//公司查询不为空
}
}
@Override
......@@ -186,7 +274,6 @@ public class ProductServiceImpl extends AbstractCRUDServiceImpl<ProductDao, Prod
productQuestionService.removeList(productQuestionlist, context);
super.removeAfter(ids, context, result);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment