diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/controller/CookRecipeController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/controller/CookRecipeController.java index 44c4c23..3ff2fd0 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/controller/CookRecipeController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/controller/CookRecipeController.java @@ -4,6 +4,7 @@ import java.util.List; import javax.servlet.http.HttpServletResponse; 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.CookRecipeDTO; 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.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -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 org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; import com.bonus.common.log.annotation.SysLog; import com.bonus.canteen.core.cook.domain.CookRecipe; 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.utils.poi.ExcelUtil; import com.bonus.common.core.web.page.TableDataInfo; +import org.springframework.web.multipart.MultipartFile; /** * 菜品计划信息Controller @@ -148,6 +146,23 @@ public class CookRecipeController extends BaseController { 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); + } + } + /** * 删除菜品计划信息 */ diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookDishes.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookDishes.java index a5500bc..218be5e 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookDishes.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookDishes.java @@ -1,7 +1,9 @@ package com.bonus.canteen.core.cook.domain; import java.math.BigDecimal; +import java.util.HashSet; import java.util.List; +import java.util.Set; import com.bonus.canteen.core.common.utils.FileUrlUtil; import com.bonus.common.core.annotation.Excel; @@ -367,6 +369,8 @@ public class CookDishes extends BaseEntity { @ApiModelProperty(value = "菜品类型id集合") private List typeIds; + private Set dishesNames = new HashSet(); + public String getImageUrl() { return FileUrlUtil.getFileUrl(this.imageUrl); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/dto/ImportRecipeDishesDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/dto/ImportRecipeDishesDTO.java new file mode 100644 index 0000000..f65808d --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/dto/ImportRecipeDishesDTO.java @@ -0,0 +1,92 @@ +package com.bonus.canteen.core.cook.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; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDetailMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDetailMapper.java index b2c333c..4d68620 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDetailMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDetailMapper.java @@ -2,6 +2,8 @@ package com.bonus.canteen.core.cook.mapper; import java.time.LocalDate; import java.util.List; +import java.util.Set; + import com.bonus.canteen.core.cook.domain.CookRecipeDetail; import org.apache.ibatis.annotations.Param; @@ -73,4 +75,6 @@ public interface CookRecipeDetailMapper { List getCookRecipeDetailLTemplate(@Param("recipeId") Long recipeId, @Param("detailType") String detailType); + List getByRecipeIdAndDatesAndIntervalId(@Param("recipeId") Long recipeId, @Param("dateList") Set dateList, @Param("mealtimeType") Long mealtimeType); + } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java index 5b28781..b4aada5 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java @@ -70,7 +70,7 @@ public interface CookRecipeMapper { */ public int updateCookRecipe(CookRecipeDTO cookRecipeDTO); - List getDeviceIdByDevivce(@Param("canteenId")String canteenId, @Param("stallId")String stallId); + List getDeviceIdByDevice(@Param("canteenId")String canteenId, @Param("stallId")String stallId); List getDeviceSnByIds(@Param("list") List deviceInfoList); @@ -82,7 +82,8 @@ public interface CookRecipeMapper { int insertBind(CookAppRecipe appRecipe); - void updateRecipeByCanteenStallMeal(@Param("recipeId")String recipeId, @Param("canteenId")String canteenId, @Param("stallId")String stallId, @Param("deviceIds")List deviceIds); + void updateRecipeByCanteenStallMeal(@Param("recipeId")Long recipeId, @Param("canteenId")Long canteenId, + @Param("stallId")Long stallId, @Param("deviceIds")List deviceIds); /** * 删除菜品计划信息 diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/ICookRecipeService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/ICookRecipeService.java index 5672815..20d96cc 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/ICookRecipeService.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/ICookRecipeService.java @@ -1,12 +1,15 @@ package com.bonus.canteen.core.cook.service; import java.util.List; +import java.util.Set; + import com.bonus.canteen.core.cook.domain.CookRecipe; import com.bonus.canteen.core.cook.dto.CookRecipeBindDTO; import com.bonus.canteen.core.cook.dto.CookRecipeDTO; import com.bonus.canteen.core.cook.dto.CookRecipeDetailDTO; import com.bonus.canteen.core.cook.vo.CookRecipeDetailVO; import com.bonus.canteen.core.cook.vo.CookRecipeVO; +import org.springframework.web.multipart.MultipartFile; /** * 菜品计划信息Service接口 @@ -57,6 +60,8 @@ public interface ICookRecipeService { public void bindCookRecipe(CookRecipeBindDTO cookRecipeDTO); + public Set recipeImportDishes(MultipartFile excel, Long recipeId); + /** * 批量删除菜品计划信息 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java index 653fb25..e063511 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java @@ -9,19 +9,24 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; 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.MqUtil; import com.bonus.canteen.core.cook.domain.CookAppRecipe; import com.bonus.canteen.core.cook.domain.CookRecipeDetail; import com.bonus.canteen.core.cook.domain.CookRecipeDishes; import com.bonus.canteen.core.cook.dto.*; +import com.bonus.canteen.core.cook.enums.CookBindTypeEnum; import com.bonus.canteen.core.cook.enums.CookRecipeSortEnum; import com.bonus.canteen.core.cook.enums.RecipeDetailTypeEnum; import com.bonus.canteen.core.cook.enums.RecipeTypeEnum; import com.bonus.canteen.core.cook.mapper.CookRecipeDetailMapper; 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.user.domain.DeviceMqPersonalUpdateMessageDTO; import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.DateUtils; import com.bonus.common.houqin.constant.GlobalConstants; @@ -37,6 +42,7 @@ import com.bonus.canteen.core.cook.domain.CookRecipe; import com.bonus.canteen.core.cook.service.ICookRecipeService; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import org.springframework.web.multipart.MultipartFile; /** * 菜品计划信息Service业务层处理 @@ -118,14 +124,14 @@ public class CookRecipeServiceImpl implements ICookRecipeService { Map bindTypeMap = CookRecipeSortEnum.getKeyMap(); CookRecipeSortEnum sortEnum = bindTypeMap.get(content.getKey()); List records = new ArrayList<>(); - if (ObjectUtil.isEmpty(sortEnum)) { + if (Objects.isNull(sortEnum)) { throw new ServiceException("参数错误"); }else{ content.setDeviceTypeList(sortEnum.getDeviceType()); content.setBindType(sortEnum.getBindType()); content.setRecipeName(LeBeanUtil.fieldLikeHandle(content.getRecipeName())); records = cookRecipeMapper.selectCookRecipeListV2(content); - if (ObjectUtil.isNotEmpty(records)) { + if (!CollectionUtils.isEmpty(records)) { List recipeIds; Map maping; List stallIds = records.stream().map(CookRecipeVO::getStallId).collect(Collectors.toList()); @@ -155,9 +161,9 @@ public class CookRecipeServiceImpl implements ICookRecipeService { item.setRecipeDateList(Arrays.asList(cookRecipeDateVO)); item.setRecipeName(Optional.ofNullable(recipeMap.get(recipeId)).map(CookRecipe::getRecipeName).orElse(null)); count = 0L; - if (ObjectUtil.isNotEmpty(item.getRecipeDateDetail()) && ObjectUtil.isNotEmpty(item.getRecipeDateList().get(0).getDetailList())) { + if (Objects.nonNull(item.getRecipeDateDetail()) && !CollectionUtils.isEmpty(item.getRecipeDateList().get(0).getDetailList())) { count = item.getRecipeDateList().get(0).getDetailList().stream().filter((x) -> { - return ObjectUtil.isNotEmpty(x.getDishesList()); + return !CollectionUtils.isEmpty(x.getDishesList()); }).flatMap((x) -> { return x.getDishesList().stream(); }).map(CookRecipeDishesVO::getDishesId).distinct().count(); @@ -363,68 +369,99 @@ public class CookRecipeServiceImpl implements ICookRecipeService { } } - public void bindCookRecipe(CookRecipeBindDTO cookRecipeDTO) { - CookRecipe menuRecipe = this.cookRecipeMapper.selectCookRecipeByRecipeId(cookRecipeDTO.getRecipeId()); - List deviceInfoList = new ArrayList<>(); - List deviceSnList = new ArrayList<>(); - if(cookRecipeDTO.getStallId() !=null){ - deviceInfoList = this.cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(cookRecipeDTO.getStallId())); - if(deviceInfoList == null || deviceInfoList.isEmpty() || deviceInfoList.size() == 0){ - throw new ServiceException("该食堂档口下没有设备信息"); - } - deviceSnList = this.cookRecipeMapper.getDeviceSnByIds(deviceInfoList); - } - CookRecipeSortEnum sortEnum = CookRecipeSortEnum.getBindTypeMap().get(cookRecipeDTO.getBindType()); - CookAppRecipe mar = new CookAppRecipe(); - mar.setRecipeId(cookRecipeDTO.getRecipeId()); - mar.setMealLineId(cookRecipeDTO.getMealLineId()); - mar.setBindType(cookRecipeDTO.getBindType()); - List deviceTypeList = cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(menuRecipe.getStallId())); - if (ObjectUtil.isEmpty(sortEnum)) { - throw new ServiceException("bingType值异常"); + @Transactional(rollbackFor = {Exception.class}) + public void bindCookRecipe(CookRecipeBindDTO content) { + CookRecipe cookRecipe = this.cookRecipeMapper.selectCookRecipeByRecipeId(content.getRecipeId()); + CookRecipeSortEnum sortEnum = CookRecipeSortEnum.getBindTypeMap().get(content.getBindType()); + if (Objects.isNull(sortEnum)) { + throw new ServiceException("菜谱绑定类型错误"); } else { - List deviceTypes = sortEnum.getDeviceType(); - if (cookRecipeDTO.getHandleType().equals(1)) { - boolean exists; -// if (CookBindTypeEnum.RESERVE.key().equals(cookRecipeDTO.getBindType())) { -// exists = this.checkCanteenIfReserve(menuRecipe.getCanteenId(), menuRecipe.getStallId()); + List deviceIds = new ArrayList<>(); + if (CookBindTypeEnum.TABLE.key().equals(content.getBindType())) { //TABLE(7, "智慧餐台/消费机") + if (content.getStallId() != null) { + deviceIds = this.cookRecipeMapper.getDeviceIdByDevice(null, String.valueOf(content.getStallId())); + if (deviceIds == null || deviceIds.isEmpty() || deviceIds.size() == 0) { + throw new ServiceException("该食堂档口下没有设备信息"); + } + } + } + CookAppRecipe appRecipe = new CookAppRecipe(); + appRecipe.setRecipeId(content.getRecipeId()); + appRecipe.setMealLineId(content.getMealLineId()); + appRecipe.setBindType(content.getBindType()); + appRecipe.setBindTime(LocalDateTime.now()); + if (content.getHandleType().equals(1)) { +// if (CookBindTypeEnum.RESERVE.key().equals(content.getBindType())) { +// exists = this.allocCanteenApi.checkCanteenIfReserve(cookRecipe.getCanteenId(), cookRecipe.getStallId()); // if (!exists) { // throw new ServiceException("不支持预订餐"); // } // } - exists = this.cookRecipeMapper.checkIfAlreadyBind(mar); + boolean exists = this.cookRecipeMapper.checkIfAlreadyBind(appRecipe); if (exists) { throw new ServiceException("菜谱已被使用,请勿重复绑定"); } - List sourceRecipeList = this.cookRecipeMapper.selectRecipeInSameShop(menuRecipe.getStallId(), cookRecipeDTO.getBindType(), cookRecipeDTO.getMealLineId()); - if (ObjectUtil.isNotEmpty(sourceRecipeList)) { - mar.setRecipeIds(sourceRecipeList); - this.cookRecipeMapper.deleteBind(mar); + List sourceRecipeList = this.cookRecipeMapper.selectRecipeInSameShop(cookRecipe.getStallId(), content.getBindType(), content.getMealLineId()); + if (!CollectionUtils.isEmpty(sourceRecipeList)) { + appRecipe.setRecipeIds(sourceRecipeList); + this.cookRecipeMapper.deleteBind(appRecipe); } - CookAppRecipe appRecipe = new CookAppRecipe(); - appRecipe.setRecipeId(cookRecipeDTO.getRecipeId()); - appRecipe.setBindType(cookRecipeDTO.getBindType()); - appRecipe.setMealLineId(cookRecipeDTO.getMealLineId()); - appRecipe.setBindTime(LocalDateTime.now()); this.cookRecipeMapper.insertBind(appRecipe); - if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) { - this.cookRecipeMapper.updateRecipeByCanteenStallMeal(String.valueOf(cookRecipeDTO.getRecipeId()), String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()),deviceTypeList); + if (!CollectionUtils.isEmpty(deviceIds)) { + this.cookRecipeMapper.updateRecipeByCanteenStallMeal(content.getRecipeId(), cookRecipe.getCanteenId(), cookRecipe.getStallId(), deviceIds); } - MqUtil.sendDataChange(menuRecipe, LeMqConstant.DataChangeType.ADD, LeMqConstant.Topic.DATA_CHANGE_RECIPE_RELEASE); + MqUtil.sendDataChange(cookRecipe, LeMqConstant.DataChangeType.ADD, LeMqConstant.Topic.DATA_CHANGE_RECIPE_RELEASE); } else { - mar.setRecipeIds(Collections.singletonList(mar.getRecipeId())); - this.cookRecipeMapper.deleteBind(mar); - if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) { - this.cookRecipeMapper.updateRecipeByCanteenStallMeal("-1", String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()), deviceTypeList); + appRecipe.setRecipeIds(Collections.singletonList(appRecipe.getRecipeId())); + this.cookRecipeMapper.deleteBind(appRecipe); + if (!CollectionUtils.isEmpty(deviceIds)) { + this.cookRecipeMapper.updateRecipeByCanteenStallMeal(-1L, cookRecipe.getCanteenId(), cookRecipe.getStallId(), deviceIds); } } //发送mq - if (!CollectionUtils.isEmpty(deviceSnList)) { - for (String deviceSn : deviceSnList) { - DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0, cookRecipeDTO.getHandleType().equals(1) ? "update" : "del"); - MqUtil.pushToSingleDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_MENU_CONFIG_V4, deviceSn); +// if (CookBindTypeEnum.TABLE.key().equals(content.getBindType())) { //TABLE(7, "智慧餐台/消费机") +// List deviceSnList = this.cookRecipeMapper.getDeviceSnByIds(deviceInfoList); +// for (String deviceSn : deviceSnList) { +// DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0, content.getHandleType().equals(1) ? "update" : "del"); +// MqUtil.pushToSingleDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_MENU_CONFIG_V4, deviceSn); +// } +// } + } + } + + @Override + public Set recipeImportDishes(MultipartFile excel, Long recipeId) { + ExcelReader excelReader = null; + try { + Set notImportDishesNames = new HashSet(); + List listeners = new ArrayList(); + + excelReader = EasyExcel.read(excel.getInputStream()).build(); + List 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(); + } + } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/utils/CookRecipeImportListener.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/utils/CookRecipeImportListener.java new file mode 100644 index 0000000..7c4e39d --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/utils/CookRecipeImportListener.java @@ -0,0 +1,188 @@ +package com.bonus.canteen.core.cook.utils; + +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.cook.domain.CookDishes; +import com.bonus.canteen.core.cook.domain.CookRecipeDetail; +import com.bonus.canteen.core.cook.domain.CookRecipeDishes; +import com.bonus.canteen.core.cook.dto.ImportRecipeDishesDTO; +import com.bonus.canteen.core.cook.mapper.CookDishesMapper; +import com.bonus.canteen.core.cook.mapper.CookRecipeDetailMapper; +import com.bonus.canteen.core.cook.mapper.CookRecipeDishesMapper; +import com.bonus.common.core.exception.ServiceException; +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 CookRecipeImportListener extends AnalysisEventListener> { + private static final Logger log = LoggerFactory.getLogger(CookRecipeImportListener.class); + private final String sheetName; + private final Long recipeId; + private final Long mealtimeType; + private final Map dateMap = new HashMap(); + private final Set dishesNames = new HashSet(); + private final Set notImportDishesNames = new HashSet(); + private final Map> datas = new HashMap(); + private final BigDecimal decimal = new BigDecimal(100); + + public Set getNotImportDishesNames() { + return this.notImportDishesNames; + } + + public CookRecipeImportListener(String sheetName, Long recipeId, Long mealtimeType) { + this.sheetName = sheetName; + this.recipeId = recipeId; + this.mealtimeType = mealtimeType; + } + + @Override + public void invoke(Map 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 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) { + try { + HashSet dates = new HashSet(this.dateMap.values()); + if (!dates.isEmpty()) { + //ICookRecipeDetailService menuRecipeDetailService = SpringContextHolder.getBean(ICookRecipeDetailService.class); + CookRecipeDetailMapper cookRecipeDetailMapper = SpringContextHolder.getBean(CookRecipeDetailMapper.class); + CookRecipeDishesMapper cookRecipeDishesMapper = SpringContextHolder.getBean(CookRecipeDishesMapper.class); + //List byRecipeIdAndDates = menuRecipeDetailService.getByRecipeIdAndDatesAndIntervalId(this.recipeId, dates, this.mealtimeType); + List byRecipeIdAndDates = cookRecipeDetailMapper.getByRecipeIdAndDatesAndIntervalId(this.recipeId, dates, this.mealtimeType); + Map dateDetailMap = byRecipeIdAndDates.stream().collect(Collectors.groupingBy(CookRecipeDetail::getApplyDate, Collectors.collectingAndThen(Collectors.toList(), (list) -> { + return list.get(0); + }))); + if (!this.dishesNames.isEmpty()) { + //ICookDishesService menuDishesService = SpringContextHolder.getBean(ICookDishesService.class); + //List menuDishesList = menuDishesService.getByNames(this.dishesNames); + CookDishesMapper cookDishesMapper = SpringContextHolder.getBean(CookDishesMapper.class); + CookDishes cookDishes = new CookDishes(); + cookDishes.setDishesNames(this.dishesNames); + List cookDishesList = cookDishesMapper.selectCookDishesList(cookDishes); + + Set difference = DifferenceCalculator.calculateDifference(this.dishesNames, cookDishesList); + System.out.println("差集结果: " + difference); + if (difference != null && difference.size() > 0) { + throw new ServiceException("以下菜品不存在:" + difference); + } + Map nameMap = cookDishesList.stream().collect(Collectors.groupingBy(CookDishes::getDishesName, Collectors.collectingAndThen(Collectors.toList(), (list) -> { + return list.get(0); + }))); + //ICookRecipeDishesService menuRecipeDishesService = SpringContextHolder.getBean(ICookRecipeDishesService.class); + List inserData = new ArrayList<>(); + + for (LocalDate date : dates) { + CookRecipeDetail cookRecipeDetail = dateDetailMap.get(date); + if (cookRecipeDetail == null) { + cookRecipeDetail = new CookRecipeDetail(); + cookRecipeDetail.setRecipeId(this.recipeId); + cookRecipeDetail.setApplyDate(date); + cookRecipeDetail.setMealtimeType(this.mealtimeType); + //menuRecipeDetail.setDetailId(Id.next()); + //menuRecipeDetailService.save(menuRecipeDetail); + cookRecipeDetailMapper.insertCookRecipeDetail(cookRecipeDetail); + } else { + //menuRecipeDishesService.deleteByDetailId(menuRecipeDetail.getDetailId()); + Long[] recipeDetailIds = {cookRecipeDetail.getRecipeDetailId()}; + cookRecipeDishesMapper.deleteCookRecipeDishesByCookRecipeDetailIds(recipeDetailIds); + } + + List importRecipeDishesDtos = this.datas.get(date); + CookRecipeDetail finalCookRecipeDetail = cookRecipeDetail; + List saveDatas = importRecipeDishesDtos.stream().filter(distinctByKey(ImportRecipeDishesDTO::getDishesName)).map((importRecipeDishesDto) -> { + CookRecipeDishes cookRecipeDishes = null; + CookDishes cookDishesValue = nameMap.get(importRecipeDishesDto.getDishesName()); + if (cookDishesValue != null) { + cookRecipeDishes = BeanUtil.copyProperties(importRecipeDishesDto, CookRecipeDishes.class, new String[0]); + cookRecipeDishes.setRecipeDetailId(finalCookRecipeDetail.getRecipeDetailId()); + cookRecipeDishes.setSizeType(cookDishesValue.getSizeType()); + cookRecipeDishes.setDishesId(cookDishesValue.getDishesId()); + } else { + this.notImportDishesNames.add(importRecipeDishesDto.getDishesName()); + } + + return cookRecipeDishes; + }).filter(Objects::nonNull).collect(Collectors.toList()); + inserData.addAll(saveDatas); + } + + //menuRecipeDishesService.saveBatch(inserData); + for (CookRecipeDishes cookRecipeDishes : inserData) { + cookRecipeDishesMapper.insertCookRecipeDishes(cookRecipeDishes); + } + } + } + + }catch (Exception e){ + throw new ServiceException(e.getMessage()); + } + } + + static Predicate distinctByKey(Function keyExtractor) { + Map seen = new ConcurrentHashMap<>(); + return (t) -> { + return seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; + }; + } + +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/utils/DifferenceCalculator.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/utils/DifferenceCalculator.java new file mode 100644 index 0000000..8b962d5 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/utils/DifferenceCalculator.java @@ -0,0 +1,22 @@ +package com.bonus.canteen.core.cook.utils; + +import com.bonus.canteen.core.cook.domain.CookDishes; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class DifferenceCalculator { + public static Set calculateDifference(Set stringSet, List menuDishesList) { + // 从menuDishesList中提取所有dishesName的集合 + Set menuDishesNames = menuDishesList.stream() + .map(CookDishes::getDishesName) + .collect(Collectors.toSet()); + + // 计算差集:stringSet中有而menuDishesNames中没有的元素 + Set difference = new HashSet<>(stringSet); + difference.removeAll(menuDishesNames); + + return difference; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/controller/SupermarketProductController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/controller/SupermarketProductController.java new file mode 100644 index 0000000..f703fd2 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/controller/SupermarketProductController.java @@ -0,0 +1,119 @@ +package com.bonus.canteen.core.supermarket.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import com.bonus.common.log.enums.OperaType; +//import com.bonus.canteen.core.supermarket.common.annotation.PreventRepeatSubmit; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +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.security.annotation.RequiresPermissions; +import com.bonus.canteen.core.supermarket.domain.SupermarketProduct; +import com.bonus.canteen.core.supermarket.service.ISupermarketProductService; +import com.bonus.common.core.web.controller.BaseController; +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.core.utils.poi.ExcelUtil; +import com.bonus.common.core.web.page.TableDataInfo; + +/** + * 超市商城商品Controller + * + * @author xsheng + * @date 2025-06-03 + */ +@Api(tags = "超市商城商品接口") +@RestController +@RequestMapping("/supermarket_product") +public class SupermarketProductController extends BaseController { + @Autowired + private ISupermarketProductService supermarketProductService; + + /** + * 查询超市商城商品列表 + */ + @ApiOperation(value = "查询超市商城商品列表") + //@RequiresPermissions("supermarket:product:list") + @GetMapping("/list") + public TableDataInfo list(SupermarketProduct supermarketProduct) { + startPage(); + List list = supermarketProductService.selectSupermarketProductList(supermarketProduct); + return getDataTable(list); + } + + /** + * 导出超市商城商品列表 + */ + @ApiOperation(value = "导出超市商城商品列表") + //@PreventRepeatSubmit + //@RequiresPermissions("supermarket:product:export") + @SysLog(title = "超市商城商品", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出超市商城商品") + @PostMapping("/export") + public void export(HttpServletResponse response, SupermarketProduct supermarketProduct) { + List list = supermarketProductService.selectSupermarketProductList(supermarketProduct); + ExcelUtil util = new ExcelUtil(SupermarketProduct.class); + util.exportExcel(response, list, "超市商城商品数据"); + } + + /** + * 获取超市商城商品详细信息 + */ + @ApiOperation(value = "获取超市商城商品详细信息") + //@RequiresPermissions("supermarket:product:query") + @GetMapping(value = "/{productId}") + public AjaxResult getInfo(@PathVariable("productId") Long productId) { + return success(supermarketProductService.selectSupermarketProductByProductId(productId)); + } + + /** + * 新增超市商城商品 + */ + @ApiOperation(value = "新增超市商城商品") + //@PreventRepeatSubmit + //@RequiresPermissions("supermarket:product:add") + @SysLog(title = "超市商城商品", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增超市商城商品") + @PostMapping + public AjaxResult add(@RequestBody SupermarketProduct supermarketProduct) { + try { + return toAjax(supermarketProductService.insertSupermarketProduct(supermarketProduct)); + } catch (Exception e) { + return error(e.getMessage()); + } + } + + /** + * 修改超市商城商品 + */ + @ApiOperation(value = "修改超市商城商品") + //@PreventRepeatSubmit + //@RequiresPermissions("supermarket:product:edit") + @SysLog(title = "超市商城商品", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改超市商城商品") + @PostMapping("/edit") + public AjaxResult edit(@RequestBody SupermarketProduct supermarketProduct) { + try { + return toAjax(supermarketProductService.updateSupermarketProduct(supermarketProduct)); + } catch (Exception e) { + return error(e.getMessage()); + } + } + + /** + * 删除超市商城商品 + */ + @ApiOperation(value = "删除超市商城商品") + //@PreventRepeatSubmit + //@RequiresPermissions("supermarket:product:remove") + @SysLog(title = "超市商城商品", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除超市商城商品") + @PostMapping("/del/{productIds}") + public AjaxResult remove(@PathVariable Long[] productIds) { + return toAjax(supermarketProductService.deleteSupermarketProductByProductIds(productIds)); + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/domain/SupermarketProduct.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/domain/SupermarketProduct.java new file mode 100644 index 0000000..29dc834 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/domain/SupermarketProduct.java @@ -0,0 +1,77 @@ +package com.bonus.canteen.core.supermarket.domain; + +import java.math.BigDecimal; +import com.bonus.common.core.annotation.Excel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; +import com.bonus.common.core.web.domain.BaseEntity; + +/** + * 超市商城商品对象 supermarket_product + * + * @author xsheng + * @date 2025-06-03 + */ + + +@Data +@ToString +public class SupermarketProduct extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** 商城商品明细id */ + private Long productId; + + /** 超市id */ + @Excel(name = "超市id") + @ApiModelProperty(value = "超市id") + private Long supermarketId; + + /** 商品id */ + @Excel(name = "商品id") + @ApiModelProperty(value = "商品id") + private Long materialId; + + /** 上架状态(1-上架,2-下架) */ + @Excel(name = "上架状态(1-上架,2-下架)") + @ApiModelProperty(value = "上架状态(1-上架,2-下架)") + private Long putawayState; + + /** 是否线上销售(1是2否) */ + @Excel(name = "是否线上销售(1是2否)") + @ApiModelProperty(value = "是否线上销售(1是2否)") + private Long ifOnline; + + /** 销售价 */ + @Excel(name = "销售价") + @ApiModelProperty(value = "销售价") + private Long salePrice; + + /** 优惠价 */ + @Excel(name = "优惠价") + @ApiModelProperty(value = "优惠价") + private Long prefPrice; + + /** 个人限购数量 */ + @Excel(name = "个人限购数量") + @ApiModelProperty(value = "个人限购数量") + private Long personLimit; + + /** 每日限购数量 */ + @Excel(name = "每日限购数量") + @ApiModelProperty(value = "每日限购数量") + private Long oneDayLimit; + + /** 图片 */ + @Excel(name = "图片") + @ApiModelProperty(value = "图片") + private String imgUrl; + + /** 库存数 */ + @Excel(name = "库存数") + @ApiModelProperty(value = "库存数") + private BigDecimal inventoryNum; + + +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketProductMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketProductMapper.java new file mode 100644 index 0000000..a7f4edb --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/mapper/SupermarketProductMapper.java @@ -0,0 +1,60 @@ +package com.bonus.canteen.core.supermarket.mapper; + +import java.util.List; +import com.bonus.canteen.core.supermarket.domain.SupermarketProduct; + +/** + * 超市商城商品Mapper接口 + * + * @author xsheng + * @date 2025-06-03 + */ +public interface SupermarketProductMapper { + /** + * 查询超市商城商品 + * + * @param productId 超市商城商品主键 + * @return 超市商城商品 + */ + public SupermarketProduct selectSupermarketProductByProductId(Long productId); + + /** + * 查询超市商城商品列表 + * + * @param supermarketProduct 超市商城商品 + * @return 超市商城商品集合 + */ + public List selectSupermarketProductList(SupermarketProduct supermarketProduct); + + /** + * 新增超市商城商品 + * + * @param supermarketProduct 超市商城商品 + * @return 结果 + */ + public int insertSupermarketProduct(SupermarketProduct supermarketProduct); + + /** + * 修改超市商城商品 + * + * @param supermarketProduct 超市商城商品 + * @return 结果 + */ + public int updateSupermarketProduct(SupermarketProduct supermarketProduct); + + /** + * 删除超市商城商品 + * + * @param productId 超市商城商品主键 + * @return 结果 + */ + public int deleteSupermarketProductByProductId(Long productId); + + /** + * 批量删除超市商城商品 + * + * @param productIds 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteSupermarketProductByProductIds(Long[] productIds); +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/ISupermarketProductService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/ISupermarketProductService.java new file mode 100644 index 0000000..8dd3a6f --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/ISupermarketProductService.java @@ -0,0 +1,60 @@ +package com.bonus.canteen.core.supermarket.service; + +import java.util.List; +import com.bonus.canteen.core.supermarket.domain.SupermarketProduct; + +/** + * 超市商城商品Service接口 + * + * @author xsheng + * @date 2025-06-03 + */ +public interface ISupermarketProductService { + /** + * 查询超市商城商品 + * + * @param productId 超市商城商品主键 + * @return 超市商城商品 + */ + public SupermarketProduct selectSupermarketProductByProductId(Long productId); + + /** + * 查询超市商城商品列表 + * + * @param supermarketProduct 超市商城商品 + * @return 超市商城商品集合 + */ + public List selectSupermarketProductList(SupermarketProduct supermarketProduct); + + /** + * 新增超市商城商品 + * + * @param supermarketProduct 超市商城商品 + * @return 结果 + */ + public int insertSupermarketProduct(SupermarketProduct supermarketProduct); + + /** + * 修改超市商城商品 + * + * @param supermarketProduct 超市商城商品 + * @return 结果 + */ + public int updateSupermarketProduct(SupermarketProduct supermarketProduct); + + /** + * 批量删除超市商城商品 + * + * @param productIds 需要删除的超市商城商品主键集合 + * @return 结果 + */ + public int deleteSupermarketProductByProductIds(Long[] productIds); + + /** + * 删除超市商城商品信息 + * + * @param productId 超市商城商品主键 + * @return 结果 + */ + public int deleteSupermarketProductByProductId(Long productId); +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketProductServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketProductServiceImpl.java new file mode 100644 index 0000000..ce92ecd --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/supermarket/service/impl/SupermarketProductServiceImpl.java @@ -0,0 +1,98 @@ +package com.bonus.canteen.core.supermarket.service.impl; + +import java.util.List; +import com.bonus.common.core.exception.ServiceException; +import com.bonus.common.core.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.bonus.canteen.core.supermarket.mapper.SupermarketProductMapper; +import com.bonus.canteen.core.supermarket.domain.SupermarketProduct; +import com.bonus.canteen.core.supermarket.service.ISupermarketProductService; + +/** + * 超市商城商品Service业务层处理 + * + * @author xsheng + * @date 2025-06-03 + */ +@Service +public class SupermarketProductServiceImpl implements ISupermarketProductService { + @Autowired + private SupermarketProductMapper supermarketProductMapper; + + /** + * 查询超市商城商品 + * + * @param productId 超市商城商品主键 + * @return 超市商城商品 + */ + @Override + public SupermarketProduct selectSupermarketProductByProductId(Long productId) { + return supermarketProductMapper.selectSupermarketProductByProductId(productId); + } + + /** + * 查询超市商城商品列表 + * + * @param supermarketProduct 超市商城商品 + * @return 超市商城商品 + */ + @Override + public List selectSupermarketProductList(SupermarketProduct supermarketProduct) { + return supermarketProductMapper.selectSupermarketProductList(supermarketProduct); + } + + /** + * 新增超市商城商品 + * + * @param supermarketProduct 超市商城商品 + * @return 结果 + */ + @Override + public int insertSupermarketProduct(SupermarketProduct supermarketProduct) { + supermarketProduct.setCreateTime(DateUtils.getNowDate()); + try { + return supermarketProductMapper.insertSupermarketProduct(supermarketProduct); + } catch (Exception e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * 修改超市商城商品 + * + * @param supermarketProduct 超市商城商品 + * @return 结果 + */ + @Override + public int updateSupermarketProduct(SupermarketProduct supermarketProduct) { + supermarketProduct.setUpdateTime(DateUtils.getNowDate()); + try { + return supermarketProductMapper.updateSupermarketProduct(supermarketProduct); + } catch (Exception e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * 批量删除超市商城商品 + * + * @param productIds 需要删除的超市商城商品主键 + * @return 结果 + */ + @Override + public int deleteSupermarketProductByProductIds(Long[] productIds) { + return supermarketProductMapper.deleteSupermarketProductByProductIds(productIds); + } + + /** + * 删除超市商城商品信息 + * + * @param productId 超市商城商品主键 + * @return 结果 + */ + @Override + public int deleteSupermarketProductByProductId(Long productId) { + return supermarketProductMapper.deleteSupermarketProductByProductId(productId); + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesMapper.xml index 3ea3d99..3751faf 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesMapper.xml @@ -105,6 +105,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{typeId} + + + #{dishesName} + + and cd.meal_type = #{mealType} and cd.custom_id = #{customId} and cd.inventory_id = #{inventoryId} diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDetailMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDetailMapper.xml index d151e29..857ba90 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDetailMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDetailMapper.xml @@ -157,4 +157,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and detail_type = #{detailType} group by mealtime_type + + diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml index 4f0950d..7af8991 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml @@ -294,7 +294,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where recipe_id = #{recipeId} - select a.device_id from device_info a LEFT JOIN cook_recipe_bind_device b on a.device_id = b.device_id diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketProductMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketProductMapper.xml new file mode 100644 index 0000000..c202325 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/supermarket/SupermarketProductMapper.xml @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + select product_id, supermarket_id, material_id, putaway_state, if_online, sale_price, pref_price, person_limit, one_day_limit, img_url, inventory_num, create_by, create_time, update_by, update_time from supermarket_product + + + + + + + + insert into supermarket_product + + supermarket_id, + material_id, + putaway_state, + if_online, + sale_price, + pref_price, + person_limit, + one_day_limit, + img_url, + inventory_num, + create_by, + create_time, + update_by, + update_time, + + + #{supermarketId}, + #{materialId}, + #{putawayState}, + #{ifOnline}, + #{salePrice}, + #{prefPrice}, + #{personLimit}, + #{oneDayLimit}, + #{imgUrl}, + #{inventoryNum}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + update supermarket_product + + supermarket_id = #{supermarketId}, + material_id = #{materialId}, + putaway_state = #{putawayState}, + if_online = #{ifOnline}, + sale_price = #{salePrice}, + pref_price = #{prefPrice}, + person_limit = #{personLimit}, + one_day_limit = #{oneDayLimit}, + img_url = #{imgUrl}, + inventory_num = #{inventoryNum}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where product_id = #{productId} + + + + delete from supermarket_product where product_id = #{productId} + + + + delete from supermarket_product where product_id in + + #{productId} + + + \ No newline at end of file