物料导入
parent
2441611940
commit
d36ab45654
|
|
@ -107,11 +107,8 @@ public class ImportDataController {
|
|||
@Log("导入部品品番")
|
||||
@ApiOperation("导入部品品番")
|
||||
@PostMapping(value = "/item")
|
||||
@Transactional
|
||||
@AnonymousAccess
|
||||
public ResponseEntity<Object> importItem( @RequestParam("file") MultipartFile multipartFile) {
|
||||
|
||||
//编码、名称、物料类型
|
||||
try {
|
||||
String result = importDataService.importItem(multipartFile);
|
||||
return new ResponseEntity(result, HttpStatus.OK);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import com.youchain.businessdata.domain.PickDetail;
|
|||
import com.youchain.businessdata.domain.PickTicket;
|
||||
import com.youchain.businessdata.service.*;
|
||||
import com.youchain.config.FileProperties;
|
||||
import com.youchain.config.thread.ThreadPoolExecutorUtil;
|
||||
import com.youchain.exception.BadRequestException;
|
||||
import com.youchain.modules.system.domain.Dept;
|
||||
import com.youchain.modules.system.domain.DictDetail;
|
||||
|
|
@ -51,6 +52,9 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
/**
|
||||
* @author HJL
|
||||
|
|
@ -179,8 +183,8 @@ public class ImportDataServiceImpl implements ImportDataService {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String importItem(MultipartFile multipartFile) {
|
||||
//编码、名称、物料类型
|
||||
FileUtil.checkSize(properties.getMaxSize(), multipartFile.getSize());
|
||||
String suffix = FileUtil.getExtensionName(multipartFile.getOriginalFilename());
|
||||
String type = FileUtil.getFileType(suffix);
|
||||
|
|
@ -201,7 +205,7 @@ public class ImportDataServiceImpl implements ImportDataService {
|
|||
Map<String, Item> existingPoint = itemService.findByCodes(itemCodes);
|
||||
|
||||
|
||||
List<Item> itemsToInsert= new ArrayList<>();//新增物料集合
|
||||
List<Item> itemsToInsert = new ArrayList<>();//新增物料集合
|
||||
List<Item> itemsToUpdate = new ArrayList<>();//修改物料集合
|
||||
for (Map<String, Object> record : readAll) {
|
||||
String itemCode = record.get("料号").toString().trim();
|
||||
|
|
@ -225,61 +229,61 @@ public class ImportDataServiceImpl implements ImportDataService {
|
|||
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());
|
||||
item.setName(Optional.ofNullable(record.get("物料描述")).map(Object::toString).map(String::trim).orElse(""));
|
||||
item.setPackageType(Optional.ofNullable(record.get("包装类型")).map(Object::toString).map(String::trim).orElse(""));
|
||||
item.setSpecQuantity(Optional.ofNullable(record.get("规格数量")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setSpecWeight(Optional.ofNullable(record.get("规格重量")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setGrossWeight(Optional.ofNullable(record.get("毛重")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setLength(Optional.ofNullable(record.get("长")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setWidth(Optional.ofNullable(record.get("宽")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setHeight(Optional.ofNullable(record.get("高")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setVolume(Optional.ofNullable(record.get("体积")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setUnit(Optional.ofNullable(record.get("单位")).map(Object::toString).map(String::trim).orElse(""));
|
||||
item.setType(Optional.ofNullable(record.get("类型")).map(Object::toString).map(String::trim).orElse(""));
|
||||
item.setValueGrade(Optional.ofNullable(record.get("物料价值等级")).map(Object::toString).map(String::trim).orElse(""));
|
||||
item.setValidPeriod(Optional.ofNullable(record.get("保质期天数")).map(Object::toString).map(Integer::parseInt).orElse(0));
|
||||
item.setAlertDays(Optional.ofNullable(record.get("预警天数")).map(Object::toString).map(Integer::parseInt).orElse(0));
|
||||
item.setIsBatch(Optional.ofNullable(record.get("是否批次")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false));
|
||||
item.setIsSerial(Optional.ofNullable(record.get("是否序列号")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false));
|
||||
item.setIsValidPeriod(Optional.ofNullable(record.get("是否有效期")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false));
|
||||
item.setIsHazardous(Optional.ofNullable(record.get("是否危化品")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false));
|
||||
item.setIsInvAvailable(Optional.ofNullable(record.get("是否有库存")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false));
|
||||
item.setIsSapMaterial(Optional.ofNullable(record.get("是否SAP料号")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false));
|
||||
item.setHeatValue(Optional.ofNullable(record.get("热度值")).map(Object::toString).map(Integer::parseInt).orElse(0));
|
||||
item.setDescription(Optional.ofNullable(record.get("备注")).map(Object::toString).map(String::trim).orElse(""));
|
||||
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.setCode(Optional.ofNullable(record.get("料号")).map(Object::toString).map(String::trim).orElse(""));
|
||||
item.setName(Optional.ofNullable(record.get("物料描述")).map(Object::toString).map(String::trim).orElse(""));
|
||||
item.setPackageType(Optional.ofNullable(record.get("包装类型")).map(Object::toString).map(String::trim).orElse(""));
|
||||
item.setSpecQuantity(Optional.ofNullable(record.get("规格数量")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setSpecWeight(Optional.ofNullable(record.get("规格重量")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setGrossWeight(Optional.ofNullable(record.get("毛重")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setLength(Optional.ofNullable(record.get("长")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setWidth(Optional.ofNullable(record.get("宽")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setHeight(Optional.ofNullable(record.get("高")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setVolume(Optional.ofNullable(record.get("体积")).map(Object::toString).map(Double::parseDouble).orElse(0D));
|
||||
item.setUnit(Optional.ofNullable(record.get("单位")).map(Object::toString).map(String::trim).orElse(""));
|
||||
item.setType(Optional.ofNullable(record.get("类型")).map(Object::toString).map(String::trim).orElse(""));
|
||||
item.setValueGrade(Optional.ofNullable(record.get("物料价值等级")).map(Object::toString).map(String::trim).orElse(""));
|
||||
item.setValidPeriod(Optional.ofNullable(record.get("保质期天数")).map(Object::toString).map(Integer::parseInt).orElse(0));
|
||||
item.setAlertDays(Optional.ofNullable(record.get("预警天数")).map(Object::toString).map(Integer::parseInt).orElse(0));
|
||||
item.setIsBatch(Optional.ofNullable(record.get("是否批次")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false));
|
||||
item.setIsSerial(Optional.ofNullable(record.get("是否序列号")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false));
|
||||
item.setIsValidPeriod(Optional.ofNullable(record.get("是否有效期")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false));
|
||||
item.setIsHazardous(Optional.ofNullable(record.get("是否危化品")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false));
|
||||
item.setIsInvAvailable(Optional.ofNullable(record.get("是否有库存")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false));
|
||||
item.setIsSapMaterial(Optional.ofNullable(record.get("是否SAP料号")).map(Object::toString).map(String::trim).map("是"::equals).orElse(false));
|
||||
item.setHeatValue(Optional.ofNullable(record.get("热度值")).map(Object::toString).map(Integer::parseInt).orElse(0));
|
||||
item.setDescription(Optional.ofNullable(record.get("备注")).map(Object::toString).map(String::trim).orElse(""));
|
||||
item.setDept(dept);
|
||||
item.setEnabled(true);
|
||||
return item;
|
||||
|
|
|
|||
Loading…
Reference in New Issue