Merge branch 'master' into order

This commit is contained in:
gaowdong 2025-05-30 13:50:57 +08:00
commit d9c05e4569
5 changed files with 310 additions and 205 deletions

View File

@ -109,10 +109,14 @@ public class CookDishesController extends BaseController {
} }
@PostMapping({"/import/dishes"}) @PostMapping({"/upload/importDishes"})
@ApiOperation("导入成功的菜品信息") @ApiOperation("导入成功的菜品信息")
@Transactional(rollbackFor = Exception.class)
public AjaxResult importDishes(@RequestBody List<MenuDishesImportDTO> request) { public AjaxResult importDishes(@RequestBody List<MenuDishesImportDTO> request) {
return AjaxResult.success(this.cookDishesService.newImportDishes(request)); try {
this.cookDishesService.newImportDishes(request);
}catch (Exception e){
return AjaxResult.error(e.getMessage());
}
return AjaxResult.success();
} }
} }

View File

@ -37,11 +37,11 @@ public class MenuDishesImportDTO implements Serializable {
@ExcelProperty( @ExcelProperty(
index = 5 index = 5
) )
private Double specificationOfWeighing; private BigDecimal specificationOfWeighing;
@ExcelProperty( @ExcelProperty(
index = 6 index = 6
) )
private Double weight; private BigDecimal weight;
@ExcelProperty( @ExcelProperty(
index = 7 index = 7
) )
@ -56,20 +56,28 @@ public class MenuDishesImportDTO implements Serializable {
private String stallName; private String stallName;
@ExcelIgnore @ExcelIgnore
private String failReason; private String failReason;
@ExcelIgnore
private String areaId;
@ExcelIgnore
private String canteenId;
@ExcelIgnore
private String stallId;
@ExcelIgnore
private String typeId;
public BigDecimal getPrice() { public BigDecimal getPrice() {
return ObjectUtil.isNull(this.price) ? BigDecimal.ZERO : this.price.setScale(2, RoundingMode.HALF_UP); return ObjectUtil.isNull(this.price) ? BigDecimal.ZERO : this.price.multiply(BigDecimal.valueOf(100)).setScale(0, RoundingMode.DOWN);
} }
public Integer getSalesMode() { public Integer getSalesMode() {
return ObjectUtil.isNull(this.salesMode) ? 1 : this.salesMode; return ObjectUtil.isNull(this.salesMode) ? 1 : this.salesMode;
} }
public Double getSpecificationOfWeighing() { public BigDecimal getSpecificationOfWeighing() {
return specificationOfWeighing; return ObjectUtil.isNull(this.price) ? BigDecimal.ZERO : this.price.multiply(BigDecimal.valueOf(100)).setScale(0, RoundingMode.DOWN);
} }
public void setSpecificationOfWeighing(Double specificationOfWeighing) { public void setSpecificationOfWeighing(BigDecimal specificationOfWeighing) {
this.specificationOfWeighing = specificationOfWeighing; this.specificationOfWeighing = specificationOfWeighing;
} }
@ -86,8 +94,8 @@ public class MenuDishesImportDTO implements Serializable {
return this.materialNames; return this.materialNames;
} }
public Double getWeight() { public BigDecimal getWeight() {
return this.weight; return ObjectUtil.isNull(this.weight) ? BigDecimal.ZERO : this.weight.setScale(0, RoundingMode.DOWN);
} }
public String getAreaName() { public String getAreaName() {
@ -126,7 +134,7 @@ public class MenuDishesImportDTO implements Serializable {
this.salesMode = salesMode; this.salesMode = salesMode;
} }
public void setWeight(final Double weight) { public void setWeight(final BigDecimal weight) {
this.weight = weight; this.weight = weight;
} }
@ -145,4 +153,57 @@ public class MenuDishesImportDTO implements Serializable {
public void setFailReason(final String failReason) { public void setFailReason(final String failReason) {
this.failReason = failReason; this.failReason = failReason;
} }
public String getAreaId() {
return areaId;
}
public void setAreaId(String areaId) {
this.areaId = areaId;
}
public String getCanteenId() {
return canteenId;
}
public void setCanteenId(String canteenId) {
this.canteenId = canteenId;
}
public String getStallId() {
return stallId;
}
public void setStallId(String stallId) {
this.stallId = stallId;
}
public String getTypeId() {
return typeId;
}
public void setTypeId(String typeId) {
this.typeId = typeId;
}
@Override
public String toString() {
return "MenuDishesImportDTO{" +
"dishesName='" + dishesName + '\'' +
", price=" + price +
", dishesTypeName='" + dishesTypeName + '\'' +
", materialNames='" + materialNames + '\'' +
", salesMode=" + salesMode +
", specificationOfWeighing=" + specificationOfWeighing +
", weight=" + weight +
", areaName='" + areaName + '\'' +
", canteenName='" + canteenName + '\'' +
", stallName='" + stallName + '\'' +
", failReason='" + failReason + '\'' +
", areaId='" + areaId + '\'' +
", canteenId='" + canteenId + '\'' +
", stallId='" + stallId + '\'' +
", typeId='" + typeId + '\'' +
'}';
}
} }

View File

@ -28,6 +28,8 @@ import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.utils.StringUtils; import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.security.utils.SecurityUtils; import com.bonus.common.security.utils.SecurityUtils;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.sun.org.slf4j.internal.Logger;
import com.sun.org.slf4j.internal.LoggerFactory;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@ -48,6 +50,8 @@ import javax.annotation.Resource;
*/ */
@Service @Service
public class CookDishesServiceImpl implements ICookDishesService { public class CookDishesServiceImpl implements ICookDishesService {
private static final Logger log = LoggerFactory.getLogger(CookDishesServiceImpl.class);
@Autowired @Autowired
private CookDishesMapper cookDishesMapper; private CookDishesMapper cookDishesMapper;
@Autowired @Autowired
@ -107,7 +111,7 @@ public class CookDishesServiceImpl implements ICookDishesService {
} }
return 1; return 1;
} catch (Exception e) { } catch (Exception e) {
throw new ServiceException(e.getMessage()); throw new ServiceException("操作失败: " + e.getMessage());
} }
} }
@ -145,21 +149,24 @@ public class CookDishesServiceImpl implements ICookDishesService {
if (cookDishes.getDishesId() == null && isUpdate) { if (cookDishes.getDishesId() == null && isUpdate) {
throw new ServiceException("菜品ID不能为空"); throw new ServiceException("菜品ID不能为空");
} }
if (StringUtils.isNull(cookDishes.getAreaId()) || cookDishes.getAreaId() == 0) { // if (StringUtils.isNull(cookDishes.getAreaId()) || cookDishes.getAreaId() == 0) {
throw new ServiceException("区域不能为空"); // throw new ServiceException("区域不能为空");
} // }
if (StringUtils.isNull(cookDishes.getCanteenId()) || cookDishes.getCanteenId() == 0) { // if (StringUtils.isNull(cookDishes.getCanteenId()) || cookDishes.getCanteenId() == 0) {
throw new ServiceException("食堂不能为空"); // throw new ServiceException("食堂不能为空");
} // }
if (StringUtils.isNull(cookDishes.getStallId()) || cookDishes.getStallId() == 0) { // if (StringUtils.isNull(cookDishes.getStallId()) || cookDishes.getStallId() == 0) {
throw new ServiceException("档口不能为空"); // throw new ServiceException("档口不能为空");
} // }
if (StringUtils.isNull(cookDishes.getTypeId()) || cookDishes.getTypeId() == 0) { if (StringUtils.isNull(cookDishes.getTypeId()) || cookDishes.getTypeId() == 0) {
throw new ServiceException("菜品分类不能为空"); throw new ServiceException("菜品分类不能为空");
} }
if (StringUtils.isNull(cookDishes.getPrice()) || cookDishes.getPrice() == 0) { if (StringUtils.isNull(cookDishes.getPrice()) || cookDishes.getPrice() == 0) {
throw new ServiceException("菜品价格不能为空"); throw new ServiceException("菜品价格不能为空");
} }
if (StringUtils.isNull(cookDishes.getWeight()) || cookDishes.getWeight().compareTo(BigDecimal.ZERO) < 0) {
throw new ServiceException("菜品份量不能为空或者小于0");
}
if (cookDishesMapper.checkDishIsExist(cookDishes) > 0) { if (cookDishesMapper.checkDishIsExist(cookDishes) > 0) {
throw new ServiceException("菜品名称已存在"); throw new ServiceException("菜品名称已存在");
} }
@ -200,7 +207,7 @@ public class CookDishesServiceImpl implements ICookDishesService {
for (CookDishesMaterial i : dishesMaterialList) { for (CookDishesMaterial i : dishesMaterialList) {
NutritionEntity nutritionEntity = cookNutritionMapper.getNutritionEntity(i); NutritionEntity nutritionEntity = cookNutritionMapper.getNutritionEntity(i);
if (nutritionEntity != null) { if (nutritionEntity != null) {
System.err.println(i.getMaterialId() + ",开始值:" + nutritionEntity.getCalcium()); log.debug("原料ID: {}, 初始钙含量: {}", i.getMaterialId(), nutritionEntity.getCalcium());
nutritionEntity.setWeight(Double.valueOf(i.getWeight() + "")); nutritionEntity.setWeight(Double.valueOf(i.getWeight() + ""));
nutritionEntity.setBaseWeight(100.0); nutritionEntity.setBaseWeight(100.0);
nutritionEntityList.add(nutritionEntity); nutritionEntityList.add(nutritionEntity);
@ -208,10 +215,12 @@ public class CookDishesServiceImpl implements ICookDishesService {
} }
NutritionEntity nutritionEntity = NutritionEntityUtil.countNutrition(nutritionEntityList); NutritionEntity nutritionEntity = NutritionEntityUtil.countNutrition(nutritionEntityList);
if (!nutritionEntityList.isEmpty()) { if (!nutritionEntityList.isEmpty()) {
log.debug("总和: {}", nutritionEntity.getCalcium());
System.err.println("总和:" + nutritionEntity.getCalcium()); System.err.println("总和:" + nutritionEntity.getCalcium());
//计算营养成分 //计算营养成分
countNum(nutritionEntity, Double.valueOf(cookDishes.getWeight() + "")); countNum(nutritionEntity, Double.valueOf(cookDishes.getWeight() + ""));
System.err.println("计算后:" + nutritionEntity.getCalcium()); System.err.println("计算后:" + nutritionEntity.getCalcium());
log.debug("计算后: {}", nutritionEntity.getCalcium());
cookDishesMapper.updateFinalNutrition(nutritionEntity, cookDishes.getDishesId()); cookDishesMapper.updateFinalNutrition(nutritionEntity, cookDishes.getDishesId());
} }
} }
@ -223,11 +232,11 @@ public class CookDishesServiceImpl implements ICookDishesService {
try { try {
Double value = (Double) field.get(nutritionEntity); Double value = (Double) field.get(nutritionEntity);
if (value != null) { if (value != null) {
System.err.println("先前值----" + value); log.debug("先前值----{}", value);
double proportion = Arith.div(weight, 100); double proportion = Arith.div(weight, 100);
value = Arith.mul(value, proportion); value = Arith.mul(value, proportion);
field.set(nutritionEntity, value); field.set(nutritionEntity, value);
System.err.println("后来值++++" + value); log.debug("后来值++++{}", value);
} else { } else {
field.set(nutritionEntity, 0.00); field.set(nutritionEntity, 0.00);
} }
@ -249,178 +258,157 @@ public class CookDishesServiceImpl implements ICookDishesService {
} }
if (CollectionUtils.isEmpty(menuDishesImportDTOS)) { if (CollectionUtils.isEmpty(menuDishesImportDTOS)) {
throw new ServiceException("导入新增菜品为空"); throw new ServiceException("导入新增菜品为空");
} else { }
List<String> sqlDishesNameList = this.cookDishesMapper.selectDishesNameAndCanteenName(); // 初始化上下文
ImportDishesContext importDishesContext = this.getImportDishesContext(null); List<String> sqlDishesNameList = cookDishesMapper.selectDishesNameAndCanteenName();
Map<String, Long> areaMap = importDishesContext.getAreaMap(); ImportDishesContext context = getImportDishesContext(null);
Map<String, Long> typeMap = importDishesContext.getTypeMap(); Map<String, Long> areaMap = context.getAreaMap();
Map<String, AllocStall> allocStallMap = importDishesContext.getAllocStallMap(); Map<String, Long> typeMap = context.getTypeMap();
Map<String, AllocCanteen> allocCanteenMap = importDishesContext.getAllocCanteenMap(); Map<String, AllocStall> stallMap = context.getAllocStallMap();
Map<Long, AllocArea> allocAreaIdMap = importDishesContext.getAllocAreaIdMap(); Map<String, AllocCanteen> canteenMap = context.getAllocCanteenMap();
Map<Long, AllocCanteen> allocCanteenIdMap = importDishesContext.getAllocCanteenIdMap(); Map<Long, AllocArea> areaIdMap = context.getAllocAreaIdMap();
Map<String, Long> materialMap = importDishesContext.getMaterialMap(); Map<Long, AllocCanteen> canteenIdMap = context.getAllocCanteenIdMap();
List<Integer> salesModeKeyList = Arrays.stream(MenuSalesTypeEnum.values()).map(MenuSalesTypeEnum::key).collect(Collectors.toList()); Map<String, Long> materialMap = context.getMaterialMap();
List<String> menuMaterialTypeList = Arrays.stream(MenuMaterialTypeEnum.values()).map(MenuMaterialTypeEnum::key).map(Object::toString).collect(Collectors.toList()); List<Integer> salesModeKeys = Arrays.stream(MenuSalesTypeEnum.values()).map(MenuSalesTypeEnum::key).collect(Collectors.toList());
List<String> dishesNameList = Lists.newArrayList(); List<String> materialTypeKeys = Arrays.stream(MenuMaterialTypeEnum.values()).map(MenuMaterialTypeEnum::key).map(Object::toString).collect(Collectors.toList());
List<String> dishesNameList = new ArrayList<>();
List<MenuDishesImportDTO> successList = new ArrayList<>(); List<MenuDishesImportDTO> successList = new ArrayList<>();
List<MenuDishesImportDTO> errorList = new ArrayList<>(); List<MenuDishesImportDTO> errorList = new ArrayList<>();
for (MenuDishesImportDTO data : menuDishesImportDTOS) { for (MenuDishesImportDTO data : menuDishesImportDTOS) {
try { try {
BigDecimal price = data.getPrice(); // 校验数据
if (BigDecimal.ZERO.compareTo(price) > 0) { if (!validateData(data, sqlDishesNameList, dishesNameList, context, salesModeKeys, materialTypeKeys)) {
data.setFailReason("菜品价格为负数");
errorList.add(data);
} else {
Integer salesMode = data.getSalesMode();
if (!salesModeKeyList.contains(salesMode)) {
data.setFailReason("计价方式只能填写1或者2");
errorList.add(data);
} else {
String dishesTypeName = data.getDishesTypeName();
if (CharSequenceUtil.isNotBlank(dishesTypeName) && typeMap.get(dishesTypeName) == null) {
data.setFailReason(dishesTypeName + "菜品类别不存在");
errorList.add(data);
} else {
String dishesName = data.getDishesName();
String canteenName = data.getCanteenName();
String stallName = data.getStallName();
String areaName = data.getAreaName();
String itemDishesName = Stream.of(data.getDishesName(), areaName, canteenName, stallName).map((x) -> CharSequenceUtil.isBlank(x) ? "*" : x).collect(Collectors.joining("-"));
if (CharSequenceUtil.isBlank(dishesName)) {
data.setFailReason("菜品名称为空");
errorList.add(data);
} else if (dishesNameList.contains(itemDishesName)) {
data.setFailReason("菜品名称重复");
errorList.add(data);
} else if (CollUtil.isNotEmpty(sqlDishesNameList) && sqlDishesNameList.contains(itemDishesName)) {
data.setFailReason("菜品名称数据库已存在");
errorList.add(data);
} else {
String menuMaterialNames = data.getMaterialNames();
BigDecimal totalWeight = BigDecimal.ZERO;
if (CharSequenceUtil.isNotBlank(menuMaterialNames)) {
String[] materialList = menuMaterialNames.replace("", ";").split(";");
String[] var33 = materialList;
int var34 = materialList.length;
for (int var35 = 0; var35 < var34; ++var35) {
String material = var33[var35];
String[] materialSplit = material.split("&");
if (materialSplit.length != 3) {
data.setFailReason(material + "原料格式不正确");
errorList.add(data);
break;
}
String materialName = materialSplit[0];
String materialType = materialSplit[1];
String materialWeight = materialSplit[2];
if (materialMap.get(materialName) == null) {
data.setFailReason(materialName + "原料不存在");
errorList.add(data);
break;
}
if (!menuMaterialTypeList.contains(materialType)) {
data.setFailReason(materialType + "原料类型填写错误");
errorList.add(data);
break;
}
if (!NumberUtil.isNumber(materialWeight)) {
data.setFailReason(materialWeight + "原料重量不是数字");
errorList.add(data);
break;
}
BigDecimal weight = new BigDecimal(materialWeight);
totalWeight = totalWeight.add(weight);
if (BigDecimal.ZERO.compareTo(weight) > 0) {
data.setFailReason(materialWeight + "原料重量为负数");
errorList.add(data);
}
}
if (ObjectUtil.isNotEmpty(data.getFailReason())) {
continue;
}
}
Long areaId;
if (ObjectUtil.isNotEmpty(stallName)) {
AllocStall allocStall = allocStallMap.get(stallName);
if (allocStall == null) {
data.setFailReason("档口名称不存在");
errorList.add(data); errorList.add(data);
continue; continue;
} }
if (ObjectUtil.isEmpty(canteenName)) { // 校验区域食堂档口
data.setFailReason("食堂名称不能为空"); if (!validateLocation(data, areaMap, stallMap, canteenMap, areaIdMap, canteenIdMap)) {
errorList.add(data); errorList.add(data);
continue; continue;
} }
areaId = allocStall.getCanteenId(); // 校验通过
AllocCanteen allocCanteen = allocCanteenIdMap.get(areaId); dishesNameList.add(generateUniqueName(data));
if (!allocCanteen.getCanteenName().equals(canteenName)) {
data.setFailReason("食堂:" + canteenName + "填写错误");
errorList.add(data);
continue;
}
}
Double weight = data.getSpecificationOfWeighing();
if (ObjectUtil.isNotEmpty(weight) && weight != 50 && weight != 100) {
data.setFailReason("规格称重填写错误");
errorList.add(data);
continue;
}
if (ObjectUtil.isNotEmpty(canteenName)) {
AllocCanteen allocCanteen = allocCanteenMap.get(canteenName);
if (allocCanteen == null) {
data.setFailReason("食堂名称不存在");
errorList.add(data);
continue;
}
if (ObjectUtil.isEmpty(areaName)) {
data.setFailReason("区域名称不能为空");
errorList.add(data);
continue;
}
areaId = allocCanteen.getAreaId();
AllocArea allocArea = allocAreaIdMap.get(areaId);
if (!allocArea.getAreaName().equals(areaName)) {
data.setFailReason("区域:" + allocArea.getAreaName() + "填写错误");
errorList.add(data);
continue;
}
}
if (ObjectUtil.isNotEmpty(areaName) && !areaMap.containsKey(areaName)) {
data.setFailReason("区域名称不存在");
errorList.add(data);
} else {
dishesNameList.add(itemDishesName);
successList.add(data); successList.add(data);
} } catch (Exception e) {
data.setFailReason("未知错误: " + e.getMessage());
}
}
}
}
} catch (Exception var43) {
data.setFailReason(var43.getMessage());
errorList.add(data); errorList.add(data);
} }
} }
dishesImportCheckResult.setErrorList(errorList); dishesImportCheckResult.setErrorList(errorList);
dishesImportCheckResult.setSuccessList(successList); dishesImportCheckResult.setSuccessList(successList);
return dishesImportCheckResult; return dishesImportCheckResult;
} }
private boolean validateData(MenuDishesImportDTO data, List<String> sqlDishesNameList, List<String> dishesNameList,
ImportDishesContext context, List<Integer> salesModeKeys, List<String> materialTypeKeys) {
// 校验价格
if (data.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
data.setFailReason("菜品价格为负数");
return false;
}
// 校验计价方式
if (!salesModeKeys.contains(data.getSalesMode())) {
data.setFailReason("计价方式只能填写1或者2");
return false;
}
// 校验菜品类别
if (CharSequenceUtil.isNotBlank(data.getDishesTypeName()) && context.getTypeMap().get(data.getDishesTypeName()) == null) {
data.setFailReason(data.getDishesTypeName() + "菜品类别不存在");
return false;
}
data.setTypeId(String.valueOf(context.getTypeMap().get(data.getDishesTypeName())));
// 校验菜品名称
String uniqueName = generateUniqueName(data);
if (CharSequenceUtil.isBlank(data.getDishesName())) {
data.setFailReason("菜品名称为空");
return false;
}
if (dishesNameList.contains(uniqueName) || sqlDishesNameList.contains(uniqueName)) {
data.setFailReason("菜品名称重复或已存在");
return false;
}
// 校验规格称重
if (data.getSpecificationOfWeighing() != null &&
data.getSpecificationOfWeighing().compareTo(BigDecimal.valueOf(50)) != 0 &&
data.getSpecificationOfWeighing().compareTo(BigDecimal.valueOf(100)) != 0) {
data.setFailReason("规格称重填写错误");
return false;
}
// 校验原料
if (!validateMaterials(data, context.getMaterialMap(), materialTypeKeys)) {
return false;
}
return true;
}
private boolean validateMaterials(MenuDishesImportDTO data, Map<String, Long> materialMap, List<String> materialTypeKeys) {
if (CharSequenceUtil.isNotBlank(data.getMaterialNames())) {
String[] materials = data.getMaterialNames().replace("", ";").split(";");
for (String material : materials) {
String[] parts = material.split("&");
if (parts.length != 3 || materialMap.get(parts[0]) == null || !materialTypeKeys.contains(parts[1]) || !NumberUtil.isNumber(parts[2])) {
data.setFailReason("原料格式或数据错误: " + material);
return false;
}
if (new BigDecimal(parts[2]).compareTo(BigDecimal.ZERO) <= 0) {
data.setFailReason("原料重量为负数: " + parts[2]);
return false;
}
}
}
return true;
}
private boolean validateLocation(MenuDishesImportDTO data, Map<String, Long> areaMap, Map<String, AllocStall> stallMap,
Map<String, AllocCanteen> canteenMap, Map<Long, AllocArea> areaIdMap, Map<Long, AllocCanteen> canteenIdMap) {
// 校验档口
if (ObjectUtil.isNotEmpty(data.getStallName())) {
AllocStall stall = stallMap.get(data.getStallName());
if (stall == null || ObjectUtil.isEmpty(data.getCanteenName()) ||
!canteenIdMap.get(stall.getCanteenId()).getCanteenName().equals(data.getCanteenName())) {
data.setFailReason("档口或食堂名称错误");
return false;
}
data.setStallId(String.valueOf(stall.getStallId()));
}
// 校验食堂和区域
if (ObjectUtil.isNotEmpty(data.getCanteenName())) {
AllocCanteen canteen = canteenMap.get(data.getCanteenName());
if (canteen == null || ObjectUtil.isEmpty(data.getAreaName()) ||
!areaIdMap.get(canteen.getAreaId()).getAreaName().equals(data.getAreaName())) {
data.setFailReason("食堂或区域名称错误");
return false;
}
data.setCanteenId(String.valueOf(canteen.getCanteenId()));
data.setAreaId(String.valueOf(canteen.getAreaId()));
}
// 校验区域
if (ObjectUtil.isNotEmpty(data.getAreaName()) && !areaMap.containsKey(data.getAreaName())) {
data.setFailReason("区域名称不存在");
return false;
}
return true;
}
private String generateUniqueName(MenuDishesImportDTO data) {
return Stream.of(data.getDishesName(), data.getAreaName(), data.getCanteenName(), data.getStallName())
.map(x -> CharSequenceUtil.isBlank(x) ? "*" : x)
.collect(Collectors.joining("-"));
} }
public ImportDishesContext getImportDishesContext(String username) { public ImportDishesContext getImportDishesContext(String username) {
@ -485,19 +473,67 @@ public class CookDishesServiceImpl implements ICookDishesService {
} }
@Override @Override
public Boolean newImportDishes(List<MenuDishesImportDTO> menuDishesImportDTOS) { @Transactional(rollbackFor = Exception.class)
public Boolean newImportDishes(List<MenuDishesImportDTO> menuDishesImportDTO) {
try { try {
String currentTraceId = LogUtil.getCurrentTraceId(); String currentTraceId = LogUtil.getCurrentTraceId();
String username = SecurityUtils.getUsername(); String username = SecurityUtils.getUsername();
this.asyncTaskExecutor.execute(() -> { this.asyncTaskExecutor.execute(() -> {
LogUtil.putLogTraceId(currentTraceId); LogUtil.putLogTraceId(currentTraceId);
this.importDishesDTO(menuDishesImportDTO, username);
}); });
} catch (Exception var7) { } catch (Exception var7) {
throw new ServiceException("批量导入菜品发生错误"); throw new ServiceException("批量导入菜品发生错误");
} }
return true; return true;
// }
} }
private void importDishesDTO(List<MenuDishesImportDTO> menuDishesImportList, String username) {
// try {
// 重新组合数据
List<CookDishes> dishesList = new ArrayList<>();
ImportDishesContext importDishesContext = this.getImportDishesContext(null);
Map<String, Long> materialMap = importDishesContext.getMaterialMap();
for (MenuDishesImportDTO menuDishesImportDTO : menuDishesImportList) {
CookDishes dishes = new CookDishes();
dishes.setCanteenId(menuDishesImportDTO.getCanteenId() == null ? null : Long.valueOf(menuDishesImportDTO.getCanteenId()));
dishes.setStallId(menuDishesImportDTO.getStallId() == null ? null : Long.valueOf(menuDishesImportDTO.getStallId()));
dishes.setAreaId(menuDishesImportDTO.getAreaId() == null ? null : Long.valueOf(menuDishesImportDTO.getAreaId()));
dishes.setDishesName(menuDishesImportDTO.getDishesName());
dishes.setPrice(menuDishesImportDTO.getPrice() == null ? null : Long.valueOf(String.valueOf(menuDishesImportDTO.getPrice())));
dishes.setWeight(menuDishesImportDTO.getWeight() == null ? null : menuDishesImportDTO.getWeight());
dishes.setWeightDeviation(BigDecimal.ZERO);
dishes.setTypeId(menuDishesImportDTO.getTypeId() == null ? null : Long.valueOf(menuDishesImportDTO.getTypeId()));
dishes.setPungencyDegree(0L);
dishes.setRecommend("0");
dishes.setSalesMode(menuDishesImportDTO.getSalesMode() == null ? null : Long.valueOf(menuDishesImportDTO.getSalesMode()));
dishes.setUnitPrice(menuDishesImportDTO.getSpecificationOfWeighing() == null ? null : Long.valueOf(String.valueOf(menuDishesImportDTO.getSpecificationOfWeighing())));
String[] materialList = menuDishesImportDTO.getMaterialNames().replace("", ";").split(";");
List<CookDishesMaterial> dishesMaterialList = new ArrayList<>();
for (String material : materialList) {
String[] materialSplit = material.split("&");
if (materialSplit.length != 3) {
continue; // 跳过格式不正确的原料
}
CookDishesMaterial dishesMaterial = new CookDishesMaterial();
try {
dishesMaterial.setWeight(BigDecimal.valueOf(Double.parseDouble(materialSplit[2])));
} catch (NumberFormatException e) {
dishesMaterial.setWeight(BigDecimal.ZERO);
}
dishesMaterial.setMaterialName(materialSplit[0]);
try {
dishesMaterial.setMaterialType(Long.valueOf(materialSplit[1]));
} catch (NumberFormatException e) {
dishesMaterial.setMaterialType(0L);
}
dishesMaterial.setMaterialId(materialMap.getOrDefault(materialSplit[0], 0L));
dishesMaterialList.add(dishesMaterial);
}
dishes.setDishesMaterialList(dishesMaterialList);
dishesList.add(dishes);
}
dishesList.forEach(this::insertCookDishes);
}
} }

View File

@ -18,19 +18,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join account_card ac on ac.user_id = su.user_id left join account_card ac on ac.user_id = su.user_id
left join account_info ai on ai.user_id = su.user_id left join account_info ai on ai.user_id = su.user_id
where ai.del_flag = '0' where ai.del_flag = '0'
<if test="userId != null and userId != '' and userId != 0 and userId != '0'">
AND su.user_id = #{userId}
</if>
<if test="type == 'user'"> <if test="type == 'user'">
<if test="time != null and time != ''"> <if test="time != null and time != ''">
AND su.update_time >= #{time} - INTERVAL 5 SECOND; AND su.update_time >= (#{time} - INTERVAL 5 SECOND)
</if> </if>
</if> </if>
<if test="type == 'card'"> <if test="type == 'card'">
<if test="time != null and time != ''"> <if test="time != null and time != ''">
AND ac.update_time >= #{time} - INTERVAL 5 SECOND; AND ac.update_time >= (#{time} - INTERVAL 5 SECOND)
</if> </if>
</if> </if>
<if test="userId != null and userId != '' and userId != 0 and userId != '0'">
AND su.user_id = #{userId}
</if>
</select> </select>
<select id="getMoneyList" resultType="com.bonus.canteen.core.android.vo.UserInfoVo"> <select id="getMoneyList" resultType="com.bonus.canteen.core.android.vo.UserInfoVo">
SELECT SELECT

View File

@ -224,14 +224,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectCanteenList" resultType="com.bonus.canteen.core.cook.domain.AllocCanteen"> <select id="selectCanteenList" resultType="com.bonus.canteen.core.cook.domain.AllocCanteen">
select select
canteen_id as canteenId, canteen_id as canteenId,
canteen_name as canteenName canteen_name as canteenName,
area_id as areaId
from basic_canteen from basic_canteen
where del_flag = '0' where del_flag = '0'
</select> </select>
<select id="selectStallList" resultType="com.bonus.canteen.core.cook.domain.AllocStall"> <select id="selectStallList" resultType="com.bonus.canteen.core.cook.domain.AllocStall">
select select
stall_id as stallId, stall_id as stallId,
stall_name as stallName stall_name as stallName,
area_id as areaId,
canteen_id as canteenId
from basic_stall from basic_stall
where del_flag = '0' where del_flag = '0'
</select> </select>