提交 e341389e 作者: 李超杰

辅材发货单导入

父级 976a708b
package com.starcharge.wios.Import.impl;
import com.starcharge.wios.Import.Import;
import com.starcharge.wios.dao.entity.Order;
import com.starcharge.wios.dao.entity.Tauxiliarymaterials;
import com.starcharge.wios.dao.mappers.OrderMapper;
import com.starcharge.wios.dao.mappers.TauxiliarymaterialsMapper;
import com.starcharge.wios.enums2.ProductType;
import com.starcharge.wios.enums2.TauxiliarymaterialStatusEnum;
import com.starcharge.wios.validation.CreateEntityGroup;
import com.starcharge.wios.vo.DeliveryAddVo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -42,55 +39,42 @@ public class AuxiliaryMaterialDeliveryImport implements Import {
@Override
public List<?> handle(List<Object> list) {
// List<String> headList = (List<String>)list.get(0);
for(int i=1;i<list.size();i++){
List<String> rowdata = (List<String>)list.get(i);
DeliveryAddVo deliveryAddVo=new DeliveryAddVo();
for (int i = 1; i < list.size(); i++) {
StringBuilder error = new StringBuilder();
List<String> rowdata = (List<String>) list.get(i);
DeliveryAddVo deliveryAddVo = new DeliveryAddVo();
deliveryAddVo.setInstallOrder(rowdata.get(0));
deliveryAddVo.setLogisticOrder(rowdata.get(1));
try {
deliveryAddVo.setQuantity(Integer.parseInt(rowdata.get(2)));
}catch (Exception e){
rowdata.add("error:发货数量必填且为整数");
} catch (Exception e) {
error.append("error:发货数量必填且为整数");
}
// deliveryAddVo.setMaterialCode(rowdata.get(1));
// deliveryAddVo.setMaterialName(rowdata.get(2));
// deliveryAddVo.setMaterialCompany(rowdata.get(3));
// deliveryAddVo.setLogisticOrder(rowdata.get(4));
// deliveryAddVo.setTeam(rowdata.get(5));
Set<ConstraintViolation<DeliveryAddVo>> sets = validator.validate(deliveryAddVo, AuxiliaryMaterialDeliveryImport.AuxiliaryBatchCreateEntityGroup.class);
if(!sets.isEmpty()){
rowdata.add(sets.stream().map(ConstraintViolation::getMessage).reduce("error:",(s1,s2)->s1+";"+s2));
continue;
Set<ConstraintViolation<DeliveryAddVo>> sets = validator.validate(deliveryAddVo, AuxiliaryMaterialDeliveryImport.AuxiliaryBatchCreateEntityGroup.class);
if (!sets.isEmpty()) {
error.append(sets.stream().map(ConstraintViolation::getMessage).reduce("error:", (s1, s2) -> s1 + ";" + s2));
}
Tauxiliarymaterials tauxiliarymaterialsquery=new Tauxiliarymaterials();
Tauxiliarymaterials tauxiliarymaterialsquery = new Tauxiliarymaterials();
tauxiliarymaterialsquery.setApplyOrder(deliveryAddVo.getInstallOrder());
tauxiliarymaterialsquery.setApplyStatus(TauxiliarymaterialStatusEnum.已通过.name());
List<Tauxiliarymaterials> tauxiliarymaterials=this.tauxiliarymaterialsMapper.selectTAuxiliaryMaterialsList(tauxiliarymaterialsquery);
if(CollectionUtils.isEmpty(tauxiliarymaterials)){
rowdata.add("error:找不到已审批通过辅材申请单");
continue;
}
Tauxiliarymaterials tauxiliarymaterial= tauxiliarymaterials.stream().filter(t->TauxiliarymaterialStatusEnum.未发货.name().equals(t.getLogisticStatus())).findFirst().orElse(null);
if(tauxiliarymaterial==null){
rowdata.add("");
rowdata.add("");
rowdata.add("");
rowdata.add("error:找不到已审批且未发货的辅材申请单");
}else{
rowdata.add(tauxiliarymaterial.getMaterialCode());
rowdata.add(tauxiliarymaterial.getMaterialName());
rowdata.add(tauxiliarymaterial.getApprovedQuantity());
if(!StringUtils.hasLength(tauxiliarymaterial.getApprovedQuantity())){
tauxiliarymaterial.setApprovedQuantity("0");
}
if(deliveryAddVo.getQuantity()>Float.parseFloat(tauxiliarymaterial.getApprovedQuantity())){
rowdata.add("error:发货数量大于已审批数量");
List<Tauxiliarymaterials> tauxiliarymaterials = this.tauxiliarymaterialsMapper.selectTAuxiliaryMaterialsList(tauxiliarymaterialsquery);
if (CollectionUtils.isEmpty(tauxiliarymaterials)) {
error.append("error:找不到已审批通过辅材申请单");
} else {
Tauxiliarymaterials tauxiliarymaterial = tauxiliarymaterials.stream().filter(t -> TauxiliarymaterialStatusEnum.未发货.name().equals(t.getLogisticStatus())).findFirst().orElse(null);
if (tauxiliarymaterial == null) {
error.append("error:找不到已审批且未发货的辅材申请单");
} else {
if (!StringUtils.hasLength(tauxiliarymaterial.getApprovedQuantity())) {
tauxiliarymaterial.setApprovedQuantity("0");
}
if (deliveryAddVo.getQuantity() > Integer.parseInt(tauxiliarymaterial.getApprovedQuantity())) {
error.append("error:发货数量大于已审批数量");
}
}
}
rowdata.add(error.toString());
}
return list;
}
......
......@@ -27,42 +27,45 @@ public class AuxiliarymaterialsCheckImport implements Import {
public List<?> handle(List<Object> list) {
for (int i = 1; i < list.size(); i++) {
List<String> rowdata = (List<String>) list.get(i);
StringBuilder error = new StringBuilder();
if (rowdata.size() < 2 || StringUtils.isEmpty(rowdata.get(1))) {
rowdata.add("error:批准数量不能为空");
continue;
error.append("error:批准数量不能为空");
}
try {
Float.parseFloat(rowdata.get(1));
} catch (Exception e) {
rowdata.add("error:批准数量必须是数字");
continue;
error.append("error:批准数量必须是数字");
rowdata.add(5, error.toString());
}
String s = rowdata.get(1);
rowdata.remove(1);
if (StringUtils.isEmpty(rowdata.get(0))) {
rowdata.add("error:申请单号不能为空");
continue;
error.append("error:申请单号不能为空");
rowdata.add(5, error.toString());
}
String materialCode = null;
String materialName = null;
String applyQuantity = null;
Tauxiliarymaterials exist = this.tauxiliarymaterialsMapper.selectByApplyOrder(rowdata.get(0));
if (Objects.isNull(exist)) {
rowdata.add("error:找不到辅材申请单");
continue;
}
TauxiliarymaterialStatusEnum enumByName = TauxiliarymaterialStatusEnum.getEnumByName(0, exist.getApplyStatus());
if (Objects.nonNull(enumByName) && enumByName.getValue() != 1) {
rowdata.add("error:辅材申请单:" + exist.getApplyOrder() + " 状态必须是已申请");
continue;
error.append("error:找不到辅材申请单");
} else {
materialCode = exist.getMaterialCode();
materialName = exist.getMaterialName();
applyQuantity = exist.getApplyQuantity();
TauxiliarymaterialStatusEnum enumByName = TauxiliarymaterialStatusEnum.getEnumByName(0, exist.getApplyStatus());
if (Objects.nonNull(enumByName) && enumByName.getValue() != 1) {
error.append("error:辅材申请单:").append(exist.getApplyOrder()).append(" 状态必须是已申请");
}
if (Integer.parseInt(s) > Integer.parseInt(exist.getApplyQuantity())) {
error.append("error:批准数量不能大于申请数量");
}
}
if (Integer.parseInt(s) > Integer.parseInt(exist.getApplyQuantity())) {
rowdata.add("error:批准数量不能大于申请数量");
continue;
}
rowdata.add(exist.getMaterialCode());
rowdata.add(exist.getMaterialName());
rowdata.add(exist.getApplyQuantity());
rowdata.add(materialCode);
rowdata.add(materialName);
rowdata.add(applyQuantity);
rowdata.add(s);
rowdata.add(error.toString());
}
return list;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论