mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 23:57:12 +08:00
fix: 品牌增加批量添加接口
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.lihongjie.coal.annotation.OrgScope;
|
|||||||
import cn.lihongjie.coal.annotation.SysLog;
|
import cn.lihongjie.coal.annotation.SysLog;
|
||||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||||
|
import cn.lihongjie.coal.warehouseGoodsBrand.dto.BatchAddRequest;
|
||||||
import cn.lihongjie.coal.warehouseGoodsBrand.dto.CreateWarehouseGoodsBrandDto;
|
import cn.lihongjie.coal.warehouseGoodsBrand.dto.CreateWarehouseGoodsBrandDto;
|
||||||
import cn.lihongjie.coal.warehouseGoodsBrand.dto.UpdateWarehouseGoodsBrandDto;
|
import cn.lihongjie.coal.warehouseGoodsBrand.dto.UpdateWarehouseGoodsBrandDto;
|
||||||
import cn.lihongjie.coal.warehouseGoodsBrand.dto.WarehouseGoodsBrandDto;
|
import cn.lihongjie.coal.warehouseGoodsBrand.dto.WarehouseGoodsBrandDto;
|
||||||
@@ -49,6 +50,13 @@ public class WarehouseGoodsBrandController {
|
|||||||
|
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
public Page<WarehouseGoodsBrandDto> list(@RequestBody CommonQuery request) {
|
public Page<WarehouseGoodsBrandDto> list(@RequestBody CommonQuery request) {
|
||||||
|
|
||||||
return this.service.list(request);
|
return this.service.list(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/batchAdd")
|
||||||
|
public Boolean batchAdd(@RequestBody BatchAddRequest request) {
|
||||||
|
this.service.batchAdd(request);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package cn.lihongjie.coal.warehouseGoodsBrand.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BatchAddRequest {
|
||||||
|
|
||||||
|
private List<String> names;
|
||||||
|
}
|
||||||
@@ -2,7 +2,9 @@ package cn.lihongjie.coal.warehouseGoodsBrand.service;
|
|||||||
|
|
||||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||||
|
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||||
import cn.lihongjie.coal.base.service.BaseService;
|
import cn.lihongjie.coal.base.service.BaseService;
|
||||||
|
import cn.lihongjie.coal.warehouseGoodsBrand.dto.BatchAddRequest;
|
||||||
import cn.lihongjie.coal.warehouseGoodsBrand.dto.CreateWarehouseGoodsBrandDto;
|
import cn.lihongjie.coal.warehouseGoodsBrand.dto.CreateWarehouseGoodsBrandDto;
|
||||||
import cn.lihongjie.coal.warehouseGoodsBrand.dto.UpdateWarehouseGoodsBrandDto;
|
import cn.lihongjie.coal.warehouseGoodsBrand.dto.UpdateWarehouseGoodsBrandDto;
|
||||||
import cn.lihongjie.coal.warehouseGoodsBrand.dto.WarehouseGoodsBrandDto;
|
import cn.lihongjie.coal.warehouseGoodsBrand.dto.WarehouseGoodsBrandDto;
|
||||||
@@ -10,8 +12,13 @@ import cn.lihongjie.coal.warehouseGoodsBrand.entity.WarehouseGoodsBrandEntity;
|
|||||||
import cn.lihongjie.coal.warehouseGoodsBrand.mapper.WarehouseGoodsBrandMapper;
|
import cn.lihongjie.coal.warehouseGoodsBrand.mapper.WarehouseGoodsBrandMapper;
|
||||||
import cn.lihongjie.coal.warehouseGoodsBrand.repository.WarehouseGoodsBrandRepository;
|
import cn.lihongjie.coal.warehouseGoodsBrand.repository.WarehouseGoodsBrandRepository;
|
||||||
|
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
import jakarta.persistence.PersistenceContext;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
@@ -20,6 +27,10 @@ import org.springframework.data.domain.Sort;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -68,4 +79,37 @@ public class WarehouseGoodsBrandService
|
|||||||
|
|
||||||
return page.map(this.mapper::toDto);
|
return page.map(this.mapper::toDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PersistenceContext EntityManager em;
|
||||||
|
@Autowired private CommonMapper commonMapper;
|
||||||
|
|
||||||
|
public void batchAdd(BatchAddRequest request) {
|
||||||
|
|
||||||
|
if (CollectionUtils.isNotEmpty(request.getNames())) {
|
||||||
|
|
||||||
|
Set<String> set =
|
||||||
|
request.getNames().stream()
|
||||||
|
.distinct()
|
||||||
|
.map(StringUtils::trim)
|
||||||
|
.filter(StringUtils::isNotBlank)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
List<String> exists =
|
||||||
|
em.createQuery(
|
||||||
|
"select distinct name from WarehouseGoodsBrandEntity",
|
||||||
|
String.class)
|
||||||
|
.getResultList();
|
||||||
|
set.removeAll(exists);
|
||||||
|
if (CollectionUtils.isNotEmpty(set)) {
|
||||||
|
set.forEach(
|
||||||
|
name -> {
|
||||||
|
WarehouseGoodsBrandEntity entity = new WarehouseGoodsBrandEntity();
|
||||||
|
entity.setName(name);
|
||||||
|
this.repository.save(entity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user