菜谱导入和菜谱定时任务
This commit is contained in:
parent
d90a34a220
commit
63d4951a3b
|
|
@ -185,8 +185,19 @@ public class MenuRecipeController extends BaseController {
|
|||
|
||||
@PostMapping({"/recipe/import/dishes"})
|
||||
@ApiOperation("批量导入菜谱中的菜品信息")
|
||||
@Transactional
|
||||
public AjaxResult recipeImportDishes(@RequestParam("file") MultipartFile excel, @RequestParam("recipeId") Long recipeId) {
|
||||
return ObjectUtil.isNull(excel) ? AjaxResult.error("请选择导入文件 ^_^") :
|
||||
AjaxResult.success(this.menuRecipeService.recipeImportDishes(excel, recipeId));
|
||||
}
|
||||
|
||||
@PostMapping({"/generateRecipe"})
|
||||
@ApiOperation("定时任务")
|
||||
@Transactional
|
||||
public AjaxResult generateRecipe() {
|
||||
this.menuRecipeService.generateRecipe();
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,9 +50,11 @@ public class MenuDishes extends Model<MenuDishes> {
|
|||
private Long typeId;
|
||||
|
||||
@ApiModelProperty("菜品类型ID List")
|
||||
@TableField(exist = false)
|
||||
private List typeIdList;
|
||||
|
||||
@ApiModelProperty("菜品类型名称")
|
||||
@TableField(exist = false)
|
||||
private String typeName;
|
||||
|
||||
@ApiModelProperty("菜品灶类ID")
|
||||
|
|
@ -161,6 +163,7 @@ public class MenuDishes extends Model<MenuDishes> {
|
|||
@ApiModelProperty("隐藏标识(1隐藏,2展示)")
|
||||
private Integer hideFlag;
|
||||
@ApiModelProperty("删除标识")
|
||||
@TableField(exist = false)
|
||||
private Integer delFlag;
|
||||
@ApiModelProperty("乐观锁")
|
||||
private Integer revision;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import com.bonus.common.core.web.domain.BaseEntity;
|
|||
|
||||
/**
|
||||
* 菜品计划详情信息对象 menu_recipe_detail
|
||||
*
|
||||
*
|
||||
* @author xsheng
|
||||
* @date 2025-04-03
|
||||
*/
|
||||
|
|
@ -41,6 +41,7 @@ public class MenuRecipeDetail{
|
|||
@ApiModelProperty("启用时间(天)")
|
||||
private LocalDate applyDate;
|
||||
@ApiModelProperty("启用时间(天)")
|
||||
@TableField(exist = false)
|
||||
private LocalDate endDate;
|
||||
@ApiModelProperty("餐次类型")
|
||||
private Integer mealtimeType;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class MenuRecipeDishes extends Model<MenuRecipeDishes> {
|
|||
@ApiModelProperty("菜品价格(优惠价)")
|
||||
private Integer salePrice;
|
||||
@ApiModelProperty("是否推荐")
|
||||
private Integer recommendFlag;
|
||||
private Integer recommendFlag = 1;
|
||||
@ApiModelProperty("排序号")
|
||||
private Integer sortNum = -1;
|
||||
@ApiModelProperty("乐观锁")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
package com.bonus.canteen.core.menu.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
public class ImportRecipeDishesDto {
|
||||
private Integer index;
|
||||
private String dishesName;
|
||||
@ApiModelProperty("菜品单价")
|
||||
private Integer price;
|
||||
@ApiModelProperty("供应数量")
|
||||
private Integer supplyNum;
|
||||
@ApiModelProperty("销售数量")
|
||||
private Integer saleNum;
|
||||
@ApiModelProperty("剩余数量")
|
||||
private Integer surplusNum;
|
||||
@ApiModelProperty("个人限购数量")
|
||||
private Integer restrictNum;
|
||||
@ApiModelProperty("菜品价格(优惠价)")
|
||||
private Integer salePrice;
|
||||
|
||||
public Integer getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
public String getDishesName() {
|
||||
return this.dishesName;
|
||||
}
|
||||
|
||||
public Integer getPrice() {
|
||||
return this.price;
|
||||
}
|
||||
|
||||
public Integer getSupplyNum() {
|
||||
return this.supplyNum;
|
||||
}
|
||||
|
||||
public Integer getSaleNum() {
|
||||
return this.saleNum;
|
||||
}
|
||||
|
||||
public Integer getSurplusNum() {
|
||||
return this.surplusNum;
|
||||
}
|
||||
|
||||
public Integer getRestrictNum() {
|
||||
return this.restrictNum;
|
||||
}
|
||||
|
||||
public Integer getSalePrice() {
|
||||
return this.salePrice;
|
||||
}
|
||||
|
||||
public ImportRecipeDishesDto setIndex(final Integer index) {
|
||||
this.index = index;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImportRecipeDishesDto setDishesName(final String dishesName) {
|
||||
this.dishesName = dishesName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImportRecipeDishesDto setPrice(final Integer price) {
|
||||
this.price = price;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImportRecipeDishesDto setSupplyNum(final Integer supplyNum) {
|
||||
this.supplyNum = supplyNum;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImportRecipeDishesDto setSaleNum(final Integer saleNum) {
|
||||
this.saleNum = saleNum;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImportRecipeDishesDto setSurplusNum(final Integer surplusNum) {
|
||||
this.surplusNum = surplusNum;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImportRecipeDishesDto setRestrictNum(final Integer restrictNum) {
|
||||
this.restrictNum = restrictNum;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImportRecipeDishesDto setSalePrice(final Integer salePrice) {
|
||||
this.salePrice = salePrice;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.bonus.canteen.core.menu.mapper;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.bonus.canteen.core.menu.domain.MapBean;
|
||||
import com.bonus.canteen.core.menu.domain.MenuDishes;
|
||||
import com.bonus.canteen.core.menu.domain.MenuDishesRelation;
|
||||
|
|
@ -16,7 +17,7 @@ import org.apache.ibatis.annotations.Param;
|
|||
* @author xsheng
|
||||
* @date 2025-04-03
|
||||
*/
|
||||
public interface MenuDishesMapper {
|
||||
public interface MenuDishesMapper extends BaseMapper<MenuDishes> {
|
||||
/**
|
||||
* 查询菜品信息
|
||||
*
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.util.Map;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.bonus.canteen.core.device.domain.DeviceInfo;
|
||||
import com.bonus.canteen.core.device.domain.DeviceInfo;
|
||||
|
|
@ -249,4 +250,8 @@ public interface MenuRecipeMapper extends BaseMapper<MenuRecipe> {
|
|||
int insertMenuMateralDishes(@Param("materialList") ArrayList<MenuMaterialDishes> menuMaterialDishesList);
|
||||
|
||||
MenuNutritionDetailVO getMenuNutritionDetailById(Long nutritionId);
|
||||
|
||||
@Select({"select recipe_id as recipeId from menu_recipe ${ew.customSqlSegment}"})
|
||||
List<Long> selectRecipeIdList(@Param("ew") QueryWrapper<MenuRecipe> recipeType);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package com.bonus.canteen.core.menu.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bonus.canteen.core.menu.domain.MapBean;
|
||||
import com.bonus.canteen.core.menu.domain.MenuDishes;
|
||||
import com.bonus.canteen.core.menu.dto.DishesImportCheckResult;
|
||||
|
|
@ -15,7 +17,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
* @author xsheng
|
||||
* @date 2025-04-03
|
||||
*/
|
||||
public interface IMenuDishesService {
|
||||
public interface IMenuDishesService extends IService<MenuDishes> {
|
||||
/**
|
||||
* 查询菜品信息
|
||||
*
|
||||
|
|
@ -74,5 +76,6 @@ public interface IMenuDishesService {
|
|||
|
||||
Boolean newImportDishes(List<MenuDishesImportDTO> request);
|
||||
|
||||
List<MenuDishes> getByNames(Set<String> dishesNames);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package com.bonus.canteen.core.menu.service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bonus.canteen.core.menu.domain.MenuRecipeDetail;
|
||||
|
|
@ -59,4 +62,12 @@ public interface IMenuRecipeDetailService extends IService<MenuRecipeDetail> {
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteMenuRecipeDetailById(Long id);
|
||||
|
||||
|
||||
|
||||
List<MenuRecipeDetail> getByRecipeIdAndDatesAndIntervalId(Long recipeId, Set<LocalDate> dates, Integer mealtimeType);
|
||||
|
||||
MenuRecipeDetail getByRecipeIdAndApplyDateAndIntervalId(Long recipeId, LocalDate applyDate, Integer mealtimeType);
|
||||
|
||||
Map<Long, Set<LocalDate>> selectApplyDateListByRecipeId(List<Long> recipeIds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,4 +76,6 @@ public interface IMenuRecipeDishesService extends IService<MenuRecipeDishes> {
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteMenuRecipeDishesById(Long id);
|
||||
|
||||
Boolean deleteByDetailId(Long detailId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,6 +96,8 @@ public interface IMenuRecipeService extends IService<MenuRecipe> {
|
|||
|
||||
void generateRecipe(Long recipeId, LocalDate applyDate);
|
||||
|
||||
void generateRecipe();
|
||||
|
||||
void bindAppRecipe(MenuRecipeBindDTO dto);
|
||||
/**
|
||||
* 根据sn获取菜谱菜品信息
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import cn.hutool.core.util.NumberUtil;
|
|||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bonus.canteen.core.alloc.domain.AllocArea;
|
||||
import com.bonus.canteen.core.alloc.domain.AllocCanteen;
|
||||
import com.bonus.canteen.core.alloc.domain.AllocStall;
|
||||
|
|
@ -40,6 +41,7 @@ import com.bonus.canteen.core.utils.PinyinUtil;
|
|||
import com.bonus.canteen.core.utils.excel.EasyExcelUtil;
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
import com.bonus.common.core.utils.DateUtils;
|
||||
import com.bonus.common.houqin.constant.DelFlagEnum;
|
||||
import com.bonus.common.houqin.utils.id.Id;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
|
|
@ -68,7 +70,7 @@ import javax.validation.constraints.Size;
|
|||
* @date 2025-04-03
|
||||
*/
|
||||
@Service
|
||||
public class MenuDishesServiceImpl implements IMenuDishesService {
|
||||
public class MenuDishesServiceImpl extends ServiceImpl<MenuDishesMapper, MenuDishes> implements IMenuDishesService {
|
||||
@Autowired
|
||||
private MenuDishesMapper menuDishesMapper;
|
||||
|
||||
|
|
@ -1048,4 +1050,11 @@ public class MenuDishesServiceImpl implements IMenuDishesService {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<MenuDishes> getByNames(Set<String> dishesNames) {
|
||||
return this.list(Wrappers.lambdaQuery(MenuDishes.class)
|
||||
//.eq(MenuDishes::getDelFlag, DelFlagEnum.DEL_FALSE.key())
|
||||
.in(MenuDishes::getDishesName, dishesNames));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,12 @@ package com.bonus.canteen.core.menu.service.impl;
|
|||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
import com.bonus.common.core.utils.DateUtils;
|
||||
|
|
@ -99,4 +104,28 @@ public class MenuRecipeDetailServiceImpl extends ServiceImpl<MenuRecipeDetailMap
|
|||
public int deleteMenuRecipeDetailById(Long id) {
|
||||
return menuRecipeDetailMapper.deleteMenuRecipeDetailById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuRecipeDetail> getByRecipeIdAndDatesAndIntervalId(Long recipeId, Set<LocalDate> values, Integer mealtimeType) {
|
||||
return this.list(Wrappers.<MenuRecipeDetail>lambdaQuery()
|
||||
.eq(MenuRecipeDetail::getMealtimeType, mealtimeType)
|
||||
.eq(MenuRecipeDetail::getRecipeId, recipeId).in(MenuRecipeDetail::getApplyDate, values));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuRecipeDetail getByRecipeIdAndApplyDateAndIntervalId(Long recipeId, LocalDate applyDate, Integer mealtimeType) {
|
||||
return (MenuRecipeDetail) this.getOne(Wrappers.<MenuRecipeDetail>lambdaQuery()
|
||||
.eq(MenuRecipeDetail::getMealtimeType, mealtimeType)
|
||||
.eq(MenuRecipeDetail::getRecipeId, recipeId)
|
||||
.eq(MenuRecipeDetail::getApplyDate, applyDate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, Set<LocalDate>> selectApplyDateListByRecipeId(List<Long> recipeIds) {
|
||||
return this.list(Wrappers.<MenuRecipeDetail>lambdaQuery()
|
||||
.select(MenuRecipeDetail::getRecipeId, MenuRecipeDetail::getApplyDate)
|
||||
.ge(MenuRecipeDetail::getApplyDate, LocalDate.now())
|
||||
.in(MenuRecipeDetail::getRecipeId, recipeIds)).stream()
|
||||
.collect(Collectors.groupingBy(MenuRecipeDetail::getRecipeId, Collectors.mapping(MenuRecipeDetail::getApplyDate, Collectors.toCollection(TreeSet::new))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.util.Collection;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.bonus.canteen.core.account.service.impl.AccSubServiceImpl;
|
||||
import com.bonus.canteen.core.common.utils.RedisUtil;
|
||||
|
||||
|
|
@ -181,4 +182,10 @@ public class MenuRecipeDishesServiceImpl extends ServiceImpl<MenuRecipeDishesMap
|
|||
public int deleteMenuRecipeDishesById(Long id) {
|
||||
return menuRecipeDishesMapper.deleteMenuRecipeDishesById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteByDetailId(Long detailId) {
|
||||
return this.remove(Wrappers.lambdaQuery(MenuRecipeDishes.class)
|
||||
.eq(MenuRecipeDishes::getDetailId, detailId));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ import com.bonus.canteen.core.menu.vo.MenuRecipeDataVO;
|
|||
import com.bonus.canteen.core.menu.vo.MenuRecipeDetailDateVO;
|
||||
import com.bonus.canteen.core.menu.vo.MenuRecipeV2VO;
|
||||
import com.bonus.canteen.core.utils.excel.EasyExcelUtil;
|
||||
import com.bonus.canteen.core.utils.excel.MenuRecipeImportListener;
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
|
|
@ -544,6 +545,16 @@ public class MenuRecipeServiceImpl extends ServiceImpl<MenuRecipeMapper, MenuRec
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateRecipe() {
|
||||
// List<Long> recipeIds = (List)this.list((Wrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(MenuRecipe.class).eq(MenuRecipe::getDelFlag, DelFlagEnum.DEL_FALSE.key())).in(MenuRecipe::getRecipeType, new Object[]{2, 3})).stream().map(MenuRecipe::getRecipeId).collect(Collectors.toList());
|
||||
List<Long> recipeIds = this.menuRecipeMapper.selectRecipeIdList(new QueryWrapper<MenuRecipe>()
|
||||
.in("recipe_type", 2, 3));
|
||||
for(int i = 0; i < 7; ++i) {
|
||||
this.generateRecipe(recipeIds, LocalDate.now().plusDays((long)i));
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public synchronized void generateRecipe(List<Long> recipeIdList, LocalDate applyDate) {
|
||||
if (!ObjectUtil.isEmpty(recipeIdList) && !ObjectUtil.isEmpty(applyDate)) {
|
||||
|
|
@ -1366,64 +1377,37 @@ public class MenuRecipeServiceImpl extends ServiceImpl<MenuRecipeMapper, MenuRec
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Set<String> recipeImportDishes(MultipartFile excel, Long recipeId) {
|
||||
// MenuRecipe menuRecipe = this.getOne(Wrappers.lambdaQuery(MenuRecipe.class)
|
||||
// .eq(MenuRecipe::getRecipeId, recipeId));
|
||||
// // .eq(MenuRecipe::getDelFlag, DelFlagEnum.DEL_FALSE.key()));
|
||||
// if (menuRecipe == null) {
|
||||
// throw new ServiceException(I18n.getMessage("menu_recipe_not_exist2", new Object[0]));
|
||||
// } else {
|
||||
// this.update(Wrappers.lambdaUpdate(MenuRecipe.class).eq(MenuRecipe::getRecipeId, recipeId).set(MenuRecipe::getUpdateTime, LocalDateTime.now()));
|
||||
// ExcelReader excelReader = null;
|
||||
// Set<String> notImportDishesNames = new HashSet();
|
||||
// List<MenuRecipeImportListener> listeners = new ArrayList();
|
||||
// try {
|
||||
// excelReader = EasyExcel.read(excel.getInputStream()).build();
|
||||
// List<ReadSheet> readSheets = excelReader.excelExecutor().sheetList();
|
||||
//
|
||||
// for (ReadSheet readSheet : readSheets) {
|
||||
// String sheetName = readSheet.getSheetName();
|
||||
// Integer mealtimeType = AllocMealtimeTypeEnum.getKeyByDesc(sheetName);
|
||||
// if (!Objects.isNull(mealtimeType)) {
|
||||
// MenuRecipeImportListener menuRecipeImportListener = new MenuRecipeImportListener(sheetName, recipeId, mealtimeType);
|
||||
// listeners.add(menuRecipeImportListener);
|
||||
// readSheet.getCustomReadListenerList().add(menuRecipeImportListener);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// excelReader.read(readSheets);
|
||||
// notImportDishesNames.addAll(
|
||||
// listeners.stream()
|
||||
// .flatMap(listener -> listener.getNotImportDishesNames().stream())
|
||||
// .collect(Collectors.toList())
|
||||
// );
|
||||
// } catch (Exception var16) {
|
||||
// log.error("导入菜品失败", var16);
|
||||
// } finally {
|
||||
// if (excelReader != null) {
|
||||
// excelReader.finish();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
ExcelReader excelReader = null;
|
||||
Set<String> notImportDishesNames = new HashSet();
|
||||
List<MenuRecipeImportListener> listeners = new ArrayList();
|
||||
try {
|
||||
excelReader = EasyExcel.read(excel.getInputStream()).build();
|
||||
List<ReadSheet> readSheets = excelReader.excelExecutor().sheetList();
|
||||
for (ReadSheet readSheet : readSheets) {
|
||||
String sheetName = readSheet.getSheetName();
|
||||
Integer mealtimeType = AllocMealtimeTypeEnum.getKeyByDesc(sheetName);
|
||||
if (!Objects.isNull(mealtimeType)) {
|
||||
MenuRecipeImportListener menuRecipeImportListener = new MenuRecipeImportListener(sheetName, recipeId, mealtimeType);
|
||||
listeners.add(menuRecipeImportListener);
|
||||
readSheet.getCustomReadListenerList().add(menuRecipeImportListener);
|
||||
}
|
||||
}
|
||||
excelReader.read(readSheets);
|
||||
notImportDishesNames.addAll(
|
||||
listeners.stream()
|
||||
.flatMap(listener -> listener.getNotImportDishesNames().stream())
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}catch (Exception var16) {
|
||||
log.error("导入菜品失败", var16);
|
||||
} finally {
|
||||
if (excelReader != null) {
|
||||
excelReader.finish();
|
||||
}
|
||||
|
||||
// return notImportDishesNames;
|
||||
return null;
|
||||
}
|
||||
return notImportDishesNames;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package com.bonus.canteen.core.menu.task;
|
||||
|
||||
import com.bonus.canteen.core.common.utils.RedisUtil;
|
||||
import com.bonus.canteen.core.menu.service.IMenuRecipeService;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Component
|
||||
public class MenuRecipeTask {
|
||||
private static final Logger log = LoggerFactory.getLogger(MenuRecipeTask.class);
|
||||
@Autowired
|
||||
private IMenuRecipeService menuRecipeService;
|
||||
|
||||
@Autowired
|
||||
private TransactionTemplate transactionTemplate;
|
||||
|
||||
@XxlJob("menuRecipeHandler")
|
||||
public void couponFixedTimeHandler() {
|
||||
boolean menuRecipeHandler = RedisUtil.setNx("menuRecipeHandler", "1", 3600);
|
||||
if (menuRecipeHandler) {
|
||||
transactionTemplate.execute(status -> {
|
||||
try {
|
||||
// 业务代码
|
||||
log.info("[定时生成菜谱]开始:{},{}", status, LocalDateTime.now());
|
||||
this.menuRecipeService.generateRecipe();
|
||||
log.info("[定时生成菜谱]结束:{},{}", status, LocalDateTime.now());
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
status.setRollbackOnly(); // 标记回滚
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,164 +1,165 @@
|
|||
//package com.bonus.canteen.core.utils.excel;
|
||||
//
|
||||
//import cn.hutool.core.bean.BeanUtil;
|
||||
//import cn.hutool.core.date.DateUtil;
|
||||
//import cn.hutool.core.util.ObjectUtil;
|
||||
//import com.alibaba.excel.context.AnalysisContext;
|
||||
//import com.alibaba.excel.event.AnalysisEventListener;
|
||||
//import com.bonus.canteen.core.common.utils.SpringContextHolder;
|
||||
//import com.bonus.canteen.core.menu.dto.ImportRecipeDishesDto;
|
||||
//import com.bonus.canteen.core.menu.entity.MenuDishes;
|
||||
//import com.bonus.canteen.core.menu.entity.MenuRecipeDetail;
|
||||
//import com.bonus.canteen.core.menu.entity.MenuRecipeDishes;
|
||||
//import com.bonus.canteen.core.menu.service.MenuDishesService;
|
||||
//import com.bonus.canteen.core.menu.service.MenuRecipeDetailService;
|
||||
//import com.bonus.canteen.core.menu.service.MenuRecipeDishesService;
|
||||
//import com.bonus.common.houqin.utils.id.Id;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//
|
||||
//import java.math.BigDecimal;
|
||||
//import java.time.LocalDate;
|
||||
//import java.util.*;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//import java.util.function.Function;
|
||||
//import java.util.function.Predicate;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
//public class MenuRecipeImportListener extends AnalysisEventListener<Map<Integer, String>> {
|
||||
// private static final Logger log = LoggerFactory.getLogger(MenuRecipeImportListener.class);
|
||||
// private final String sheetName;
|
||||
// private final Long recipeId;
|
||||
// private final Integer mealtimeType;
|
||||
// private final Map<Integer, LocalDate> dateMap = new HashMap();
|
||||
// private final Set<String> dishesNames = new HashSet();
|
||||
// private final Set<String> notImportDishesNames = new HashSet();
|
||||
// private final Map<LocalDate, List<ImportRecipeDishesDto>> datas = new HashMap();
|
||||
// private final BigDecimal decimal = new BigDecimal(100);
|
||||
//
|
||||
// public Set<String> getNotImportDishesNames() {
|
||||
// return this.notImportDishesNames;
|
||||
// }
|
||||
//
|
||||
// public MenuRecipeImportListener(String sheetName, Long recipeId, Integer mealtimeType) {
|
||||
// this.sheetName = sheetName;
|
||||
// this.recipeId = recipeId;
|
||||
// this.mealtimeType = mealtimeType;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void invoke(Map<Integer, String> integerStringMap, AnalysisContext analysisContext) {
|
||||
// Integer rowIndex = analysisContext.readRowHolder().getRowIndex();
|
||||
// String no;
|
||||
// if (rowIndex == 1) {
|
||||
// no = (String)integerStringMap.get(1);
|
||||
// log.info("餐次名称:{}", no);
|
||||
// }
|
||||
//
|
||||
// if (rowIndex == 2) {
|
||||
// for(int i = 1; i < integerStringMap.size(); i += 3) {
|
||||
// String date = (String)integerStringMap.get(i);
|
||||
// if (date != null && !date.isEmpty()) {
|
||||
// Date parse = DateUtil.parse(date);
|
||||
// String format = DateUtil.format(parse, "yyyy/MM/dd");
|
||||
// String[] split = format.split("/");
|
||||
// LocalDate localDate = LocalDate.of(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
|
||||
// this.dateMap.put(i, localDate);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// log.info("导入的日期:{}", this.dateMap.values());
|
||||
// }
|
||||
//
|
||||
// if (rowIndex > 2) {
|
||||
// try {
|
||||
// no = (String)integerStringMap.get(0);
|
||||
// if (no != null && !no.isEmpty()) {
|
||||
// for(int i = 1; i < integerStringMap.size(); i += 3) {
|
||||
// String dishesName = (String)integerStringMap.get(i);
|
||||
// if (!ObjectUtil.isEmpty(dishesName)) {
|
||||
// ImportRecipeDishesDto importRecipeDishesDto = new ImportRecipeDishesDto();
|
||||
// this.dishesNames.add(dishesName);
|
||||
// BigDecimal price = (new BigDecimal((String)integerStringMap.get(i + 1))).multiply(this.decimal);
|
||||
// BigDecimal salePrice = (new BigDecimal((String)integerStringMap.get(i + 2))).multiply(this.decimal);
|
||||
// importRecipeDishesDto.setSurplusNum(9999).setIndex(i).setDishesName(dishesName).setSaleNum(0).setSupplyNum(9999).setRestrictNum(9999).setPrice(price.intValue()).setSalePrice(salePrice.intValue());
|
||||
// if (this.datas.containsKey(this.dateMap.get(i))) {
|
||||
// ((List)this.datas.get(this.dateMap.get(i))).add(importRecipeDishesDto);
|
||||
// } else {
|
||||
// List<ImportRecipeDishesDto> list = new ArrayList();
|
||||
// list.add(importRecipeDishesDto);
|
||||
// this.datas.put((LocalDate)this.dateMap.get(i), list);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception var11) {
|
||||
// log.info("解析excel失败:DATA:{}", integerStringMap);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||
// HashSet<LocalDate> dates = new HashSet(this.dateMap.values());
|
||||
// if (!dates.isEmpty()) {
|
||||
// MenuRecipeDetailService menuRecipeDetailService = SpringContextHolder.getBean(MenuRecipeDetailService.class);
|
||||
// List<MenuRecipeDetail> byRecipeIdAndDates = menuRecipeDetailService.getByRecipeIdAndDatesAndIntervalId(this.recipeId, dates, this.mealtimeType);
|
||||
// Map<LocalDate, MenuRecipeDetail> dateDetailMap = byRecipeIdAndDates.stream().collect(Collectors.groupingBy(MenuRecipeDetail::getApplyDate, Collectors.collectingAndThen(Collectors.toList(), (list) -> {
|
||||
// return list.get(0);
|
||||
// })));
|
||||
// if (!this.dishesNames.isEmpty()) {
|
||||
// MenuDishesService menuDishesService = SpringContextHolder.getBean(MenuDishesService.class);
|
||||
// List<MenuDishes> menuDishesList = menuDishesService.getByNames(this.dishesNames);
|
||||
// Map<String, MenuDishes> nameMap = menuDishesList.stream().collect(Collectors.groupingBy(MenuDishes::getDishesName, Collectors.collectingAndThen(Collectors.toList(), (list) -> {
|
||||
// return list.get(0);
|
||||
// })));
|
||||
// MenuRecipeDishesService menuRecipeDishesService = SpringContextHolder.getBean(MenuRecipeDishesService.class);
|
||||
// List<MenuRecipeDishes> inserData = new ArrayList<>();
|
||||
//
|
||||
// for (LocalDate date : dates) {
|
||||
// MenuRecipeDetail menuRecipeDetail = dateDetailMap.get(date);
|
||||
// if (menuRecipeDetail == null) {
|
||||
// menuRecipeDetail = new MenuRecipeDetail();
|
||||
// menuRecipeDetail.setRecipeId(this.recipeId);
|
||||
// menuRecipeDetail.setApplyDate(date);
|
||||
// menuRecipeDetail.setMealtimeType(this.mealtimeType);
|
||||
// menuRecipeDetail.setDetailId(Id.next());
|
||||
// menuRecipeDetailService.save(menuRecipeDetail);
|
||||
// } else {
|
||||
// menuRecipeDishesService.deleteByDetailId(menuRecipeDetail.getDetailId());
|
||||
// }
|
||||
//
|
||||
// List<ImportRecipeDishesDto> importRecipeDishesDtos = this.datas.get(date);
|
||||
// MenuRecipeDetail finalMenuRecipeDetail = menuRecipeDetail;
|
||||
// List<MenuRecipeDishes> saveDatas = importRecipeDishesDtos.stream().filter(distinctByKey(ImportRecipeDishesDto::getDishesName)).map((importRecipeDishesDto) -> {
|
||||
// MenuRecipeDishes menuRecipeDishes = null;
|
||||
// MenuDishes menuDishes = nameMap.get(importRecipeDishesDto.getDishesName());
|
||||
// if (menuDishes != null) {
|
||||
// menuRecipeDishes = BeanUtil.copyProperties(importRecipeDishesDto, MenuRecipeDishes.class, new String[0]);
|
||||
// menuRecipeDishes.setDetailId(finalMenuRecipeDetail.getDetailId());
|
||||
// menuRecipeDishes.setSizeType(menuDishes.getSizeType());
|
||||
// menuRecipeDishes.setDishesId(menuDishes.getDishesId());
|
||||
// } else {
|
||||
// this.notImportDishesNames.add(importRecipeDishesDto.getDishesName());
|
||||
// }
|
||||
//
|
||||
// return menuRecipeDishes;
|
||||
// }).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
// inserData.addAll(saveDatas);
|
||||
// }
|
||||
//
|
||||
// menuRecipeDishesService.saveBatch(inserData);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||
// Map<Object, Boolean> seen = new ConcurrentHashMap<>();
|
||||
// return (t) -> {
|
||||
// return seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
||||
// };
|
||||
// }
|
||||
//}
|
||||
package com.bonus.canteen.core.utils.excel;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import com.bonus.canteen.core.common.utils.SpringContextHolder;
|
||||
import com.bonus.canteen.core.menu.domain.MenuDishes;
|
||||
import com.bonus.canteen.core.menu.domain.MenuRecipeDetail;
|
||||
import com.bonus.canteen.core.menu.domain.MenuRecipeDishes;
|
||||
import com.bonus.canteen.core.menu.dto.ImportRecipeDishesDto;
|
||||
import com.bonus.canteen.core.menu.service.IMenuDishesService;
|
||||
import com.bonus.canteen.core.menu.service.IMenuRecipeDetailService;
|
||||
import com.bonus.canteen.core.menu.service.IMenuRecipeDishesService;
|
||||
import com.bonus.common.houqin.utils.id.Id;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MenuRecipeImportListener extends AnalysisEventListener<Map<Integer, String>> {
|
||||
private static final Logger log = LoggerFactory.getLogger(MenuRecipeImportListener.class);
|
||||
private final String sheetName;
|
||||
private final Long recipeId;
|
||||
private final Integer mealtimeType;
|
||||
private final Map<Integer, LocalDate> dateMap = new HashMap();
|
||||
private final Set<String> dishesNames = new HashSet();
|
||||
private final Set<String> notImportDishesNames = new HashSet();
|
||||
private final Map<LocalDate, List<ImportRecipeDishesDto>> datas = new HashMap();
|
||||
private final BigDecimal decimal = new BigDecimal(100);
|
||||
|
||||
public Set<String> getNotImportDishesNames() {
|
||||
return this.notImportDishesNames;
|
||||
}
|
||||
|
||||
public MenuRecipeImportListener(String sheetName, Long recipeId, Integer mealtimeType) {
|
||||
this.sheetName = sheetName;
|
||||
this.recipeId = recipeId;
|
||||
this.mealtimeType = mealtimeType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(Map<Integer, String> integerStringMap, AnalysisContext analysisContext) {
|
||||
Integer rowIndex = analysisContext.readRowHolder().getRowIndex();
|
||||
String no;
|
||||
if (rowIndex == 1) {
|
||||
no = (String)integerStringMap.get(1);
|
||||
log.info("餐次名称:{}", no);
|
||||
}
|
||||
|
||||
if (rowIndex == 2) {
|
||||
for(int i = 1; i < integerStringMap.size(); i += 3) {
|
||||
String date = (String)integerStringMap.get(i);
|
||||
if (date != null && !date.isEmpty()) {
|
||||
Date parse = DateUtil.parse(date);
|
||||
String format = DateUtil.format(parse, "yyyy/MM/dd");
|
||||
String[] split = format.split("/");
|
||||
LocalDate localDate = LocalDate.of(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
|
||||
this.dateMap.put(i, localDate);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("导入的日期:{}", this.dateMap.values());
|
||||
}
|
||||
|
||||
if (rowIndex > 2) {
|
||||
try {
|
||||
no = (String)integerStringMap.get(0);
|
||||
if (no != null && !no.isEmpty()) {
|
||||
for(int i = 1; i < integerStringMap.size(); i += 3) {
|
||||
String dishesName = (String)integerStringMap.get(i);
|
||||
if (!ObjectUtil.isEmpty(dishesName)) {
|
||||
ImportRecipeDishesDto importRecipeDishesDto = new ImportRecipeDishesDto();
|
||||
this.dishesNames.add(dishesName);
|
||||
BigDecimal price = (new BigDecimal((String)integerStringMap.get(i + 1))).multiply(this.decimal);
|
||||
BigDecimal salePrice = (new BigDecimal((String)integerStringMap.get(i + 2))).multiply(this.decimal);
|
||||
importRecipeDishesDto.setSurplusNum(9999).setIndex(i).setDishesName(dishesName).setSaleNum(0).setSupplyNum(9999).setRestrictNum(9999).setPrice(price.intValue()).setSalePrice(salePrice.intValue());
|
||||
if (this.datas.containsKey(this.dateMap.get(i))) {
|
||||
((List)this.datas.get(this.dateMap.get(i))).add(importRecipeDishesDto);
|
||||
} else {
|
||||
List<ImportRecipeDishesDto> list = new ArrayList();
|
||||
list.add(importRecipeDishesDto);
|
||||
this.datas.put((LocalDate)this.dateMap.get(i), list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception var11) {
|
||||
log.info("解析excel失败:DATA:{}", integerStringMap);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||
HashSet<LocalDate> dates = new HashSet(this.dateMap.values());
|
||||
if (!dates.isEmpty()) {
|
||||
IMenuRecipeDetailService menuRecipeDetailService = SpringContextHolder.getBean(IMenuRecipeDetailService.class);
|
||||
List<MenuRecipeDetail> byRecipeIdAndDates = menuRecipeDetailService.getByRecipeIdAndDatesAndIntervalId(this.recipeId, dates, this.mealtimeType);
|
||||
Map<LocalDate, MenuRecipeDetail> dateDetailMap = byRecipeIdAndDates.stream().collect(Collectors.groupingBy(MenuRecipeDetail::getApplyDate, Collectors.collectingAndThen(Collectors.toList(), (list) -> {
|
||||
return list.get(0);
|
||||
})));
|
||||
if (!this.dishesNames.isEmpty()) {
|
||||
IMenuDishesService menuDishesService = SpringContextHolder.getBean(IMenuDishesService.class);
|
||||
List<MenuDishes> menuDishesList = menuDishesService.getByNames(this.dishesNames);
|
||||
Map<String, MenuDishes> nameMap = menuDishesList.stream().collect(Collectors.groupingBy(MenuDishes::getDishesName, Collectors.collectingAndThen(Collectors.toList(), (list) -> {
|
||||
return list.get(0);
|
||||
})));
|
||||
IMenuRecipeDishesService menuRecipeDishesService = SpringContextHolder.getBean(IMenuRecipeDishesService.class);
|
||||
List<MenuRecipeDishes> inserData = new ArrayList<>();
|
||||
|
||||
for (LocalDate date : dates) {
|
||||
MenuRecipeDetail menuRecipeDetail = dateDetailMap.get(date);
|
||||
if (menuRecipeDetail == null) {
|
||||
menuRecipeDetail = new MenuRecipeDetail();
|
||||
menuRecipeDetail.setRecipeId(this.recipeId);
|
||||
menuRecipeDetail.setApplyDate(date);
|
||||
menuRecipeDetail.setMealtimeType(this.mealtimeType);
|
||||
menuRecipeDetail.setDetailId(Id.next());
|
||||
menuRecipeDetailService.save(menuRecipeDetail);
|
||||
} else {
|
||||
menuRecipeDishesService.deleteByDetailId(menuRecipeDetail.getDetailId());
|
||||
}
|
||||
|
||||
List<ImportRecipeDishesDto> importRecipeDishesDtos = this.datas.get(date);
|
||||
MenuRecipeDetail finalMenuRecipeDetail = menuRecipeDetail;
|
||||
List<MenuRecipeDishes> saveDatas = importRecipeDishesDtos.stream().filter(distinctByKey(ImportRecipeDishesDto::getDishesName)).map((importRecipeDishesDto) -> {
|
||||
MenuRecipeDishes menuRecipeDishes = null;
|
||||
MenuDishes menuDishes = nameMap.get(importRecipeDishesDto.getDishesName());
|
||||
if (menuDishes != null) {
|
||||
menuRecipeDishes = BeanUtil.copyProperties(importRecipeDishesDto, MenuRecipeDishes.class, new String[0]);
|
||||
menuRecipeDishes.setDetailId(finalMenuRecipeDetail.getDetailId());
|
||||
menuRecipeDishes.setSizeType(menuDishes.getSizeType());
|
||||
menuRecipeDishes.setDishesId(menuDishes.getDishesId());
|
||||
} else {
|
||||
this.notImportDishesNames.add(importRecipeDishesDto.getDishesName());
|
||||
}
|
||||
|
||||
return menuRecipeDishes;
|
||||
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
inserData.addAll(saveDatas);
|
||||
}
|
||||
|
||||
menuRecipeDishesService.saveBatch(inserData);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
|
||||
return (t) -> {
|
||||
return seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,12 +160,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<insert id="insertValues">
|
||||
INSERT INTO menu_recipe_dishes
|
||||
(detail_id, dishes_id, price, size_type, supply_num, sale_num, surplus_num,
|
||||
restrict_num, sale_price, recommend_flag, crby, crtime, upby, uptime, sort_num)
|
||||
restrict_num, sale_price, recommend_flag, create_by, create_time, update_by, update_time, sort_num)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator="," open="" close="">
|
||||
( #{item.detailId}, #{item.dishesId},#{item.price},#{item.sizeType},#{item.supplyNum},#{item.saleNum},#{item.surplusNum},
|
||||
#{item.restrictNum},#{item.salePrice},#{item.recommendFlag}
|
||||
,#{item.crby},#{item.crtime},#{item.upby},#{item.uptime},#{item.sortNum})
|
||||
,#{item.createBy},#{item.createTime},#{item.updateBy},#{item.updateTime},#{item.sortNum})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue