物料导入
parent
6c483a7118
commit
2441611940
|
|
@ -22,6 +22,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @website https://eladmin.vip
|
* @website https://eladmin.vip
|
||||||
|
|
@ -37,4 +38,7 @@ public interface ItemRepository extends JpaRepository<Item, Long>, JpaSpecificat
|
||||||
|
|
||||||
@Query(value = "SELECT DISTINCT b.* FROM `data_item_key` a INNER JOIN `base_item` b on a.item_id = b.id", nativeQuery = true)
|
@Query(value = "SELECT DISTINCT b.* FROM `data_item_key` a INNER JOIN `base_item` b on a.item_id = b.id", nativeQuery = true)
|
||||||
List<Item> quryOneItemAll();
|
List<Item> quryOneItemAll();
|
||||||
|
|
||||||
|
@Query(value = "from Item i where i.code in :itemCodes ")
|
||||||
|
List<Item> findByCodes(Set itemCodes);
|
||||||
}
|
}
|
||||||
|
|
@ -79,8 +79,6 @@ import java.util.Map;
|
||||||
@RequestMapping("/api/importData")
|
@RequestMapping("/api/importData")
|
||||||
public class ImportDataController {
|
public class ImportDataController {
|
||||||
private final FileProperties properties;
|
private final FileProperties properties;
|
||||||
private final BigItemRepository bigItemRepository;
|
|
||||||
private final ItemRepository itemRepository;
|
|
||||||
private final ImportDataService importDataService;
|
private final ImportDataService importDataService;
|
||||||
private final AsnService asnService;
|
private final AsnService asnService;
|
||||||
private final PickTicketService pickTicketService;
|
private final PickTicketService pickTicketService;
|
||||||
|
|
@ -112,23 +110,14 @@ public class ImportDataController {
|
||||||
@Transactional
|
@Transactional
|
||||||
@AnonymousAccess
|
@AnonymousAccess
|
||||||
public ResponseEntity<Object> importItem( @RequestParam("file") MultipartFile multipartFile) {
|
public ResponseEntity<Object> importItem( @RequestParam("file") MultipartFile multipartFile) {
|
||||||
List<Map<String, Object>> readAll = getMaps(multipartFile);
|
|
||||||
int a=0;//新增
|
//编码、名称、物料类型
|
||||||
int b=0;//修改
|
try {
|
||||||
for (int i = 0; i < readAll.size(); i++) {
|
String result = importDataService.importItem(multipartFile);
|
||||||
Map<String, Object> map=readAll.get(i);
|
return new ResponseEntity(result, HttpStatus.OK);
|
||||||
String code =(String) map.get("品番");
|
} catch (Exception e) {
|
||||||
if(code==null||code.equals("")){
|
return new ResponseEntity("导入失败:" + e.getMessage(), HttpStatus.BAD_REQUEST);
|
||||||
break;
|
|
||||||
}
|
|
||||||
String re = importDataService.importItem(map);
|
|
||||||
if (re.equals("a")){
|
|
||||||
a=a+1;
|
|
||||||
}else if (re.equals("b")){
|
|
||||||
b=b+1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new ResponseEntity("导入成功:执行"+(a+b)+"行 新增"+a+"行,修改"+b+"行",HttpStatus.OK);
|
|
||||||
}
|
}
|
||||||
@Log("导入其他入库")
|
@Log("导入其他入库")
|
||||||
@ApiOperation("导入其他入库")
|
@ApiOperation("导入其他入库")
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,10 @@ public interface ImportDataService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param stringObjectMap
|
* @param multipartFile web上传的文件
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String importItem(Map<String, Object> stringObjectMap);
|
String importItem(MultipartFile multipartFile);
|
||||||
|
|
||||||
String importBigItem(Map<String, Object> stringObjectMap);
|
String importBigItem(Map<String, Object> stringObjectMap);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Set;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -112,4 +113,12 @@ public interface ItemService {
|
||||||
*/
|
*/
|
||||||
Item existItem(String itemCode);
|
Item existItem(String itemCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据物料编码查询物料信息
|
||||||
|
*
|
||||||
|
* @param itemCodes
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Map<String, Item> findByCodes(Set itemCodes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -16,6 +16,8 @@
|
||||||
package com.youchain.basicdata.service.impl;
|
package com.youchain.basicdata.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.poi.excel.ExcelReader;
|
||||||
|
import cn.hutool.poi.excel.ExcelUtil;
|
||||||
import com.youchain.basicdata.domain.*;
|
import com.youchain.basicdata.domain.*;
|
||||||
import com.youchain.basicdata.repository.*;
|
import com.youchain.basicdata.repository.*;
|
||||||
import com.youchain.basicdata.service.*;
|
import com.youchain.basicdata.service.*;
|
||||||
|
|
@ -30,6 +32,7 @@ import com.youchain.businessdata.domain.PickTicket;
|
||||||
import com.youchain.businessdata.service.*;
|
import com.youchain.businessdata.service.*;
|
||||||
import com.youchain.config.FileProperties;
|
import com.youchain.config.FileProperties;
|
||||||
import com.youchain.exception.BadRequestException;
|
import com.youchain.exception.BadRequestException;
|
||||||
|
import com.youchain.modules.system.domain.Dept;
|
||||||
import com.youchain.modules.system.domain.DictDetail;
|
import com.youchain.modules.system.domain.DictDetail;
|
||||||
import com.youchain.modules.system.repository.DictDetailRepository;
|
import com.youchain.modules.system.repository.DictDetailRepository;
|
||||||
import com.youchain.modules.system.repository.DictRepository;
|
import com.youchain.modules.system.repository.DictRepository;
|
||||||
|
|
@ -62,13 +65,9 @@ public class ImportDataServiceImpl implements ImportDataService {
|
||||||
private final BigItemRepository bigItemRepository;
|
private final BigItemRepository bigItemRepository;
|
||||||
private final AreaRepository areaRepository;
|
private final AreaRepository areaRepository;
|
||||||
private final ItemRepository itemRepository;
|
private final ItemRepository itemRepository;
|
||||||
private final DictDetailRepository dictDetailRepository;
|
|
||||||
private final PointRepository pointRepository;
|
private final PointRepository pointRepository;
|
||||||
private final PointService pointService;
|
private final PointService pointService;
|
||||||
private final AreaService areaService;
|
|
||||||
private final BomAccountRepository bomAccountRepository;
|
private final BomAccountRepository bomAccountRepository;
|
||||||
private final AreaMapper areaMapper;
|
|
||||||
private final PointMapper pointMapper;
|
|
||||||
private final ItemService itemService;
|
private final ItemService itemService;
|
||||||
private final AsnDetailService asnDetailService;
|
private final AsnDetailService asnDetailService;
|
||||||
private final AsnService asnService;
|
private final AsnService asnService;
|
||||||
|
|
@ -78,58 +77,59 @@ public class ImportDataServiceImpl implements ImportDataService {
|
||||||
private final BigItemService bigItemService;
|
private final BigItemService bigItemService;
|
||||||
private final BomAccountService bomAccountService;
|
private final BomAccountService bomAccountService;
|
||||||
private final BomAccountLogService bomAccountLogService;
|
private final BomAccountLogService bomAccountLogService;
|
||||||
|
private final BatchCreateOrUpdate batchCreateOrUpdate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void importBomAccount(int row,Map<String, Object> readAll) {
|
public void importBomAccount(int row, Map<String, Object> readAll) {
|
||||||
String bigItemCode =readAll.get("完成品品番")==null?null:readAll.get("完成品品番").toString();
|
String bigItemCode = readAll.get("完成品品番") == null ? null : readAll.get("完成品品番").toString();
|
||||||
String station_type =readAll.get("工位")==null?null:readAll.get("工位").toString();
|
String station_type = readAll.get("工位") == null ? null : readAll.get("工位").toString();
|
||||||
String itemCode = readAll.get("部品品番")==null?null:readAll.get("部品品番").toString();
|
String itemCode = readAll.get("部品品番") == null ? null : readAll.get("部品品番").toString();
|
||||||
String ac = readAll.get("AC")==null?null:readAll.get("AC").toString();
|
String ac = readAll.get("AC") == null ? null : readAll.get("AC").toString();
|
||||||
String contents = readAll.get("加工内容")==null?null:readAll.get("加工内容").toString();
|
String contents = readAll.get("加工内容") == null ? null : readAll.get("加工内容").toString();
|
||||||
String single = readAll.get("单用")==null?null:readAll.get("单用").toString();
|
String single = readAll.get("单用") == null ? null : readAll.get("单用").toString();
|
||||||
String r_area_name = readAll.get("入库库区")==null?null:readAll.get("入库库区").toString();
|
String r_area_name = readAll.get("入库库区") == null ? null : readAll.get("入库库区").toString();
|
||||||
String c_area_name =readAll.get("出库库区")==null?null:readAll.get("出库库区").toString();
|
String c_area_name = readAll.get("出库库区") == null ? null : readAll.get("出库库区").toString();
|
||||||
String z_point_code =readAll.get("制造库位")==null?null:readAll.get("制造库位").toString();
|
String z_point_code = readAll.get("制造库位") == null ? null : readAll.get("制造库位").toString();
|
||||||
// String c_point_code =readAll.get("暂存库位")==null?null:readAll.get("暂存库位").toString();
|
// String c_point_code =readAll.get("暂存库位")==null?null:readAll.get("暂存库位").toString();
|
||||||
String out_type = readAll.get("出库类型")==null?null:readAll.get("出库类型").toString();
|
String out_type = readAll.get("出库类型") == null ? null : readAll.get("出库类型").toString();
|
||||||
String supplier = readAll.get("供应商")==null?null:readAll.get("供应商").toString();
|
String supplier = readAll.get("供应商") == null ? null : readAll.get("供应商").toString();
|
||||||
String bp_type = readAll.get("部品种类")==null?null:readAll.get("部品种类").toString();
|
String bp_type = readAll.get("部品种类") == null ? null : readAll.get("部品种类").toString();
|
||||||
|
|
||||||
BigItem bigItem = null;
|
BigItem bigItem = null;
|
||||||
if (bigItemCode.length() > 0) {
|
if (bigItemCode.length() > 0) {
|
||||||
bigItem = bigItemRepository.findByCode(bigItemCode);
|
bigItem = bigItemRepository.findByCode(bigItemCode);
|
||||||
if (bigItem == null) {
|
if (bigItem == null) {
|
||||||
throw new BadRequestException(HttpStatus.NOT_FOUND, row+"行"+bigItemCode+"完成品品番无效");
|
throw new BadRequestException(HttpStatus.NOT_FOUND, row + "行" + bigItemCode + "完成品品番无效");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestException(HttpStatus.NOT_FOUND, row+"行"+"请输入完成品品番");
|
throw new BadRequestException(HttpStatus.NOT_FOUND, row + "行" + "请输入完成品品番");
|
||||||
}
|
}
|
||||||
Item item = null;
|
Item item = null;
|
||||||
if (itemCode.length() > 0) {
|
if (itemCode.length() > 0) {
|
||||||
item = itemRepository.findByCode(itemCode);
|
item = itemRepository.findByCode(itemCode);
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
throw new BadRequestException(HttpStatus.NOT_FOUND, row+"行"+itemCode+"部品品番无效");
|
throw new BadRequestException(HttpStatus.NOT_FOUND, row + "行" + itemCode + "部品品番无效");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestException(HttpStatus.NOT_FOUND, row+"行"+"请输入部品品番");
|
throw new BadRequestException(HttpStatus.NOT_FOUND, row + "行" + "请输入部品品番");
|
||||||
}
|
}
|
||||||
Area r_area = null;
|
Area r_area = null;
|
||||||
if (r_area_name.length() > 0) {
|
if (r_area_name.length() > 0) {
|
||||||
r_area = areaRepository.getByName(r_area_name);
|
r_area = areaRepository.getByName(r_area_name);
|
||||||
if (r_area == null) {
|
if (r_area == null) {
|
||||||
throw new BadRequestException(HttpStatus.NOT_FOUND, row+"行"+r_area_name+"入库库区无效");
|
throw new BadRequestException(HttpStatus.NOT_FOUND, row + "行" + r_area_name + "入库库区无效");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestException(HttpStatus.NOT_FOUND, row+"行"+"请输入入库库区");
|
throw new BadRequestException(HttpStatus.NOT_FOUND, row + "行" + "请输入入库库区");
|
||||||
}
|
}
|
||||||
Area c_area = null;
|
Area c_area = null;
|
||||||
if (c_area_name.length() > 0) {
|
if (c_area_name.length() > 0) {
|
||||||
c_area = areaRepository.getByName(c_area_name);
|
c_area = areaRepository.getByName(c_area_name);
|
||||||
if (c_area == null) {
|
if (c_area == null) {
|
||||||
throw new BadRequestException(HttpStatus.NOT_FOUND, row+"行"+c_area_name+"出库库区无效");
|
throw new BadRequestException(HttpStatus.NOT_FOUND, row + "行" + c_area_name + "出库库区无效");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestException(HttpStatus.NOT_FOUND, row+"行"+"请输入出库库区");
|
throw new BadRequestException(HttpStatus.NOT_FOUND, row + "行" + "请输入出库库区");
|
||||||
}
|
}
|
||||||
// Point c_point = null;
|
// Point c_point = null;
|
||||||
// if (c_point_code!=null&&!c_point_code.equals("")) {
|
// if (c_point_code!=null&&!c_point_code.equals("")) {
|
||||||
|
|
@ -139,7 +139,7 @@ public class ImportDataServiceImpl implements ImportDataService {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
Point z_point = null;
|
Point z_point = null;
|
||||||
if (z_point_code!=null&&!z_point_code.equals("")) {
|
if (z_point_code != null && !z_point_code.equals("")) {
|
||||||
z_point = pointRepository.findByCode(z_point_code);
|
z_point = pointRepository.findByCode(z_point_code);
|
||||||
if (z_point == null) {
|
if (z_point == null) {
|
||||||
// z_point = pointService.createPoint(z_point_code, "ZZKW", r_area,c_point);
|
// z_point = pointService.createPoint(z_point_code, "ZZKW", r_area,c_point);
|
||||||
|
|
@ -147,9 +147,9 @@ public class ImportDataServiceImpl implements ImportDataService {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestException(HttpStatus.NOT_FOUND, row+"行"+"请输入制造库位");
|
throw new BadRequestException(HttpStatus.NOT_FOUND, row + "行" + "请输入制造库位");
|
||||||
}
|
}
|
||||||
Boolean isNew= Boolean.FALSE;
|
Boolean isNew = Boolean.FALSE;
|
||||||
BomAccount bomAccount = bomAccountRepository.findByOnly(bigItem.getId(), item.getId(), r_area.getId(), z_point.getId());
|
BomAccount bomAccount = bomAccountRepository.findByOnly(bigItem.getId(), item.getId(), r_area.getId(), z_point.getId());
|
||||||
if (bomAccount == null) {
|
if (bomAccount == null) {
|
||||||
bomAccount = new BomAccount();
|
bomAccount = new BomAccount();
|
||||||
|
|
@ -159,7 +159,7 @@ public class ImportDataServiceImpl implements ImportDataService {
|
||||||
bomAccount.setDept(r_area.getDept());
|
bomAccount.setDept(r_area.getDept());
|
||||||
bomAccount.setZPoint(z_point);
|
bomAccount.setZPoint(z_point);
|
||||||
bomAccount.setBp_type(bp_type);
|
bomAccount.setBp_type(bp_type);
|
||||||
isNew=Boolean.TRUE;
|
isNew = Boolean.TRUE;
|
||||||
}
|
}
|
||||||
bomAccount.setStationType(station_type);
|
bomAccount.setStationType(station_type);
|
||||||
bomAccount.setCArea(c_area);
|
bomAccount.setCArea(c_area);
|
||||||
|
|
@ -169,57 +169,131 @@ public class ImportDataServiceImpl implements ImportDataService {
|
||||||
bomAccount.setSingles(Integer.parseInt(single));
|
bomAccount.setSingles(Integer.parseInt(single));
|
||||||
bomAccount.setOutType(out_type);
|
bomAccount.setOutType(out_type);
|
||||||
bomAccount.setSupplier(supplier);
|
bomAccount.setSupplier(supplier);
|
||||||
if(isNew){
|
if (isNew) {
|
||||||
bomAccountService.create(bomAccount);
|
bomAccountService.create(bomAccount);
|
||||||
bomAccountLogService.copyBomAccount(bomAccount.getId(),"import_add");
|
bomAccountLogService.copyBomAccount(bomAccount.getId(), "import_add");
|
||||||
}else{
|
} else {
|
||||||
bomAccountService.update(bomAccount);
|
bomAccountService.update(bomAccount);
|
||||||
bomAccountLogService.copyBomAccount(bomAccount.getId(),"import_update");
|
bomAccountLogService.copyBomAccount(bomAccount.getId(), "import_update");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String importItem(Map<String, Object> readAll) {
|
public String importItem(MultipartFile multipartFile) {
|
||||||
String re = "";
|
//编码、名称、物料类型
|
||||||
String code = readAll.get("品番")==null?null:readAll.get("品番").toString();
|
FileUtil.checkSize(properties.getMaxSize(), multipartFile.getSize());
|
||||||
String name = readAll.get("品名")==null?null:readAll.get("品名").toString();
|
String suffix = FileUtil.getExtensionName(multipartFile.getOriginalFilename());
|
||||||
String specs = readAll.get("规格")==null?null:readAll.get("规格").toString();
|
String type = FileUtil.getFileType(suffix);
|
||||||
String unit = readAll.get("单位")==null?null:readAll.get("单位").toString();
|
File file = FileUtil.upload(multipartFile, properties.getPath().getPath() + type + File.separator);
|
||||||
String hz = readAll.get("荷资")==null?null:readAll.get("荷资").toString();
|
Dept dept = UserUtils.getDept();
|
||||||
String srs =readAll.get("收容数")==null?null:readAll.get("收容数").toString();
|
ExcelReader reader = ExcelUtil.getReader(file);
|
||||||
if (code.length() > 0) {
|
List<Map<String, Object>> readAll = reader.readAll();
|
||||||
Item item = itemRepository.findByAllCode(code);
|
Set<String> itemCodes = new HashSet<>();//物料集合
|
||||||
if (item == null) {
|
for (Map<String, Object> record : readAll) {
|
||||||
re = "a";
|
String itemCode = record.get("料号").toString().trim();
|
||||||
item = new Item();
|
if (!StringUtils.isEmpty(itemCode)) {
|
||||||
item.setDept(UserUtils.getDept());
|
itemCodes.add(itemCode);
|
||||||
item.setCode(code);
|
|
||||||
} else {
|
|
||||||
re = "b";
|
|
||||||
}
|
|
||||||
item.setName(name);
|
|
||||||
|
|
||||||
if (unit!=null&&!unit.equals("")) {
|
|
||||||
DictDetail dictDetail = dictDetailRepository.findByDictAndLabel("item_unit", unit);
|
|
||||||
item.setUnit(dictDetail.getValue());
|
|
||||||
}
|
|
||||||
if (re.equals("a")){
|
|
||||||
itemRepository.save(item);
|
|
||||||
}else if (re.equals("b")){
|
|
||||||
itemService.update(item);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return re;
|
|
||||||
|
|
||||||
|
//获取已存在的物料
|
||||||
|
Map<String, Item> existingPoint = itemService.findByCodes(itemCodes);
|
||||||
|
|
||||||
|
|
||||||
|
List<Item> itemsToInsert= new ArrayList<>();//新增物料集合
|
||||||
|
List<Item> itemsToUpdate = new ArrayList<>();//修改物料集合
|
||||||
|
for (Map<String, Object> record : readAll) {
|
||||||
|
String itemCode = record.get("料号").toString().trim();
|
||||||
|
//判断是否已存在物料
|
||||||
|
if (existingPoint.containsKey(itemCode)) {
|
||||||
|
Item item = existingPoint.get(itemCode);
|
||||||
|
//更新物料
|
||||||
|
itemsToUpdate.add(updateItems(item, dept, record));
|
||||||
|
} else {
|
||||||
|
//新增点位
|
||||||
|
itemsToInsert.add(createItem(dept, record));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//批量新增物料
|
||||||
|
if (!itemsToInsert.isEmpty()) {
|
||||||
|
batchCreateOrUpdate.batchInsert(itemsToInsert);
|
||||||
|
}
|
||||||
|
|
||||||
|
//批量更新物料
|
||||||
|
if (!itemsToUpdate.isEmpty()) {
|
||||||
|
batchCreateOrUpdate.batchUpdate(itemsToUpdate);
|
||||||
|
}
|
||||||
|
return ("导入成功:" + " 新增(" + itemsToInsert.size() + ")修改(" + itemsToUpdate.size() + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Item updateItems(Item item, Dept dept, Map<String, Object> record) {
|
||||||
|
item.setDept(dept);
|
||||||
|
item.setName(record.get("物料描述").toString().trim());
|
||||||
|
item.setPackageType(record.get("包装类型").toString().trim());
|
||||||
|
item.setSpecQuantity(record.get("规格数量") == null ? 0 : Double.parseDouble(record.get("规格数量").toString()));
|
||||||
|
item.setSpecWeight(record.get("规格重量") == null ? 0 : Double.parseDouble(record.get("规格重量").toString()));
|
||||||
|
item.setGrossWeight(record.get("毛重") == null ? 0 : Double.parseDouble(record.get("毛重").toString()));
|
||||||
|
item.setLength(record.get("长") == null ? 0 : Double.parseDouble(record.get("长").toString()));
|
||||||
|
item.setWidth(record.get("宽") == null ? 0 : Double.parseDouble(record.get("宽").toString()));
|
||||||
|
item.setHeight(record.get("高") == null ? 0 : Double.parseDouble(record.get("高").toString()));
|
||||||
|
item.setVolume(record.get("体积") == null ? 0 : Double.parseDouble(record.get("体积").toString()));
|
||||||
|
item.setUnit(record.get("单位").toString().trim());
|
||||||
|
item.setType(record.get("类型").toString().trim());
|
||||||
|
item.setValueGrade(record.get("物料价值等级").toString().trim());
|
||||||
|
item.setValidPeriod(record.get("保质期") == null ? 0 : Integer.parseInt(record.get("保质期").toString()));
|
||||||
|
item.setAlertDays(record.get("预警天数") == null ? 0 : Integer.parseInt(record.get("预警天数").toString()));
|
||||||
|
item.setIsBatch("是".equals(record.get("是否批次").toString().trim()) ? true : false);
|
||||||
|
item.setIsSerial("是".equals(record.get("是否序列号").toString().trim()) ? true : false);
|
||||||
|
item.setIsValidPeriod("是".equals(record.get("是否有效期").toString().trim()) ? true : false);
|
||||||
|
item.setIsHazardous("是".equals(record.get("是否危化品").toString().trim()) ? true : false);
|
||||||
|
item.setIsInvAvailable("是".equals(record.get("是否有库存").toString().trim()) ? true : false);
|
||||||
|
item.setIsSapMaterial("是".equals(record.get("是否SAP料号").toString().trim()) ? true : false);
|
||||||
|
item.setHeatValue(record.get("热度值") == null ? 0 : Integer.parseInt(record.get("热度值").toString()));
|
||||||
|
item.setDescription(record.get("备注").toString().trim());
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Item createItem(Dept dept, Map<String, Object> record) {
|
||||||
|
Item item = new Item();
|
||||||
|
item.setCode(record.get("料号").toString().trim());
|
||||||
|
item.setName(record.get("物料描述").toString().trim());
|
||||||
|
item.setPackageType(record.get("包装类型").toString().trim());
|
||||||
|
item.setSpecQuantity(record.get("规格数量") == null ? 0 : Double.parseDouble(record.get("规格数量").toString()));
|
||||||
|
item.setSpecWeight(record.get("规格重量") == null ? 0 : Double.parseDouble(record.get("规格重量").toString()));
|
||||||
|
item.setGrossWeight(record.get("毛重") == null ? 0 : Double.parseDouble(record.get("毛重").toString()));
|
||||||
|
item.setLength(record.get("长") == null ? 0 : Double.parseDouble(record.get("长").toString()));
|
||||||
|
item.setWidth(record.get("宽") == null ? 0 : Double.parseDouble(record.get("宽").toString()));
|
||||||
|
item.setHeight(record.get("高") == null ? 0 : Double.parseDouble(record.get("高").toString()));
|
||||||
|
item.setVolume(record.get("体积") == null ? 0 : Double.parseDouble(record.get("体积").toString()));
|
||||||
|
item.setUnit(record.get("单位").toString().trim());
|
||||||
|
item.setType(record.get("类型").toString().trim());
|
||||||
|
item.setValueGrade(record.get("物料价值等级").toString().trim());
|
||||||
|
item.setValidPeriod(record.get("保质期") == null ? 0 : Integer.parseInt(record.get("保质期").toString()));
|
||||||
|
item.setAlertDays(record.get("预警天数") == null ? 0 : Integer.parseInt(record.get("预警天数").toString()));
|
||||||
|
item.setIsBatch("是".equals(record.get("是否批次").toString().trim()) ? true : false);
|
||||||
|
item.setIsSerial("是".equals(record.get("是否序列号").toString().trim()) ? true : false);
|
||||||
|
item.setIsValidPeriod("是".equals(record.get("是否有效期").toString().trim()) ? true : false);
|
||||||
|
item.setIsHazardous("是".equals(record.get("是否危化品").toString().trim()) ? true : false);
|
||||||
|
item.setIsInvAvailable("是".equals(record.get("是否有库存").toString().trim()) ? true : false);
|
||||||
|
item.setIsSapMaterial("是".equals(record.get("是否SAP料号").toString().trim()) ? true : false);
|
||||||
|
item.setHeatValue(record.get("热度值") == null ? 0 : Integer.parseInt(record.get("热度值").toString()));
|
||||||
|
item.setDescription(record.get("备注").toString().trim());
|
||||||
|
item.setDept(dept);
|
||||||
|
item.setEnabled(true);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String importBigItem(Map<String, Object> readAll) {
|
public String importBigItem(Map<String, Object> readAll) {
|
||||||
String re = "";
|
String re = "";
|
||||||
String code =readAll.get("完成品品番")==null?null:readAll.get("完成品品番").toString().trim();
|
String code = readAll.get("完成品品番") == null ? null : readAll.get("完成品品番").toString().trim();
|
||||||
String name = readAll.get("完成品型式名")==null?null:readAll.get("完成品型式名").toString().trim();
|
String name = readAll.get("完成品型式名") == null ? null : readAll.get("完成品型式名").toString().trim();
|
||||||
String models =readAll.get("机种")==null?null:readAll.get("机种").toString().trim();
|
String models = readAll.get("机种") == null ? null : readAll.get("机种").toString().trim();
|
||||||
String country =readAll.get("国别")==null?null:readAll.get("国别").toString().trim();
|
String country = readAll.get("国别") == null ? null : readAll.get("国别").toString().trim();
|
||||||
String outboundType =readAll.get("出库类型")==null?null:readAll.get("出库类型").toString().trim();
|
String outboundType = readAll.get("出库类型") == null ? null : readAll.get("出库类型").toString().trim();
|
||||||
if (code.length() > 0) {
|
if (code.length() > 0) {
|
||||||
BigItem bigItem = bigItemRepository.findByCode(code);
|
BigItem bigItem = bigItemRepository.findByCode(code);
|
||||||
if (bigItem == null) {
|
if (bigItem == null) {
|
||||||
|
|
@ -228,16 +302,17 @@ public class ImportDataServiceImpl implements ImportDataService {
|
||||||
bigItem.setCode(code);
|
bigItem.setCode(code);
|
||||||
bigItem.setDeptId(UserUtils.getDept().getId());
|
bigItem.setDeptId(UserUtils.getDept().getId());
|
||||||
} else {
|
} else {
|
||||||
re = "b";
|
//新增物料
|
||||||
|
//itemsToCreate.add(createItem(dept, record));
|
||||||
}
|
}
|
||||||
bigItem.setModels(models);
|
bigItem.setModels(models);
|
||||||
bigItem.setName(name);
|
bigItem.setName(name);
|
||||||
bigItem.setCountry(country);
|
bigItem.setCountry(country);
|
||||||
bigItem.setOutboundType(outboundType);
|
bigItem.setOutboundType(outboundType);
|
||||||
bigItem.setEnabled(true);
|
bigItem.setEnabled(true);
|
||||||
if (re.equals("a")){
|
if (re.equals("a")) {
|
||||||
bigItemService.create(bigItem);
|
bigItemService.create(bigItem);
|
||||||
}else if (re.equals("b")){
|
} else if (re.equals("b")) {
|
||||||
bigItemService.update(bigItem);
|
bigItemService.update(bigItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -247,23 +322,23 @@ public class ImportDataServiceImpl implements ImportDataService {
|
||||||
@Override
|
@Override
|
||||||
public String importAsnDetail(Map<String, Object> readAll, Asn asn) {
|
public String importAsnDetail(Map<String, Object> readAll, Asn asn) {
|
||||||
String re = "";
|
String re = "";
|
||||||
String code =readAll.get("品番")==null?null:readAll.get("品番").toString();
|
String code = readAll.get("品番") == null ? null : readAll.get("品番").toString();
|
||||||
String qty = readAll.get("数量")==null?null:readAll.get("数量").toString();
|
String qty = readAll.get("数量") == null ? null : readAll.get("数量").toString();
|
||||||
String zzkw = readAll.get("制造库位")==null?null:readAll.get("制造库位").toString();
|
String zzkw = readAll.get("制造库位") == null ? null : readAll.get("制造库位").toString();
|
||||||
if (code.length() > 0) {
|
if (code.length() > 0) {
|
||||||
Item item = itemRepository.findByCode(code);
|
Item item = itemRepository.findByCode(code);
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return "部品品番无效";
|
return "部品品番无效";
|
||||||
}
|
}
|
||||||
Point point=pointService.getPoint(zzkw,null,null,null);
|
Point point = pointService.getPoint(zzkw, null, null, null);
|
||||||
if(point==null){
|
if (point == null) {
|
||||||
return "制造库位无效";
|
return "制造库位无效";
|
||||||
}
|
}
|
||||||
List<BomAccount> boms= bomAccountRepository.queryBomUnique(asn.getArea().getId(),item.getId(), point.getId());
|
List<BomAccount> boms = bomAccountRepository.queryBomUnique(asn.getArea().getId(), item.getId(), point.getId());
|
||||||
if(boms.size()<=0){
|
if (boms.size() <= 0) {
|
||||||
return "BOM工位清单不存在";
|
return "BOM工位清单不存在";
|
||||||
}
|
}
|
||||||
AsnDetail asnDetail=new AsnDetail();
|
AsnDetail asnDetail = new AsnDetail();
|
||||||
asnDetail.setAsn(asn);
|
asnDetail.setAsn(asn);
|
||||||
asnDetail.setDept(UserUtils.getDept());
|
asnDetail.setDept(UserUtils.getDept());
|
||||||
asnDetail.setStatus(BizStatus.OPEN);
|
asnDetail.setStatus(BizStatus.OPEN);
|
||||||
|
|
@ -271,7 +346,7 @@ public class ImportDataServiceImpl implements ImportDataService {
|
||||||
asnDetail.setPoint(point);
|
asnDetail.setPoint(point);
|
||||||
asnDetail.setOrderQty(Double.parseDouble(qty));
|
asnDetail.setOrderQty(Double.parseDouble(qty));
|
||||||
asnDetailService.create(asnDetail);
|
asnDetailService.create(asnDetail);
|
||||||
asn.setOrderQuantity(asn.getOrderQuantity()+asnDetail.getOrderQty());
|
asn.setOrderQuantity(asn.getOrderQuantity() + asnDetail.getOrderQty());
|
||||||
asnService.update(asn);
|
asnService.update(asn);
|
||||||
}
|
}
|
||||||
return re;
|
return re;
|
||||||
|
|
@ -289,24 +364,24 @@ public class ImportDataServiceImpl implements ImportDataService {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return "部品品番无效";
|
return "部品品番无效";
|
||||||
}
|
}
|
||||||
Point point=pointService.getPoint(zzkw,null,null,null);
|
Point point = pointService.getPoint(zzkw, null, null, null);
|
||||||
Long zzkwId=null;
|
Long zzkwId = null;
|
||||||
if(point==null){
|
if (point == null) {
|
||||||
if(pickTicket.getArea().getBexb()) {
|
if (pickTicket.getArea().getBexb()) {
|
||||||
return "制造库位无效";
|
return "制造库位无效";
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
zzkwId=point.getId();
|
zzkwId = point.getId();
|
||||||
}
|
}
|
||||||
// List<BomAccount> boms= bomAccountRepository.queryBomUnique(pickTicket.getArea().getId(),item.getId(), point.getId());
|
// List<BomAccount> boms= bomAccountRepository.queryBomUnique(pickTicket.getArea().getId(),item.getId(), point.getId());
|
||||||
// if(boms.size()<=0){
|
// if(boms.size()<=0){
|
||||||
// return "BOM工位清单不存在";
|
// return "BOM工位清单不存在";
|
||||||
// }
|
// }
|
||||||
Double xbQty=inventoryService.getInvQty(item.getId(),pickTicket.getArea().getId(),zzkwId);
|
Double xbQty = inventoryService.getInvQty(item.getId(), pickTicket.getArea().getId(), zzkwId);
|
||||||
if(xbQty.intValue()<Double.parseDouble(qty)){
|
if (xbQty.intValue() < Double.parseDouble(qty)) {
|
||||||
return "库存不足";
|
return "库存不足";
|
||||||
}
|
}
|
||||||
PickDetail pickDetail=new PickDetail();
|
PickDetail pickDetail = new PickDetail();
|
||||||
pickDetail.setPickTicket(pickTicket);
|
pickDetail.setPickTicket(pickTicket);
|
||||||
pickDetail.setDept(UserUtils.getDept());
|
pickDetail.setDept(UserUtils.getDept());
|
||||||
pickDetail.setStatus(BizStatus.OPEN);
|
pickDetail.setStatus(BizStatus.OPEN);
|
||||||
|
|
@ -316,7 +391,7 @@ public class ImportDataServiceImpl implements ImportDataService {
|
||||||
pickDetail.setArea(pickTicket.getArea());
|
pickDetail.setArea(pickTicket.getArea());
|
||||||
pickDetail.setOrderQty(Double.parseDouble(qty));
|
pickDetail.setOrderQty(Double.parseDouble(qty));
|
||||||
pickDetailService.create(pickDetail);
|
pickDetailService.create(pickDetail);
|
||||||
pickTicket.setOrderQuantity(pickTicket.getOrderQuantity()+pickDetail.getOrderQty());
|
pickTicket.setOrderQuantity(pickTicket.getOrderQuantity() + pickDetail.getOrderQty());
|
||||||
pickTicketService.update(pickTicket);
|
pickTicketService.update(pickTicket);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,16 +29,14 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import org.springframework.data.domain.Example;
|
import org.springframework.data.domain.Example;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @website https://eladmin.vip
|
* @website https://eladmin.vip
|
||||||
|
|
@ -138,4 +136,14 @@ public class ItemServiceImpl implements ItemService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Item> findByCodes(Set itemCodes) {
|
||||||
|
List<Item> items = itemRepository.findByCodes(itemCodes);
|
||||||
|
Map<String, Item> itemMap = new HashMap<>();
|
||||||
|
for (Item item : items) {
|
||||||
|
itemMap.put(item.getCode(), item);
|
||||||
|
}
|
||||||
|
return itemMap;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.youchain.utils;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class BatchCreateOrUpdate {
|
||||||
|
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
private int batchSize=500;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量插入
|
||||||
|
*
|
||||||
|
* @param list 实体类集合
|
||||||
|
* @param <T> 表对应的实体类
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public <T> void batchInsert(List<T> list) {
|
||||||
|
if (list == null || list.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
entityManager.persist(list.get(i));
|
||||||
|
if (i % batchSize == 0) {
|
||||||
|
entityManager.flush();
|
||||||
|
entityManager.clear();
|
||||||
|
}
|
||||||
|
entityManager.flush();
|
||||||
|
entityManager.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新
|
||||||
|
*
|
||||||
|
* @param list 实体类集合
|
||||||
|
* @param <T> 表对应的实体类
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public <T> void batchUpdate(List<T> list) {
|
||||||
|
if (list == null || list.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
entityManager.merge(list.get(i));
|
||||||
|
if (i % batchSize == 0) {
|
||||||
|
entityManager.flush();
|
||||||
|
entityManager.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entityManager.flush();
|
||||||
|
entityManager.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue