菜谱管理
This commit is contained in:
parent
45bdb1d8c4
commit
b1cd6849e9
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.bonus.canteen.core.cook.dto.CookRecipeBindDTO;
|
import com.bonus.canteen.core.cook.dto.CookRecipeBindDTO;
|
||||||
import com.bonus.canteen.core.cook.dto.CookRecipeDTO;
|
import com.bonus.canteen.core.cook.dto.CookRecipeDTO;
|
||||||
import com.bonus.canteen.core.cook.dto.CookRecipeDetailDTO;
|
import com.bonus.canteen.core.cook.dto.CookRecipeDetailDTO;
|
||||||
|
|
@ -14,12 +15,8 @@ import com.bonus.common.log.enums.OperaType;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import com.bonus.common.log.annotation.SysLog;
|
import com.bonus.common.log.annotation.SysLog;
|
||||||
import com.bonus.canteen.core.cook.domain.CookRecipe;
|
import com.bonus.canteen.core.cook.domain.CookRecipe;
|
||||||
import com.bonus.canteen.core.cook.service.ICookRecipeService;
|
import com.bonus.canteen.core.cook.service.ICookRecipeService;
|
||||||
|
|
@ -27,6 +24,7 @@ import com.bonus.common.core.web.controller.BaseController;
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
import com.bonus.common.core.utils.poi.ExcelUtil;
|
import com.bonus.common.core.utils.poi.ExcelUtil;
|
||||||
import com.bonus.common.core.web.page.TableDataInfo;
|
import com.bonus.common.core.web.page.TableDataInfo;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜品计划信息Controller
|
* 菜品计划信息Controller
|
||||||
|
|
@ -148,6 +146,23 @@ public class CookRecipeController extends BaseController {
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping({"/recipe/import/dishes"})
|
||||||
|
@ApiOperation("批量导入菜谱中的菜品信息")
|
||||||
|
@Transactional
|
||||||
|
public AjaxResult recipeImportDishes(@RequestParam("file") MultipartFile excel, @RequestParam("recipeId") Long recipeId) {
|
||||||
|
try{
|
||||||
|
return ObjectUtil.isNull(excel) ? AjaxResult.error("请选择导入文件 ^_^") :
|
||||||
|
AjaxResult.success(this.cookRecipeService.recipeImportDishes(excel, recipeId));
|
||||||
|
}catch (Exception e){
|
||||||
|
String message = e.toString();
|
||||||
|
//取倒数第二个:之后的信息
|
||||||
|
String finalMessage = message.substring(message.lastIndexOf(":") - 7);
|
||||||
|
String errorMes = finalMessage.replace("Error:", "");
|
||||||
|
System.err.println("errorMes="+errorMes);
|
||||||
|
return error("导入失败:"+errorMes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除菜品计划信息
|
* 删除菜品计划信息
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
package com.bonus.canteen.core.cook.service;
|
package com.bonus.canteen.core.cook.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import com.bonus.canteen.core.cook.domain.CookRecipe;
|
import com.bonus.canteen.core.cook.domain.CookRecipe;
|
||||||
import com.bonus.canteen.core.cook.dto.CookRecipeBindDTO;
|
import com.bonus.canteen.core.cook.dto.CookRecipeBindDTO;
|
||||||
import com.bonus.canteen.core.cook.dto.CookRecipeDTO;
|
import com.bonus.canteen.core.cook.dto.CookRecipeDTO;
|
||||||
import com.bonus.canteen.core.cook.dto.CookRecipeDetailDTO;
|
import com.bonus.canteen.core.cook.dto.CookRecipeDetailDTO;
|
||||||
import com.bonus.canteen.core.cook.vo.CookRecipeDetailVO;
|
import com.bonus.canteen.core.cook.vo.CookRecipeDetailVO;
|
||||||
import com.bonus.canteen.core.cook.vo.CookRecipeVO;
|
import com.bonus.canteen.core.cook.vo.CookRecipeVO;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜品计划信息Service接口
|
* 菜品计划信息Service接口
|
||||||
|
|
@ -57,6 +60,8 @@ public interface ICookRecipeService {
|
||||||
|
|
||||||
public void bindCookRecipe(CookRecipeBindDTO cookRecipeDTO);
|
public void bindCookRecipe(CookRecipeBindDTO cookRecipeDTO);
|
||||||
|
|
||||||
|
public Set<String> recipeImportDishes(MultipartFile excel, Long recipeId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除菜品计划信息
|
* 批量删除菜品计划信息
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.alibaba.excel.EasyExcel;
|
||||||
|
import com.alibaba.excel.ExcelReader;
|
||||||
|
import com.alibaba.excel.read.metadata.ReadSheet;
|
||||||
|
import com.bonus.canteen.core.android.vo.CookMealtimeTypeEnum;
|
||||||
import com.bonus.canteen.core.common.utils.DateUtil;
|
import com.bonus.canteen.core.common.utils.DateUtil;
|
||||||
import com.bonus.canteen.core.common.utils.MqUtil;
|
import com.bonus.canteen.core.common.utils.MqUtil;
|
||||||
import com.bonus.canteen.core.cook.domain.CookAppRecipe;
|
import com.bonus.canteen.core.cook.domain.CookAppRecipe;
|
||||||
|
|
@ -21,6 +25,7 @@ import com.bonus.canteen.core.cook.enums.RecipeDetailTypeEnum;
|
||||||
import com.bonus.canteen.core.cook.enums.RecipeTypeEnum;
|
import com.bonus.canteen.core.cook.enums.RecipeTypeEnum;
|
||||||
import com.bonus.canteen.core.cook.mapper.CookRecipeDetailMapper;
|
import com.bonus.canteen.core.cook.mapper.CookRecipeDetailMapper;
|
||||||
import com.bonus.canteen.core.cook.mapper.CookRecipeDishesMapper;
|
import com.bonus.canteen.core.cook.mapper.CookRecipeDishesMapper;
|
||||||
|
import com.bonus.canteen.core.cook.utils.CookRecipeImportListener;
|
||||||
import com.bonus.canteen.core.cook.vo.*;
|
import com.bonus.canteen.core.cook.vo.*;
|
||||||
import com.bonus.common.core.exception.ServiceException;
|
import com.bonus.common.core.exception.ServiceException;
|
||||||
import com.bonus.common.core.utils.DateUtils;
|
import com.bonus.common.core.utils.DateUtils;
|
||||||
|
|
@ -37,6 +42,7 @@ import com.bonus.canteen.core.cook.domain.CookRecipe;
|
||||||
import com.bonus.canteen.core.cook.service.ICookRecipeService;
|
import com.bonus.canteen.core.cook.service.ICookRecipeService;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜品计划信息Service业务层处理
|
* 菜品计划信息Service业务层处理
|
||||||
|
|
@ -423,6 +429,42 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> recipeImportDishes(MultipartFile excel, Long recipeId) {
|
||||||
|
ExcelReader excelReader = null;
|
||||||
|
try {
|
||||||
|
Set<String> notImportDishesNames = new HashSet();
|
||||||
|
List<CookRecipeImportListener> listeners = new ArrayList();
|
||||||
|
|
||||||
|
excelReader = EasyExcel.read(excel.getInputStream()).build();
|
||||||
|
List<ReadSheet> readSheets = excelReader.excelExecutor().sheetList();
|
||||||
|
for (ReadSheet readSheet : readSheets) {
|
||||||
|
String sheetName = readSheet.getSheetName();
|
||||||
|
Integer mealtimeType = CookMealtimeTypeEnum.getKeyByDesc(sheetName);
|
||||||
|
if (!Objects.isNull(mealtimeType)) {
|
||||||
|
CookRecipeImportListener cookRecipeImportListener = new CookRecipeImportListener(sheetName, recipeId, mealtimeType.longValue());
|
||||||
|
listeners.add(cookRecipeImportListener);
|
||||||
|
readSheet.getCustomReadListenerList().add(cookRecipeImportListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
excelReader.read(readSheets);
|
||||||
|
notImportDishesNames.addAll(
|
||||||
|
listeners.stream()
|
||||||
|
.flatMap(listener -> listener.getNotImportDishesNames().stream())
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
|
||||||
|
return notImportDishesNames;
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new ServiceException(e.toString());
|
||||||
|
} finally {
|
||||||
|
if (excelReader != null) {
|
||||||
|
excelReader.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除菜品计划信息
|
* 批量删除菜品计划信息
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,9 @@ import com.bonus.canteen.core.cook.dto.ImportRecipeDishesDTO;
|
||||||
import com.bonus.canteen.core.cook.mapper.CookDishesMapper;
|
import com.bonus.canteen.core.cook.mapper.CookDishesMapper;
|
||||||
import com.bonus.canteen.core.cook.mapper.CookRecipeDetailMapper;
|
import com.bonus.canteen.core.cook.mapper.CookRecipeDetailMapper;
|
||||||
import com.bonus.canteen.core.cook.mapper.CookRecipeDishesMapper;
|
import com.bonus.canteen.core.cook.mapper.CookRecipeDishesMapper;
|
||||||
import com.bonus.canteen.core.cook.service.ICookDishesService;
|
|
||||||
import com.bonus.canteen.core.cook.service.ICookRecipeDetailService;
|
|
||||||
import com.bonus.canteen.core.cook.service.ICookRecipeDishesService;
|
|
||||||
import com.bonus.common.core.exception.ServiceException;
|
import com.bonus.common.core.exception.ServiceException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -109,7 +104,7 @@ public class CookRecipeImportListener extends AnalysisEventListener<Map<Integer,
|
||||||
try {
|
try {
|
||||||
HashSet<LocalDate> dates = new HashSet(this.dateMap.values());
|
HashSet<LocalDate> dates = new HashSet(this.dateMap.values());
|
||||||
if (!dates.isEmpty()) {
|
if (!dates.isEmpty()) {
|
||||||
ICookRecipeDetailService menuRecipeDetailService = SpringContextHolder.getBean(ICookRecipeDetailService.class);
|
//ICookRecipeDetailService menuRecipeDetailService = SpringContextHolder.getBean(ICookRecipeDetailService.class);
|
||||||
CookRecipeDetailMapper cookRecipeDetailMapper = SpringContextHolder.getBean(CookRecipeDetailMapper.class);
|
CookRecipeDetailMapper cookRecipeDetailMapper = SpringContextHolder.getBean(CookRecipeDetailMapper.class);
|
||||||
CookRecipeDishesMapper cookRecipeDishesMapper = SpringContextHolder.getBean(CookRecipeDishesMapper.class);
|
CookRecipeDishesMapper cookRecipeDishesMapper = SpringContextHolder.getBean(CookRecipeDishesMapper.class);
|
||||||
//List<CookRecipeDetail> byRecipeIdAndDates = menuRecipeDetailService.getByRecipeIdAndDatesAndIntervalId(this.recipeId, dates, this.mealtimeType);
|
//List<CookRecipeDetail> byRecipeIdAndDates = menuRecipeDetailService.getByRecipeIdAndDatesAndIntervalId(this.recipeId, dates, this.mealtimeType);
|
||||||
|
|
@ -123,50 +118,50 @@ public class CookRecipeImportListener extends AnalysisEventListener<Map<Integer,
|
||||||
CookDishesMapper cookDishesMapper = SpringContextHolder.getBean(CookDishesMapper.class);
|
CookDishesMapper cookDishesMapper = SpringContextHolder.getBean(CookDishesMapper.class);
|
||||||
CookDishes cookDishes = new CookDishes();
|
CookDishes cookDishes = new CookDishes();
|
||||||
cookDishes.setDishesNames(this.dishesNames);
|
cookDishes.setDishesNames(this.dishesNames);
|
||||||
List<CookDishes> menuDishesList = cookDishesMapper.selectCookDishesList(cookDishes);
|
List<CookDishes> cookDishesList = cookDishesMapper.selectCookDishesList(cookDishes);
|
||||||
|
|
||||||
Set<String> difference = DifferenceCalculator.calculateDifference(this.dishesNames, menuDishesList);
|
Set<String> difference = DifferenceCalculator.calculateDifference(this.dishesNames, cookDishesList);
|
||||||
System.out.println("差集结果: " + difference);
|
System.out.println("差集结果: " + difference);
|
||||||
if (difference != null && difference.size() > 0) {
|
if (difference != null && difference.size() > 0) {
|
||||||
throw new ServiceException("以下菜品不存在:" + difference);
|
throw new ServiceException("以下菜品不存在:" + difference);
|
||||||
}
|
}
|
||||||
Map<String, CookDishes> nameMap = menuDishesList.stream().collect(Collectors.groupingBy(CookDishes::getDishesName, Collectors.collectingAndThen(Collectors.toList(), (list) -> {
|
Map<String, CookDishes> nameMap = cookDishesList.stream().collect(Collectors.groupingBy(CookDishes::getDishesName, Collectors.collectingAndThen(Collectors.toList(), (list) -> {
|
||||||
return list.get(0);
|
return list.get(0);
|
||||||
})));
|
})));
|
||||||
ICookRecipeDishesService menuRecipeDishesService = SpringContextHolder.getBean(ICookRecipeDishesService.class);
|
//ICookRecipeDishesService menuRecipeDishesService = SpringContextHolder.getBean(ICookRecipeDishesService.class);
|
||||||
List<CookRecipeDishes> inserData = new ArrayList<>();
|
List<CookRecipeDishes> inserData = new ArrayList<>();
|
||||||
|
|
||||||
for (LocalDate date : dates) {
|
for (LocalDate date : dates) {
|
||||||
CookRecipeDetail menuRecipeDetail = dateDetailMap.get(date);
|
CookRecipeDetail cookRecipeDetail = dateDetailMap.get(date);
|
||||||
if (menuRecipeDetail == null) {
|
if (cookRecipeDetail == null) {
|
||||||
menuRecipeDetail = new CookRecipeDetail();
|
cookRecipeDetail = new CookRecipeDetail();
|
||||||
menuRecipeDetail.setRecipeId(this.recipeId);
|
cookRecipeDetail.setRecipeId(this.recipeId);
|
||||||
menuRecipeDetail.setApplyDate(date);
|
cookRecipeDetail.setApplyDate(date);
|
||||||
menuRecipeDetail.setMealtimeType(this.mealtimeType);
|
cookRecipeDetail.setMealtimeType(this.mealtimeType);
|
||||||
//menuRecipeDetail.setDetailId(Id.next());
|
//menuRecipeDetail.setDetailId(Id.next());
|
||||||
//menuRecipeDetailService.save(menuRecipeDetail);
|
//menuRecipeDetailService.save(menuRecipeDetail);
|
||||||
cookRecipeDetailMapper.insertCookRecipeDetail(menuRecipeDetail);
|
cookRecipeDetailMapper.insertCookRecipeDetail(cookRecipeDetail);
|
||||||
} else {
|
} else {
|
||||||
//menuRecipeDishesService.deleteByDetailId(menuRecipeDetail.getDetailId());
|
//menuRecipeDishesService.deleteByDetailId(menuRecipeDetail.getDetailId());
|
||||||
Long[] recipeDetailIds = {menuRecipeDetail.getRecipeDetailId()};
|
Long[] recipeDetailIds = {cookRecipeDetail.getRecipeDetailId()};
|
||||||
cookRecipeDishesMapper.deleteCookRecipeDishesByCookRecipeDetailIds(recipeDetailIds);
|
cookRecipeDishesMapper.deleteCookRecipeDishesByCookRecipeDetailIds(recipeDetailIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ImportRecipeDishesDTO> importRecipeDishesDtos = this.datas.get(date);
|
List<ImportRecipeDishesDTO> importRecipeDishesDtos = this.datas.get(date);
|
||||||
CookRecipeDetail finalMenuRecipeDetail = menuRecipeDetail;
|
CookRecipeDetail finalCookRecipeDetail = cookRecipeDetail;
|
||||||
List<CookRecipeDishes> saveDatas = importRecipeDishesDtos.stream().filter(distinctByKey(ImportRecipeDishesDTO::getDishesName)).map((importRecipeDishesDto) -> {
|
List<CookRecipeDishes> saveDatas = importRecipeDishesDtos.stream().filter(distinctByKey(ImportRecipeDishesDTO::getDishesName)).map((importRecipeDishesDto) -> {
|
||||||
CookRecipeDishes menuRecipeDishes = null;
|
CookRecipeDishes cookRecipeDishes = null;
|
||||||
CookDishes menuDishes = nameMap.get(importRecipeDishesDto.getDishesName());
|
CookDishes cookDishesValue = nameMap.get(importRecipeDishesDto.getDishesName());
|
||||||
if (menuDishes != null) {
|
if (cookDishesValue != null) {
|
||||||
menuRecipeDishes = BeanUtil.copyProperties(importRecipeDishesDto, CookRecipeDishes.class, new String[0]);
|
cookRecipeDishes = BeanUtil.copyProperties(importRecipeDishesDto, CookRecipeDishes.class, new String[0]);
|
||||||
menuRecipeDishes.setRecipeDetailId(finalMenuRecipeDetail.getRecipeDetailId());
|
cookRecipeDishes.setRecipeDetailId(finalCookRecipeDetail.getRecipeDetailId());
|
||||||
menuRecipeDishes.setSizeType(menuDishes.getSizeType());
|
cookRecipeDishes.setSizeType(cookDishesValue.getSizeType());
|
||||||
menuRecipeDishes.setDishesId(menuDishes.getDishesId());
|
cookRecipeDishes.setDishesId(cookDishesValue.getDishesId());
|
||||||
} else {
|
} else {
|
||||||
this.notImportDishesNames.add(importRecipeDishesDto.getDishesName());
|
this.notImportDishesNames.add(importRecipeDishesDto.getDishesName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return menuRecipeDishes;
|
return cookRecipeDishes;
|
||||||
}).filter(Objects::nonNull).collect(Collectors.toList());
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||||
inserData.addAll(saveDatas);
|
inserData.addAll(saveDatas);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue