Pārlūkot izejas kodu

禁止自定义产品编码重复,客户分页跟进记录保留3条

yzc 2 gadi atpakaļ
vecāks
revīzija
5423545bc2

+ 11 - 24
hx-customer/src/main/java/com/fjhx/customer/service/customer/impl/CustomerServiceImpl.java

@@ -26,8 +26,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -76,18 +74,13 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
         List<CustomerVo> records = page.getRecords();
         AreaUtil.setAreaName(records);
         //赋值客户跟进记录
-        List<Long> customerIds = records.stream().map(Customer::getId).collect(Collectors.toList());
-        if (ObjectUtil.isNotEmpty(customerIds)) {
-            Map<Long, List<CustomerFollowRecords>> longListMap = customerFollowRecordsService.mapKGroup(CustomerFollowRecords::getCustomerId,
-                    q -> q.in(CustomerFollowRecords::getCustomerId, customerIds).orderByDesc(CustomerFollowRecords::getDate));
-            for (CustomerVo record : records) {
-//                List<CustomerFollowRecords> customerFollowRecords = longListMap.get(record.getId());
-//                if (ObjectUtil.isNotEmpty(customerFollowRecords)) {
-//                    record.setCustomerFollowRecordsList(customerFollowRecords.subList(0, 2));
-//                }
-                record.setCustomerFollowRecordsList(longListMap.get(record.getId()));
-            }
+        for (CustomerVo record : records) {
+            List<CustomerFollowRecords> customerFollowRecordsList = customerFollowRecordsService.list(q ->
+                    q.eq(CustomerFollowRecords::getCustomerId, record.getId())
+                            .orderByDesc(CustomerFollowRecords::getDate).last("limit 3"));
+            record.setCustomerFollowRecordsList(customerFollowRecordsList);
         }
+
         return page;
     }
 
@@ -177,17 +170,11 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
         List<CustomerVo> records = page.getRecords();
         AreaUtil.setAreaName(records);
         //赋值客户跟进记录
-        List<Long> customerIds = records.stream().map(Customer::getId).collect(Collectors.toList());
-        if (ObjectUtil.isNotEmpty(customerIds)) {
-            Map<Long, List<CustomerFollowRecords>> longListMap = customerFollowRecordsService.mapKGroup(CustomerFollowRecords::getCustomerId,
-                    q -> q.in(CustomerFollowRecords::getCustomerId, customerIds));
-            for (CustomerVo record : records) {
-//                List<CustomerFollowRecords> customerFollowRecords = longListMap.get(record.getId());
-//                if (ObjectUtil.isNotEmpty(customerFollowRecords)) {
-//                    record.setCustomerFollowRecordsList(customerFollowRecords.subList(0, 2));
-//                }
-                record.setCustomerFollowRecordsList(longListMap.get(record.getId()));
-            }
+        for (CustomerVo record : records) {
+            List<CustomerFollowRecords> customerFollowRecordsList = customerFollowRecordsService.list(q ->
+                    q.eq(CustomerFollowRecords::getCustomerId, record.getId())
+                            .orderByDesc(CustomerFollowRecords::getDate).last("limit 3"));
+            record.setCustomerFollowRecordsList(customerFollowRecordsList);
         }
         return page;
     }

+ 44 - 2
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -123,8 +123,48 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
 
     @Override
     public Page<ProductInfoVo> getPageByWdly(ProductInfoSelectDto dto) {
-        Page<ProductInfoVo> page = getPage(dto);
+        IWrapper<ProductInfo> wrapper = getWrapper();
+        wrapper.orderByDesc("pi", ProductInfo::getId);
+        wrapper.eq("pi", ProductInfo::getType, dto.getType());
+        wrapper.eq("pi", ProductInfo::getDefinition, dto.getDefinition());
+        wrapper.eq("pi", ProductInfo::getProductClassifyId, dto.getProductClassifyId());
+        wrapper.keyword(dto,
+                new SqlField("pi", ProductInfo::getName),
+                new SqlField("pi", ProductInfo::getCustomCode)
+        );
+        //计算并根据生命周期过滤
+        wrapper.eq("IF(DATEDIFF(now(),pi.create_time)> json_unquote( victoriatourist_json -> '$.growUpDay' ),3,IF( DATEDIFF(now(),pi.create_time)> json_unquote( victoriatourist_json -> '$.newProductsDay' ), 2, 1 ))", dto.getLifeCycle());
+        wrapper.eq("json_unquote( victoriatourist_json -> '$.combination' )", dto.getCombination());
+        Page<ProductInfoVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
+
         List<ProductInfoVo> records = page.getRecords();
+
+        if (records.size() == 0) {
+            return page;
+        }
+
+        List<ProductClassify> productClassifyList = productClassifyService.list();
+        Map<Long, ProductClassify> productClassifyMap = productClassifyList.stream().collect(Collectors.toMap(BaseIdPo::getId, Function.identity()));
+
+        for (ProductInfoVo record : records) {
+            Long productClassifyId = record.getProductClassifyId();
+            ProductClassify productClassify = productClassifyMap.get(productClassifyId);
+            if (productClassify == null) {
+                continue;
+            }
+
+            record.setClassifyName(productClassify.getName());
+
+            List<String> classifyNameGroup = new ArrayList<>();
+
+            while (productClassify != null) {
+                classifyNameGroup.add(0, productClassify.getName());
+                productClassify = productClassifyMap.get(productClassify.getParentId());
+            }
+            record.setClassifyNameGroup(classifyNameGroup);
+
+        }
+//--------------------------------------------------
         //赋值维多利亚扩展部门名称
         List<Long> ids = new ArrayList<>();
         for (ProductInfoVo record : records) {
@@ -238,6 +278,8 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         productInfoDto.setCode(CodeEnum.PRODUCT.getCode());
         // 排除名称重复
         this.nameDuplication(ProductInfo::getName, productInfoDto.getName(), "产品名称重复");
+        // 排除自定义编码重复
+        this.nameDuplication(ProductInfo::getCustomCode, productInfoDto.getCustomCode(), "产品自定义编码重复");
         this.save(productInfoDto);
         ObsFileUtil.saveFile(productInfoDto.getFileList(), productInfoDto.getId());
     }
@@ -327,7 +369,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             //产品分类名称转id
             ProductClassify productClassify = productClassifyService.getOne(q -> q.eq(ProductClassify::getName, productInfoEhsdExcel.getProductClassifyName()));
             if (ObjectUtil.isEmpty(productClassify)) {
-                throw new ServiceException("未知产品分类"+ productInfoEhsdExcel.getProductClassifyName());
+                throw new ServiceException("未知产品分类" + productInfoEhsdExcel.getProductClassifyName());
             }
             productInfo.setProductClassifyId(productClassify.getId());
             //单位名称转字典key