新增菜谱
This commit is contained in:
parent
adcdd0086b
commit
1bb5aadfb8
|
|
@ -6,6 +6,8 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -26,7 +28,7 @@ public class CookRecipeDateDTO extends BaseEntity {
|
||||||
@ApiModelProperty(value = "启用时间(天)")
|
@ApiModelProperty(value = "启用时间(天)")
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
@Excel(name = "启用时间(天)", width = 30, dateFormat = "yyyy-MM-dd")
|
@Excel(name = "启用时间(天)", width = 30, dateFormat = "yyyy-MM-dd")
|
||||||
private Date applyDate;
|
private LocalDate applyDate;
|
||||||
|
|
||||||
/** 启用时间(周) */
|
/** 启用时间(周) */
|
||||||
@Excel(name = "启用时间(周)")
|
@Excel(name = "启用时间(周)")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.bonus.canteen.core.cook.service.impl;
|
package com.bonus.canteen.core.cook.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.time.LocalDate;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import com.bonus.canteen.core.cook.domain.CookRecipeDetail;
|
import com.bonus.canteen.core.cook.domain.CookRecipeDetail;
|
||||||
import com.bonus.canteen.core.cook.domain.CookRecipeDishes;
|
import com.bonus.canteen.core.cook.domain.CookRecipeDishes;
|
||||||
|
|
@ -77,34 +78,84 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
|
||||||
cookRecipeDTO.setCreateTime(DateUtils.getNowDate());
|
cookRecipeDTO.setCreateTime(DateUtils.getNowDate());
|
||||||
cookRecipeDTO.setCreateBy(SecurityUtils.getUsername());
|
cookRecipeDTO.setCreateBy(SecurityUtils.getUsername());
|
||||||
try {
|
try {
|
||||||
|
//TODO 判断名字是否重复
|
||||||
int count = cookRecipeMapper.insertCookRecipe(cookRecipeDTO); //插入菜谱
|
int count = cookRecipeMapper.insertCookRecipe(cookRecipeDTO); //插入菜谱
|
||||||
List<CookRecipeDateDTO> recipeDateList = cookRecipeDTO.getRecipeDateList();
|
createRecipeDetails(cookRecipeDTO, true);
|
||||||
for (CookRecipeDateDTO recipeDateDTO : recipeDateList) {
|
|
||||||
List<CookRecipeDetailDTO> detailList = recipeDateDTO.getDetailList();
|
|
||||||
for (CookRecipeDetailDTO detailDTO : detailList) {
|
|
||||||
if (CollectionUtils.isEmpty(detailDTO.getDishesList())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
CookRecipeDetail cookRecipeDetail = new CookRecipeDetail();
|
|
||||||
BeanUtils.copyProperties(recipeDateDTO, detailDTO);
|
|
||||||
BeanUtils.copyProperties(detailDTO, cookRecipeDetail);
|
|
||||||
cookRecipeDetail.setRecipeId(cookRecipeDTO.getRecipeId());
|
|
||||||
cookRecipeDetailMapper.insertCookRecipeDetail(cookRecipeDetail); //插入菜谱之执行计划
|
|
||||||
List<CookRecipeDishesDTO> dishesList = detailDTO.getDishesList();
|
|
||||||
for (CookRecipeDishesDTO dishesDTO : dishesList) {
|
|
||||||
CookRecipeDishes cookRecipeDishes = new CookRecipeDishes();
|
|
||||||
BeanUtils.copyProperties(dishesDTO, cookRecipeDishes);
|
|
||||||
cookRecipeDishes.setRecipeDetailId(cookRecipeDetail.getRecipeDetailId());
|
|
||||||
cookRecipeDishesMapper.insertCookRecipeDishes(cookRecipeDishes); //插入菜谱之菜品详情
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count;
|
return count;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceException(e.getMessage());
|
throw new ServiceException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createRecipeDetails(CookRecipeDTO cookRecipeDTO, boolean isCreate) {
|
||||||
|
List<CookRecipeDateDTO> recipeDateList = getCookRecipeDateList(cookRecipeDTO);
|
||||||
|
insertRecipeDetails(cookRecipeDTO, recipeDateList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<CookRecipeDateDTO> getCookRecipeDateList(CookRecipeDTO cookRecipeDTO) {
|
||||||
|
List<CookRecipeDateDTO> recipeDateList = new ArrayList<>();
|
||||||
|
if (1 == cookRecipeDTO.getRecipeType()) { //指定日期
|
||||||
|
recipeDateList = cookRecipeDTO.getRecipeDateList();
|
||||||
|
} else if (2 == cookRecipeDTO.getRecipeType()) { //每日循环
|
||||||
|
CookRecipeDateDTO cookRecipeDateDTO = new CookRecipeDateDTO();
|
||||||
|
LocalDate now = LocalDate.now();
|
||||||
|
for (int i = 0; i < 7; ++i) {
|
||||||
|
cookRecipeDateDTO.setApplyDate(now.plusDays(i));
|
||||||
|
}
|
||||||
|
recipeDateList.add(cookRecipeDateDTO);
|
||||||
|
recipeDateList.add(new CookRecipeDateDTO());
|
||||||
|
} else if (3 == cookRecipeDTO.getRecipeType()) { //每周循环
|
||||||
|
LocalDate now = LocalDate.now();
|
||||||
|
HashMap<Integer, LocalDate> dateHashMap = new HashMap<>();
|
||||||
|
for (int i = 0; i < 7; ++i) {
|
||||||
|
LocalDate applyWeek = now.plusDays((long) i);
|
||||||
|
dateHashMap.put(applyWeek.getDayOfWeek().getValue(), applyWeek);
|
||||||
|
}
|
||||||
|
for (Integer key : dateHashMap.keySet()) {
|
||||||
|
CookRecipeDateDTO cookRecipeDateDTO = new CookRecipeDateDTO();
|
||||||
|
cookRecipeDateDTO.setApplyWeek(Long.valueOf(key));
|
||||||
|
recipeDateList.add(cookRecipeDateDTO);
|
||||||
|
}
|
||||||
|
Iterator<Map.Entry<Integer, LocalDate>> iterator = dateHashMap.entrySet().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Map.Entry<Integer, LocalDate> entry = iterator.next();
|
||||||
|
CookRecipeDateDTO cookRecipeDateDTO = new CookRecipeDateDTO();
|
||||||
|
cookRecipeDateDTO.setApplyWeek(Long.valueOf(entry.getKey()));
|
||||||
|
cookRecipeDateDTO.setApplyDate(entry.getValue());
|
||||||
|
recipeDateList.add(cookRecipeDateDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return recipeDateList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void insertRecipeDetails(CookRecipeDTO cookRecipeDTO, List<CookRecipeDateDTO> recipeDateList) {
|
||||||
|
for (CookRecipeDateDTO recipeDateDTO : recipeDateList) {
|
||||||
|
List<CookRecipeDetailDTO> detailList = recipeDateDTO.getDetailList();
|
||||||
|
for (CookRecipeDetailDTO detailDTO : detailList) {
|
||||||
|
if (1 == cookRecipeDTO.getRecipeType() && CollectionUtils.isEmpty(detailDTO.getDishesList())) { //指定日期,不插入空数据
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
CookRecipeDetail cookRecipeDetail = new CookRecipeDetail();
|
||||||
|
BeanUtils.copyProperties(recipeDateDTO, detailDTO);
|
||||||
|
BeanUtils.copyProperties(detailDTO, cookRecipeDetail);
|
||||||
|
cookRecipeDetail.setRecipeId(cookRecipeDTO.getRecipeId());
|
||||||
|
if (Objects.isNull(cookRecipeDetail.getApplyDate())) {
|
||||||
|
cookRecipeDetail.setDetailType(1L); //模板数据
|
||||||
|
} else {
|
||||||
|
cookRecipeDetail.setDetailType(2L); //详情数据
|
||||||
|
}
|
||||||
|
cookRecipeDetailMapper.insertCookRecipeDetail(cookRecipeDetail); //插入菜谱之执行计划
|
||||||
|
List<CookRecipeDishesDTO> dishesList = detailDTO.getDishesList();
|
||||||
|
for (CookRecipeDishesDTO dishesDTO : dishesList) {
|
||||||
|
CookRecipeDishes cookRecipeDishes = new CookRecipeDishes();
|
||||||
|
BeanUtils.copyProperties(dishesDTO, cookRecipeDishes);
|
||||||
|
cookRecipeDishes.setRecipeDetailId(cookRecipeDetail.getRecipeDetailId());
|
||||||
|
cookRecipeDishesMapper.insertCookRecipeDishes(cookRecipeDishes); //插入菜谱之菜品详情
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改菜品计划信息
|
* 修改菜品计划信息
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue