package com.bonus.canteen.core.menuai.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bonus.canteen.core.allocation.api.AllocCanteenApi;
import com.bonus.canteen.core.common.constant.LeMqConstant;
import com.bonus.canteen.core.common.enums.AllocMealtimeTypeEnum;
import com.bonus.canteen.core.common.redis.RedisUtil;
import com.bonus.canteen.core.common.utils.SysUtil;
import com.bonus.canteen.core.common.utils.TenantContextHolder;
import com.bonus.canteen.core.menu.entity.MenuDishes;
import com.bonus.canteen.core.menu.entity.MenuRecipe;
import com.bonus.canteen.core.menu.mapper.MenuDishesMapper;
import com.bonus.canteen.core.menu.mapper.MenuRecipeMapper;
import com.bonus.canteen.core.menuai.constants.MenuaiContants;
import com.bonus.canteen.core.menuai.constants.PictureTypeEnum;
import com.bonus.canteen.core.menuai.entity.MenuaiPicture;
import com.bonus.canteen.core.menuai.mapper.MenuaiPictureMapper;
import com.bonus.canteen.core.menuai.model.MenuaiRemoveModel;
import com.bonus.canteen.core.menuai.service.MenuaiV4Service;
import com.bonus.canteen.core.merchant.dto.MenuaiPictureRemoveDTO;
import com.bonus.canteen.core.order.mq.MqUtil;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.houqin.constant.LeConstants;
import com.bonus.common.houqin.oss.OssProperties;
import com.bonus.common.houqin.oss.service.OssTemplate;
import com.google.common.collect.Maps;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.SerializedLambda;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Service
public class MenuaiV4ServiceImpl implements MenuaiV4Service {
   private static final Logger log = LoggerFactory.getLogger(MenuaiV4ServiceImpl.class);
//   @Autowired
//   private MenuaiV2Service menuaiV2Service;
   @Resource
   private MenuaiPictureMapper menuaiPictureMapper;
//   @Autowired
//   private MenuaiMapper menuaiMapper;
//   @Autowired
//   private MenuDishesMapper menuDishesMapper;
//   @Autowired
//   private AllocCanteenApi allocCanteenApi;
   @Resource
   private OssProperties ossProperties;
   @Resource
   private OssTemplate ossTemplate;
//   @Autowired
//   private MenuaiRegisterDishesMapper menuaiRegisterDishesMapper;
//   @Autowired
//   private MenuaiSyncRecordMapper menuaiSyncRecordMapper;
//   @Autowired
//   private MenuaiPictureService menuaiPictureService;
//   @Autowired
//   private MenuaiRegisterMapper menuaiRegisterMapper;
//   @Autowired
//   private StringRedisTemplate stringRedisTemplate;
//   @Resource(
//      name = "yunshitangTaskExecutor"
//   )
//   private AsyncTaskExecutor asyncTaskExecutor;
//   @Autowired
//   private MenuRecipeMapper menuRecipeMapper;
//   @Autowired
//   @Lazy
//   private MenuDishesAiConfigService menuDishesAiConfigService;
//   @Resource
//   @Qualifier("menuDishesPictureBaseService")
//   private MenuDishesPictureBaseService menuDishesPictureBaseService;
//
//   public List<MenuaiRemoveModel> uploadBigPicture(MultipartFile multipartFile, MenuaiUploadBigPictureDTO content, String cutPictureResult) {
//      Long stallId = content.getStallId();
//      Long dishesId = content.getDishesId();
//      String suffix = CharSequenceUtil.subAfter(multipartFile.getOriginalFilename(), ".", false);
//      String bigFileName = "" + dishesId + "_b_" + Id.next() + "." + suffix;
//      MenuaiStallModel stallModel = this.allocCanteenApi.getStallDetail(stallId);
//      log.info("档口id: {},获取到的编号信息详情: {}", stallId, stallModel);
//      String areaNum = stallModel.getAreaNum();
//      String canteenNum = stallModel.getCanteenNum();
//      String stallNum = stallModel.getStallNum();
//      String filePreFix = "/menuai/" + TenantContextHolder.getTenantId() + "/" + areaNum + "/" + canteenNum + "/" + stallNum + "/dishes/" + dishesId;
//      String bigFilePrefix = filePreFix + "/b/";
//      String smallFilePrefix = filePreFix + "/s/";
//      File bigPictureFile = new File(bigFileName);
//
//      try {
//         InputStream bigInputStream = multipartFile.getInputStream();
//         FileUtils.copyInputStreamToFile(bigInputStream, bigPictureFile);
//      } catch (IOException var31) {
//         log.info("文件转换异常: ", var31);
//         throw new LeException("文件转换异常 ^_^");
//      }
//
//      String dishesName = this.menuDishesMapper.selectDishesNameByWrapper((Wrapper)Wrappers.lambdaQuery(MenuDishes.class).eq(MenuDishes::getDishesId, dishesId));
//      Long var10000 = content.getDishesId();
//      String dishesFlag = "" + var10000 + "_" + dishesName.replace("/", "").replace(" ", "").replace(".", "");
//      if (CharSequenceUtil.isBlank(cutPictureResult)) {
//         throw new LeException("算法服务器返回异常 ^_^");
//      } else {
//         log.info("***算法服务器上传大图返回结果cutPictureResult: {}", cutPictureResult);
//         JSONObject cutJsonObject = JSON.parseObject(cutPictureResult);
//         this.menuaiV2Service.insertSyncRecord("", content.getCanteenId(), stallId, dishesId, dishesName, PictureTypeEnum.BIG_PICTURE.getKey(), bigFileName, OperateTypeEnum.UPLOAD_BIG_PIC.key());
//         JSONArray coordinates = cutJsonObject.getJSONArray("coordinates");
//         JSONArray filenames = cutJsonObject.getJSONArray("filenames");
//         List<ImageValueModel> coordList = Lists.newArrayList();
//
//         for(int i = 0; i < coordinates.size(); ++i) {
//            ImageValueModel imageValueModel = new ImageValueModel();
//            JSONArray dishes = (JSONArray)coordinates.get(i);
//            String pictureName = (String)filenames.get(i);
//            int x1 = dishes.getIntValue(0);
//            int y1 = dishes.getIntValue(1);
//            int x2 = dishes.getIntValue(2);
//            int y2 = dishes.getIntValue(3);
//            imageValueModel.setX(x1);
//            imageValueModel.setY(y1);
//            imageValueModel.setWidth(x2 - x1);
//            imageValueModel.setHeight(y2 - y1);
//            imageValueModel.setPictureName(pictureName);
//            coordList.add(imageValueModel);
//         }
//
//         List<MenuaiPictureModel> smallPictureList = Lists.newArrayList();
//         List<File> smallFileList = Lists.newArrayList();
//         coordList.forEach((c) -> {
//            String smallFileName = "" + dishesId + "_s_" + Id.next() + "." + suffix;
//            File smallFile = new File(smallFileName);
//
//            try {
//               BufferedImage read = ImageIO.read(bigPictureFile);
//               BufferedImage image = read.getSubimage(c.getX(), c.getY(), c.getWidth(), c.getHeight());
//               String fileName = bigPictureFile.getName();
//               String formatName = fileName.substring(fileName.lastIndexOf(".") + 1);
//               ImageIO.write(image, formatName, smallFile);
//               FileInputStream smallInput = new FileInputStream(smallFile);
//               MultipartFile smallMultipartFile = new MockMultipartFile("file", smallFile.getName(), "text/plain", IOUtils.toByteArray(smallInput));
//               MenuaiPictureModel pictureModel = new MenuaiPictureModel();
//               pictureModel.setFileName(smallFileName);
//               pictureModel.setMultipartFile(smallMultipartFile);
//               pictureModel.setPictureName(c.getPictureName());
//               smallFileList.add(smallFile);
//               smallPictureList.add(pictureModel);
//               smallInput.close();
//            } catch (IOException var18) {
//               log.info("裁剪图片异常: ", var18);
//               throw new LeException("裁剪图片异常 ^_^");
//            } finally {
//               smallFile.delete();
//            }
//
//         });
//         boolean delete = bigPictureFile.delete();
//         log.info("***临时文件删除结果: {}", delete);
//
//         try {
//            this.ossTemplate.putObject(this.ossProperties.getBucketName(), bigFilePrefix + bigFileName, multipartFile.getInputStream());
//            Iterator var36 = smallPictureList.iterator();
//
//            while(var36.hasNext()) {
//               MenuaiPictureModel pictureModel = (MenuaiPictureModel)var36.next();
//               this.ossTemplate.putObject(this.ossProperties.getBucketName(), smallFilePrefix + pictureModel.getFileName(), pictureModel.getMultipartFile().getInputStream());
//            }
//         } catch (Exception var32) {
//            log.info("上传图片异常: ", var32);
//            throw new LeException("上传图片异常 ^_^");
//         }
//
//         MenuaiPicture bigPicture = new MenuaiPicture();
//         Long bigPictureId = Id.next();
//         bigPicture.setId(bigPictureId);
//         bigPicture.setStallId(MenuaiContants.COMMON_STALL_ID);
//         bigPicture.setDishesId(dishesId);
//         String bigPictureUrl = "/" + this.ossProperties.getBucketName() + bigFilePrefix + bigFileName;
//         bigPicture.setPictureUrl(bigPictureUrl);
//         bigPicture.setPictureType(PictureTypeEnum.BIG_PICTURE.getKey());
//         this.menuaiPictureMapper.insert(bigPicture);
//         smallPictureList.forEach((s) -> {
//            MenuaiPicture smallPicture = new MenuaiPicture();
//            Long smallPictureId = Id.next();
//            smallPicture.setId(smallPictureId);
//            smallPicture.setPictureName(s.getPictureName());
//            smallPicture.setStallId(MenuaiContants.COMMON_STALL_ID);
//            smallPicture.setDishesId(dishesId);
//            String smallPictureUrl = "/" + this.ossProperties.getBucketName() + smallFilePrefix + s.getFileName();
//            smallPicture.setPictureUrl(smallPictureUrl);
//            smallPicture.setPictureType(PictureTypeEnum.SMALL_PICTURE.getKey());
//            smallPicture.setBigPictureId(bigPictureId);
//            this.menuaiPictureMapper.insert(smallPicture);
//         });
//         return this.deleteLimitPic(MenuaiContants.COMMON_STALL_ID, content.getDishesId(), dishesFlag);
//      }
//   }
//
//   public String getDishesFlag(Long dishesId) {
//      String dishesName = this.menuDishesMapper.selectDishesNameByWrapper((Wrapper)Wrappers.lambdaQuery(MenuDishes.class).eq(MenuDishes::getDishesId, dishesId));
//      Assert.notNull(dishesName, () -> {
//         return new LeException("菜品不存在");
//      });
//      return "" + dishesId + "_" + dishesName.replace("/", "").replace(" ", "").replace(".", "");
//   }
//
//   public void uploadEmptyTray(MultipartFile file, Long canteenId, Long stallId, ActionSourceTypeEnum sourceTypeEnum) {
//      String suffix = CharSequenceUtil.subAfter(file.getOriginalFilename(), ".", false);
//      long var10000 = Id.next();
//      String fileName = "空托盘_" + var10000 + "." + suffix;
//      MenuaiStallModel stallModel = this.allocCanteenApi.getStallDetail(stallId);
//      String areaNum = stallModel.getAreaNum();
//      String canteenNum = stallModel.getCanteenNum();
//      String stallNum = stallModel.getStallNum();
//      String filePrefix = "/menuai/" + TenantContextHolder.getTenantId() + "/" + areaNum + "/" + canteenNum + "/" + stallNum + "/tray/";
//
//      try {
//         this.ossTemplate.putObject(this.ossProperties.getBucketName(), filePrefix + fileName, file.getInputStream());
//      } catch (Exception var14) {
//         log.info("***空托盘图片保存异常: ", var14);
//         throw new LeException("空托盘图片保存异常 ^_^");
//      }
//
//      String filePath = "/" + this.ossProperties.getBucketName() + "/" + filePrefix + fileName;
//      if (ActionSourceTypeEnum.WEB.equals(sourceTypeEnum)) {
//         Map<String, String> uploadParamMap = Maps.newHashMap();
//         uploadParamMap.put("type", "tray");
//         uploadParamMap.put("food", "10000");
//         uploadParamMap.put("uid", String.valueOf(stallId));
//         uploadParamMap.put("file", SysUtil.getCutFileUrl(filePath));
//         uploadParamMap.put("action", "uploadEmptyTray");
//         MqUtil.pushToTenantAllDevice(uploadParamMap, LeMqConstant.Topic.AI_GATEWAY_MQTT);
//      }
//
//      this.menuaiV2Service.insertSyncRecord("", canteenId, stallId, 10000L, "空托盘", PictureTypeEnum.TRAY_PICTURE.getKey(), fileName, OperateTypeEnum.UPLOAD_EMPTY_TRAY.key());
//      MenuaiPicture picture = new MenuaiPicture();
//      picture.setId(Id.next());
//      picture.setPictureName("");
//      picture.setStallId(stallId);
//      picture.setDishesId(10000L);
//      picture.setPictureUrl(filePath);
//      picture.setPictureType(PictureTypeEnum.TRAY_PICTURE.getKey());
//      this.menuaiPictureMapper.insert(picture);
//   }
//
//   public MenuaiQueryRegistResultVO packageRegister(MenuaiRegisterSaasDTO content) {
//      Long stallId = content.getShopstallId();
//      Long intervalId = content.getIntervalId();
//      Long recipeId = content.getRecipeId();
//      boolean exists = this.menuaiPictureMapper.exists((Wrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(MenuaiPicture.class).eq(MenuaiPicture::getStallId, stallId)).eq(MenuaiPicture::getDishesId, 10000L));
//      if (!exists) {
//         throw new LeException("空托盘图片不存在 ^_^");
//      } else {
//         List<MenuaiRegisterDishesModel> dishesModelList = this.menuDishesMapper.selectRegisterDishes(recipeId, intervalId.intValue(), stallId);
//         if (CollUtil.isEmpty(dishesModelList)) {
//            throw new LeException("未查询到需要注册的菜品 ^_^");
//         } else {
//            Map<String, Object> registerParamMap = Maps.newHashMap();
//            String requestId = "" + stallId + "_" + recipeId + "_" + intervalId;
//            registerParamMap.put("requestId", requestId);
//            registerParamMap.put("uid", String.valueOf(stallId));
//            String intervalName = AllocMealtimeTypeEnum.getDescByKey(intervalId.intValue());
//            registerParamMap.put("model", intervalName);
//            Map<String, String> dishesMap = Maps.newHashMap();
//            dishesModelList.forEach((d) -> {
//               Long var10000 = d.getDishesId();
//               String dishesFlag = "" + var10000 + "_" + d.getDishesName().replace("/", "").replace(" ", "").replace(".", "");
//               dishesMap.put(dishesFlag, dishesFlag);
//            });
//            registerParamMap.put("food", dishesMap);
//            registerParamMap.put("expiredTime", LocalDateTime.now().plusMinutes(5L).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//            LocalDateTime registerTime = LocalDateTime.now();
//            MenuaiRegister register = (MenuaiRegister)this.menuaiRegisterMapper.selectOne((Wrapper)((LambdaQueryWrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(MenuaiRegister.class).eq(MenuaiRegister::getRecipeId, recipeId)).eq(MenuaiRegister::getServerAddress, "")).eq(MenuaiRegister::getMealtimeType, intervalId.intValue()));
//            Integer dishesNum = dishesModelList.size();
//            Integer pictureNum = dishesModelList.stream().mapToInt(MenuaiRegisterDishesModel::getPictureNum).sum();
//            Long registerId;
//            if (ObjectUtil.isNull(register)) {
//               registerId = Id.next();
//               MenuaiRegister insertRegister = new MenuaiRegister();
//               insertRegister.setId(registerId);
//               insertRegister.setRecipeId(recipeId);
//               insertRegister.setServerAddress("");
//               insertRegister.setMealtimeType(intervalId.intValue());
//               insertRegister.setRegisterTime(registerTime);
//               insertRegister.setRegisterState(RegisterStateEnum.REGISTERING.getKey());
//               insertRegister.setRegisterMsg("注册中");
//               insertRegister.setCostTime("");
//               insertRegister.setRegisterNum(dishesModelList.size());
//               insertRegister.setSuccNum(dishesNum);
//               insertRegister.setPictureNum(pictureNum);
//               insertRegister.setRequestId(requestId);
//               this.menuaiRegisterMapper.insert(insertRegister);
//            } else {
//               registerId = register.getId();
//               this.menuaiRegisterMapper.update((Object)null, (Wrapper)((LambdaUpdateWrapper)((LambdaUpdateWrapper)((LambdaUpdateWrapper)((LambdaUpdateWrapper)((LambdaUpdateWrapper)((LambdaUpdateWrapper)((LambdaUpdateWrapper)((LambdaUpdateWrapper)Wrappers.lambdaUpdate(MenuaiRegister.class).eq(MenuaiRegister::getId, registerId)).set(MenuaiRegister::getRegisterTime, registerTime)).set(MenuaiRegister::getRegisterState, RegisterStateEnum.REGISTERING.getKey())).set(MenuaiRegister::getRegisterMsg, "注册中")).set(MenuaiRegister::getCostTime, "")).set(MenuaiRegister::getRegisterNum, dishesModelList.size())).set(MenuaiRegister::getSuccNum, dishesNum)).set(MenuaiRegister::getPictureNum, pictureNum)).set(MenuaiRegister::getRequestId, requestId));
//            }
//
//            this.menuaiRegisterDishesMapper.delete((Wrapper)Wrappers.lambdaQuery(MenuaiRegisterDishes.class).eq(MenuaiRegisterDishes::getRegisterId, registerId));
//            dishesModelList.forEach((d) -> {
//               MenuaiRegisterDishes registerDishes = new MenuaiRegisterDishes();
//               registerDishes.setRegisterId(registerId);
//               registerDishes.setDishesId(d.getDishesId());
//               registerDishes.setRegisterState(RegisterStateEnum.REGISTERING.getKey());
//               this.menuaiRegisterDishesMapper.insert(registerDishes);
//            });
//            MenuaiQueryRegistResultVO result = new MenuaiQueryRegistResultVO();
//            result.setRegisterId(registerId);
//            result.setRegisterParamMap(registerParamMap);
//            return result;
//         }
//      }
//   }
//
//   public MenuaiQueryRegistResultVO queryRegistResult(MenuaiQueryRegistResultDTO content) {
//      MenuaiRegister register = (MenuaiRegister)this.menuaiRegisterMapper.selectOne((Wrapper)Wrappers.lambdaQuery(MenuaiRegister.class).eq(MenuaiRegister::getId, content.getRegisterId()));
//      if (ObjectUtil.isNull(register)) {
//         throw new LeException("注册失败");
//      } else if (RegisterStateEnum.SUCCESS.getKey().equals(register.getRegisterState())) {
//         LocalDateTime registerTime = register.getRegisterTime();
//         LocalDateTime registerEndTime = registerTime.plus((new BigDecimal(register.getCostTime())).longValue(), ChronoUnit.SECONDS);
//         long registerMillis = Duration.between(registerTime, registerEndTime).toMillis();
//         log.info("***菜品注册总耗时: {}", registerMillis);
//         List<Long> dishesIdList = this.menuaiRegisterDishesMapper.selectDishesIdList((Wrapper)Wrappers.lambdaQuery(MenuaiRegisterDishes.class).eq(MenuaiRegisterDishes::getRegisterId, content.getRegisterId()));
//         MenuaiQueryRegistResultVO result = new MenuaiQueryRegistResultVO();
//         result.setRegistDishesNum(dishesIdList.size());
//         result.setSuccessDishesNum(dishesIdList.size());
//         result.setResult("成功");
//         result.setRequestId(register.getRequestId());
//         result.setUseTime(register.getCostTime());
//         result.setRegistEndTime(registerEndTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//         return result;
//      } else if (RegisterStateEnum.FAIL.getKey().equals(register.getRegisterState())) {
//         throw new LeException("注册失败");
//      } else if (RegisterStateEnum.REGISTERING.getKey().equals(register.getRegisterState())) {
//         throw new LeException(57081, "注册中");
//      } else if (RegisterStateEnum.CANCELED.getKey().equals(register.getRegisterState())) {
//         throw new LeException("注册中");
//      } else if (RegisterStateEnum.TIMEOUT.getKey().equals(register.getRegisterState())) {
//         throw new LeException("注册超时");
//      } else {
//         throw new LeException("注册中");
//      }
//   }
//
//   public List<MenuaiRemoveModel> uploadSmallPicture(MultipartFile multipartFile, MenuaiUploadSmallPictureDTO content) {
//      Long stallId = content.getStallId();
//      Long dishesId = content.getDishesId();
//      String suffix = CharSequenceUtil.subAfter(multipartFile.getOriginalFilename(), ".", false);
//      String smallFileName = "" + dishesId + "_s_" + Id.next() + "." + suffix;
//      MenuaiStallModel stallModel = this.allocCanteenApi.getStallDetail(stallId);
//      String areaNum = stallModel.getAreaNum();
//      String canteenNum = stallModel.getCanteenNum();
//      String stallNum = stallModel.getStallNum();
//      String filePreFix = "/menuai/" + TenantContextHolder.getTenantId() + "/" + areaNum + "/" + canteenNum + "/" + stallNum + "/dishes/" + dishesId;
//      String smallFilePrefix = filePreFix + "/s/";
//      String dishesName = this.menuDishesMapper.selectDishesNameByWrapper((Wrapper)Wrappers.lambdaQuery(MenuDishes.class).eq(MenuDishes::getDishesId, dishesId));
//      Long var10000 = content.getDishesId();
//      String dishesFlag = "" + var10000 + "_" + dishesName.replace("/", "").replace(" ", "").replace(".", "");
//      this.menuaiV2Service.insertSyncRecord("", content.getCanteenId(), stallId, dishesId, dishesName, PictureTypeEnum.SMALL_PICTURE.getKey(), smallFileName, OperateTypeEnum.UPLOAD_CORRECT_PIC.key());
//
//      try {
//         this.ossTemplate.putObject(this.ossProperties.getBucketName(), smallFilePrefix + smallFileName, multipartFile.getInputStream());
//      } catch (Exception var18) {
//         log.info("保存菜品小图异常: ", var18);
//         throw new LeException("保存菜品小图异常 ^_^");
//      }
//
//      MenuaiPicture smallPicture = new MenuaiPicture();
//      Long smallPictureId = Id.next();
//      smallPicture.setId(smallPictureId);
//      if (StrUtil.isNotEmpty(content.getPictureName())) {
//         smallPicture.setPictureName(content.getPictureName());
//      } else {
//         smallPicture.setPictureName(multipartFile.getOriginalFilename());
//      }
//
//      smallPicture.setStallId(MenuaiContants.COMMON_STALL_ID);
//      smallPicture.setDishesId(content.getDishesId());
//      String smallPictureUrl = "/" + this.ossProperties.getBucketName() + "/" + smallFilePrefix + smallFileName;
//      smallPicture.setPictureUrl(smallPictureUrl);
//      smallPicture.setPictureType(PictureTypeEnum.SMALL_PICTURE.getKey());
//      smallPicture.setBigPictureId(-1L);
//      this.menuaiPictureMapper.insert(smallPicture);
//      return this.deleteLimitPic(MenuaiContants.COMMON_STALL_ID, content.getDishesId(), dishesFlag);
//   }

   @Override
   public List<MenuaiRemoveModel> removeDishesPictureBatch(List<MenuaiPictureRemoveDTO> content) {
      String repeatKey = "yst:" + TenantContextHolder.getTenantId() + ":removeMenuPicture";
      if (!RedisUtil.tryLock(repeatKey, LeConstants.COMMON_YES, 5)) {
         throw new ServiceException("程序运行中,请勿重复操作");
      } else {
         List<Long> removeIdList = Lists.newArrayList();
         Set<MenuaiPictureRemoveDTO> bigPictureSet = content.stream().filter((c) -> {
            return PictureTypeEnum.BIG_PICTURE.getKey().equals(c.getPicType());
         }).collect(Collectors.toSet());
         Set<Long> smallPictureSet;
         List<Long> removeModelList;
         if (CollUtil.isNotEmpty(bigPictureSet)) {
            smallPictureSet = bigPictureSet.stream().map(MenuaiPictureRemoveDTO::getPictureId).collect(Collectors.toSet());
            removeIdList.addAll(smallPictureSet);
            removeModelList = this.menuaiPictureMapper.selectPictureIdList(Wrappers.lambdaQuery(MenuaiPicture.class)
                    .in(MenuaiPicture::getBigPictureId, smallPictureSet));
            if (CollUtil.isNotEmpty(removeModelList)) {
               removeIdList.addAll(removeModelList);
            }
         }

         Set<MenuaiPictureRemoveDTO> newsmallPictureSet = content.stream().filter((c) -> {
            return !PictureTypeEnum.BIG_PICTURE.getKey().equals(c.getPicType());
         }).collect(Collectors.toSet());
         if (CollUtil.isNotEmpty(newsmallPictureSet)) {
            Set<Long> smallPictureIdSet = newsmallPictureSet.stream().map(MenuaiPictureRemoveDTO::getPictureId).collect(Collectors.toSet());
            removeIdList.addAll(smallPictureIdSet);
         }

         if (CollUtil.isEmpty(removeIdList)) {
            return Lists.newArrayList();
         } else {
            List<MenuaiRemoveModel> removeModelLists =
                    this.menuaiPictureMapper.selectRemovePictureDetailList(removeIdList);
            if (CollUtil.isEmpty(removeModelLists)) {
               return Lists.newArrayList();
            } else {
               removeModelLists.forEach((r) -> {
                  String objectName = CharSequenceUtil.subAfter(r.getPictureUrl(), this.ossProperties.getBucketName() + "/", true);
                  if (!StrUtil.contains(objectName, "/menu_data/")) {
                     try {
                        log.info("删除oss文件系统文件: {}", objectName);
                        this.ossTemplate.removeObject(this.ossProperties.getBucketName(), objectName);
                     } catch (Exception var4) {
                        log.info("删除图片异常: ", var4);
                        throw new ServiceException("删除图片异常 ^_^");
                     }
                  }

               });
               this.menuaiPictureMapper.deleteBatchIds(removeIdList);
               MenuaiRemoveModel removeModel = removeModelLists.get(0);
               this.checkSmallPictureExist(removeModel.getStallId());
               return removeModelLists;
            }
         }
      }
   }

//   public void transferData(MenuaiTransferDataV2DTO content) {
//      Long merchantId = TenantContextHolder.getTenantId();
//      String redisKey = "yst:menuai:" + merchantId + ":" + content.getCanteenId() + ":" + content.getShopstallId() + ":" + content.getRecipeId() + ":transferDate";
//      String checkTransfer = (String)this.stringRedisTemplate.opsForValue().get(redisKey);
//      if (CharSequenceUtil.isNotBlank(checkTransfer)) {
//         throw new LeException("数据迁移中,请勿重复操作 ^_^");
//      } else {
//         log.info("oss配置:{}", this.ossProperties.toString());
//         boolean exists = this.menuaiPictureMapper.exists((Wrapper)Wrappers.lambdaQuery(MenuaiPicture.class).eq(MenuaiPicture::getStallId, content.getShopstallId()));
//         if (!exists) {
//            throw new LeException("暂无可迁移图片信息 ^_^");
//         } else {
//            this.stringRedisTemplate.opsForValue().set(redisKey, "1", 10L, TimeUnit.MINUTES);
//            this.asyncTaskExecutor.execute(() -> {
//               this.packageTransfer(content, redisKey);
//            });
//         }
//      }
//   }
//
//   private void packageTransfer(MenuaiTransferDataV2DTO content, String redisKey) {
//      log.info("开始打包迁移!");
//      Long stallId = content.getShopstallId();
//      MenuaiRecipePictureNumDTO numDTO = new MenuaiRecipePictureNumDTO();
//      numDTO.setRecipeId(content.getRecipeId());
//      List<MenuaiRecipePictureNumVO> resultList = this.menuaiPictureMapper.selectRecipePictureNum(numDTO);
//      if (!CollUtil.isEmpty(resultList)) {
//         List<Long> dishesIdList = this.menuaiPictureMapper.selectDishesIdList((Wrapper)((LambdaQueryWrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(MenuaiPicture.class).in(MenuaiPicture::getDishesId, (Collection)resultList.stream().map(MenuaiRecipePictureNumVO::getDishesId).collect(Collectors.toList()))).eq(MenuaiPicture::getPictureType, PictureTypeEnum.SMALL_PICTURE.getKey())).groupBy(MenuaiPicture::getDishesId));
//         if (!CollUtil.isEmpty(dishesIdList)) {
//            this.reSyncSmallPicture(dishesIdList);
//            log.info("删除托盘请求档口: {}", stallId);
//            Map<String, String> removeEmptyTrayMap = Maps.newHashMap();
//            removeEmptyTrayMap.put("uid", String.valueOf(stallId));
//            removeEmptyTrayMap.put("action", "removeEmptyTray");
//            MqUtil.pushToTenantAllDevice(removeEmptyTrayMap, LeMqConstant.Topic.AI_GATEWAY_MQTT);
//            this.reUploadTray(stallId);
//            this.reUploadSmallPic(dishesIdList);
//            MenuaiSyncRecord menuaiSyncRecord = new MenuaiSyncRecord();
//            menuaiSyncRecord.setRecordId(Id.next());
//            menuaiSyncRecord.setCanteenId(content.getCanteenId());
//            menuaiSyncRecord.setShopstallId(stallId);
//            menuaiSyncRecord.setOperateType(OperateTypeEnum.TRANSFER_DATA.key());
//            menuaiSyncRecord.setRecordTime(LocalDateTime.now());
//            menuaiSyncRecord.setAiIp("");
//            menuaiSyncRecord.setRecordCode(10000);
//            menuaiSyncRecord.setRecordResult("成功");
//            this.menuaiSyncRecordMapper.insert(menuaiSyncRecord);
//            this.stringRedisTemplate.delete(redisKey);
//            log.info("结束打包迁移!");
//         }
//      }
//   }
//
//   private void reUploadSmallPic(List<Long> dishesIdList) {
//      List<MenuaiRegistPicVO> menuaiRegistPicList = this.menuaiPictureMapper.selectRegistPic(MenuaiContants.COMMON_STALL_ID, dishesIdList, PictureTypeEnum.SMALL_PICTURE.getKey());
//      if (CollUtil.isNotEmpty(menuaiRegistPicList)) {
//         menuaiRegistPicList.forEach((dishes) -> {
//            try {
//               InputStream inputStream = SysUtil.getInputStream(dishes.getPictureUrl());
//               MultipartFile multipartFile = new MockMultipartFile("file", dishes.getPictureName() + ".jpeg", "text/plain", inputStream);
//               this.menuDishesPictureBaseService.uploadTrainImageWithNoRecord(multipartFile, dishes.getDishesId(), dishes.getDishesName());
//            } catch (Exception var4) {
//               log.error("上传图片失败: {}", var4.getMessage());
//            }
//
//         });
//      }
//
//   }
//
//   private void reUploadTray(Long stallId) {
//      List<String> trayFileUrlList = this.menuaiPictureMapper.selectTrayFileList((Wrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(MenuaiPicture.class).eq(MenuaiPicture::getStallId, stallId)).eq(MenuaiPicture::getPictureType, PictureTypeEnum.TRAY_PICTURE.getKey()));
//      if (CollUtil.isNotEmpty(trayFileUrlList)) {
//         trayFileUrlList.forEach((pictureUrl) -> {
//            String fileName = CharSequenceUtil.subAfter(pictureUrl, "/", true);
//            File dishesFile = new File(fileName);
//            InputStream inputStream = this.ossTemplate.getObject(this.ossProperties.getBucketName(), CharSequenceUtil.subAfter(pictureUrl, "/" + this.ossProperties.getBucketName(), false));
//
//            try {
//               FileUtils.copyInputStreamToFile(inputStream, dishesFile);
//            } catch (IOException var7) {
//               log.info("图片文件获取异常: ", var7);
//               throw new LeException("图片文件获取异常 ^_^");
//            }
//
//            Map<String, String> uploadParamMap = Maps.newHashMap();
//            uploadParamMap.put("type", "tray");
//            uploadParamMap.put("food", "10000");
//            uploadParamMap.put("uid", String.valueOf(stallId));
//            uploadParamMap.put("file", SysUtil.getCutFileUrl(pictureUrl));
//            uploadParamMap.put("action", "uploadEmptyTray");
//            MqUtil.pushToTenantAllDevice(uploadParamMap, LeMqConstant.Topic.AI_GATEWAY_MQTT);
//         });
//      }
//
//   }
//
//   public List<MenuaiRemoveModel> deleteLimitPic(Long stallId, Long dishesId, String dishesFlag) {
//      log.info("设备端上传图片限制菜品ID {}", dishesId);
//      MenuDishesAiConfig menuDishesAiConfig = this.menuDishesAiConfigService.getMenuDishesAiConfig(dishesId);
//      Integer pictureLimit = menuDishesAiConfig.getTrainCount();
//      if (!ObjectUtil.isNull(pictureLimit) && pictureLimit >= 6) {
//         List<MenuaiRemoveModel> removeModelList = this.menuaiPictureMapper.selectRemovePictureDetailLimit(stallId, dishesId, pictureLimit);
//         if (CollUtil.isEmpty(removeModelList)) {
//            return Lists.newArrayList();
//         } else {
//            log.info("获取待删除图片结果：{}, 图片上限: {}", JSON.toJSONString(removeModelList), pictureLimit);
//            List<Long> removeIdList = (List)removeModelList.stream().map(MenuaiRemoveModel::getId).collect(Collectors.toList());
//            this.menuDishesPictureBaseService.deleteById(removeIdList);
//            return removeModelList;
//         }
//      } else {
//         return Lists.newArrayList();
//      }
//   }
//
   private void checkSmallPictureExist(Long stallId) {
      List<MenuaiRemoveModel> removeModelList = this.menuaiPictureMapper.selectRemovePictureDetailByStallId(stallId);
      if (!CollUtil.isEmpty(removeModelList)) {
         List<Long> removeIdList = removeModelList.stream().map(MenuaiRemoveModel::getId).collect(Collectors.toList());
         removeModelList.forEach((r) -> {
            String objectName = CharSequenceUtil.subAfter(r.getPictureUrl(), this.ossProperties.getBucketName() + "/", true);
            if (!CharSequenceUtil.contains(objectName, "/menu_data/")) {
               try {
                  log.info("删除oss文件系统文件: {}", objectName);
                  this.ossTemplate.removeObject(this.ossProperties.getBucketName(), objectName);
               } catch (Exception var4) {
                  log.info("删除图片异常: ", var4);
                  throw new ServiceException("删除图片异常 ^_^");
               }
            }

         });
         this.menuaiPictureMapper.deleteBatchIds(removeIdList);
      }
   }

   @Override
   public void removeDishesFromAi(Long dishesId, String dishesName) {
      Map<String, Object> removeDishesParam = Maps.newHashMap();
      removeDishesParam.put("uid", String.valueOf(0));
      removeDishesParam.put("force", true);
      removeDishesParam.put("food", Collections.singletonList("" + dishesId + "_" + dishesName));
      removeDishesParam.put("action", "removeFood");
      MqUtil.pushToTenantAllDevice(removeDishesParam, LeMqConstant.Topic.AI_GATEWAY_MQTT);
   }

//   public void reSyncSmallPicture(List<Long> dishesIdList) {
//      String suffix = ".jpeg";
//      List<MenuDishes> dishesList = this.menuDishesMapper.selectDishesIdAndNameListByWrapper((Wrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(MenuDishes.class).in(MenuDishes::getDishesId, dishesIdList)).eq(MenuDishes::getDelFlag, DelFlagEnum.DEL_FALSE.key()));
//      if (!CollUtil.isEmpty(dishesList)) {
//         List<String> dishesFlagList = Lists.newArrayList();
//         dishesList.forEach((d) -> {
//            Long var10000 = d.getDishesId();
//            String dishesFlag = "" + var10000 + "_" + d.getDishesName().replace("/", "").replace(" ", "").replace(".", "");
//            dishesFlagList.add(dishesFlag);
//         });
//         Map<String, Object> removeDishesParam = Maps.newHashMap();
//         removeDishesParam.put("uid", String.valueOf(0));
//         removeDishesParam.put("force", true);
//         removeDishesParam.put("food", dishesFlagList);
//         removeDishesParam.put("action", "removeFood");
//         log.info("删除菜品算法请求: {}", removeDishesParam);
//         MqUtil.pushToTenantAllDevice(removeDishesParam, LeMqConstant.Topic.AI_GATEWAY_MQTT);
//         List<MenuaiPictureExtend> pictureList = this.menuaiPictureMapper.selectDishesAllSmallPictureBySql((List)dishesList.stream().map(MenuDishes::getDishesId).collect(Collectors.toList()), MenuaiContants.COMMON_STALL_ID, PictureTypeEnum.SMALL_PICTURE.getKey());
//         if (!CollUtil.isEmpty(pictureList)) {
//            Map<Long, List<MenuaiPictureExtend>> pictureExtendMap = (Map)pictureList.stream().collect(Collectors.groupingBy(MenuaiPictureExtend::getDishesId));
//            pictureExtendMap.forEach((k, v) -> {
//               List<SyncSmallPicListDto.SyncSmallSinglePicDto> syncSmallPicList = new ArrayList();
//               List<MenuaiPicture> menuaiPictureList = new ArrayList();
//               if (CollUtil.isNotEmpty(v)) {
//                  v.forEach((e) -> {
//                     SyncSmallPicListDto.SyncSmallSinglePicDto syncSmallSinglePicDto = new SyncSmallPicListDto.SyncSmallSinglePicDto();
//                     syncSmallSinglePicDto.setUid(String.valueOf(MenuaiContants.COMMON_STALL_ID));
//                     Long var10001 = e.getDishesId();
//                     syncSmallSinglePicDto.setFood("" + var10001 + "_" + e.getDishesName().replace("/", "").replace(" ", "").replace(".", ""));
//                     syncSmallSinglePicDto.setFile(SysUtil.getCutFileUrl(e.getPictureUrl()));
//                     String var7 = e.getPictureName();
//                     syncSmallSinglePicDto.setFilename(var7 + suffix);
//                     syncSmallPicList.add(syncSmallSinglePicDto);
//                     String fileName = CharSequenceUtil.subAfter(e.getPictureUrl(), "/", true);
//                     log.info("获取图片文件名: {}", fileName);
//                     MenuaiPicture menuaiPicture = new MenuaiPicture();
//                     BeanUtil.copyProperties(e, menuaiPicture, new String[0]);
//                     menuaiPicture.setId(e.getId());
//                     menuaiPictureList.add(menuaiPicture);
//                  });
//               }
//
//               this.menuaiPictureService.updateBatchById(menuaiPictureList);
//               SyncSmallPicListDto syncSmallPicListDto = new SyncSmallPicListDto();
//               syncSmallPicListDto.setAction("syncSmallPicList");
//               syncSmallPicListDto.setSyncSmallPicMapList(syncSmallPicList);
//               log.info("小图同步请求: {}", syncSmallPicListDto);
//               MqUtil.pushToTenantAllDevice(syncSmallPicListDto, LeMqConstant.Topic.AI_GATEWAY_MQTT);
//            });
//         }
//      }
//   }
//
//   public void notifyRegisterResult(MenuaiRegistResultDTO content) {
//      MenuaiRegister register = (MenuaiRegister)this.menuaiRegisterMapper.selectOne((Wrapper)Wrappers.lambdaQuery(MenuaiRegister.class).eq(MenuaiRegister::getRequestId, content.getRequestId()));
//      if (ObjectUtil.isNull(register)) {
//         throw new LeException("注册失败");
//      } else {
//         MenuRecipe recipe = (MenuRecipe)this.menuRecipeMapper.selectOne((Wrapper)Wrappers.lambdaQuery(MenuRecipe.class).eq(MenuRecipe::getRecipeId, register.getRecipeId()));
//         String timeoutCode = "TIMEOUT";
//         String canceledCode = "CANCELED";
//         String failedCode = "FAILED";
//         String successCode = "SUCCESS";
//         MenuaiRegister updateRegister = new MenuaiRegister();
//         updateRegister.setId(register.getId());
//         if (timeoutCode.equals(content.getCode())) {
//            updateRegister.setRegisterState(RegisterStateEnum.TIMEOUT.getKey());
//            updateRegister.setRegisterMsg(RegisterStateEnum.TIMEOUT.getValue());
//            this.menuaiRegisterMapper.updateById(updateRegister);
//         } else if (canceledCode.equals(content.getCode())) {
//            updateRegister.setRegisterState(RegisterStateEnum.CANCELED.getKey());
//            updateRegister.setRegisterMsg(RegisterStateEnum.CANCELED.getValue());
//            this.menuaiRegisterMapper.updateById(updateRegister);
//         } else if (failedCode.equals(content.getCode())) {
//            updateRegister.setRegisterState(RegisterStateEnum.FAIL.getKey());
//            updateRegister.setRegisterMsg(content.getMessage());
//            this.menuaiRegisterMapper.updateById(updateRegister);
//         } else if (successCode.equals(content.getCode())) {
//            LocalDateTime registerTime = register.getRegisterTime();
//            LocalDateTime registerEndTime = LocalDateTime.now();
//            long registerMillis = Duration.between(registerTime, registerEndTime).toMillis();
//            log.info("***菜品注册总耗时: {}", registerMillis);
//            String costTime = (new BigDecimal(registerMillis)).divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP).toString();
//            List<Long> dishesIdList = this.menuaiRegisterDishesMapper.selectDishesIdList((Wrapper)Wrappers.lambdaQuery(MenuaiRegisterDishes.class).eq(MenuaiRegisterDishes::getRegisterId, register.getId()));
//            String intervalName = AllocMealtimeTypeEnum.getDescByKey(register.getMealtimeType());
//            updateRegister.setRegisterState(RegisterStateEnum.SUCCESS.getKey());
//            updateRegister.setRegisterMsg(RegisterStateEnum.SUCCESS.getValue());
//            updateRegister.setCostTime(costTime);
//            this.menuaiRegisterMapper.updateById(updateRegister);
//            this.menuaiRegisterDishesMapper.delete((Wrapper)Wrappers.lambdaQuery(MenuaiRegisterDishes.class).eq(MenuaiRegisterDishes::getRegisterId, register.getId()));
//            dishesIdList.forEach((d) -> {
//               MenuaiRegisterDishes registerDishes = new MenuaiRegisterDishes();
//               registerDishes.setRegisterId(register.getId());
//               registerDishes.setDishesId(d);
//               registerDishes.setRegisterState(RegisterStateEnum.SUCCESS.getKey());
//               this.menuaiRegisterDishesMapper.insert(registerDishes);
//            });
//         }
//
//      }
//   }
//
//   public void syncSingleSmallPic(MultipartFile multipartFile, SyncSmallPicDto syncSmallPicDto) {
//      Long canteenId = 0L;
//      String suffix = ".jpeg";
//      MenuaiSyncRecord menuaiSyncRecord = new MenuaiSyncRecord();
//      menuaiSyncRecord.setRecordId(Id.next());
//      menuaiSyncRecord.setCanteenId(canteenId);
//      menuaiSyncRecord.setShopstallId(MenuaiContants.COMMON_STALL_ID);
//      menuaiSyncRecord.setDishesId(syncSmallPicDto.getDishesId());
//      menuaiSyncRecord.setDishesName(syncSmallPicDto.getDishesName());
//      menuaiSyncRecord.setPicType(syncSmallPicDto.getPicType());
//      menuaiSyncRecord.setOperateType(syncSmallPicDto.getOperateType());
//      menuaiSyncRecord.setRecordTime(LocalDateTime.now());
//      menuaiSyncRecord.setPicName(syncSmallPicDto.getSaveName());
//      menuaiSyncRecord.setAiIp("");
//      menuaiSyncRecord.setRecordResult("成功");
//      menuaiSyncRecord.setRecordCode(10000);
//      String pictureName = String.valueOf(UUID.randomUUID());
//      Map<String, String> syncSmallPicMap = new HashMap();
//      syncSmallPicMap.put("uid", String.valueOf(MenuaiContants.COMMON_STALL_ID));
//      syncSmallPicMap.put("food", syncSmallPicDto.getDishesName());
//      syncSmallPicMap.put("file", SysUtil.getCutFileUrl(syncSmallPicDto.getPictureUrl()));
//      syncSmallPicMap.put("filename", pictureName + suffix);
//      syncSmallPicMap.put("action", "syncSmallPic");
//      MqUtil.pushToTenantAllDevice(syncSmallPicMap, LeMqConstant.Topic.AI_GATEWAY_MQTT);
//      MenuaiPicture smallPicture = new MenuaiPicture();
//      Long smallPictureId = Id.next();
//      smallPicture.setId(smallPictureId);
//      smallPicture.setPictureName(pictureName);
//      smallPicture.setStallId(MenuaiContants.COMMON_STALL_ID);
//      smallPicture.setDishesId(syncSmallPicDto.getDishesId());
//      smallPicture.setPictureUrl(syncSmallPicDto.getPictureUrl());
//      smallPicture.setConsumerDetectPicId(syncSmallPicDto.getConsumerDetectPicId());
//      smallPicture.setPictureType(PictureTypeEnum.SMALL_PICTURE.getKey());
//      smallPicture.setBigPictureId(0L);
//      smallPicture.setTrainTag(syncSmallPicDto.getTrainTag());
//      smallPicture.setShowTag(syncSmallPicDto.getShowTag());
//      this.menuaiPictureMapper.insert(smallPicture);
//      this.deleteLimitPic(MenuaiContants.COMMON_STALL_ID, syncSmallPicDto.getDishesId(), syncSmallPicDto.getDishesName());
//      menuaiSyncRecord.setRecordResult("成功");
//      this.menuaiSyncRecordMapper.insert(menuaiSyncRecord);
//   }
//
//   public void syncSingleSmallPicWithNoRecord(MultipartFile multipartFile, SyncSmallPicDto syncSmallPicDto) {
//      Long canteenId = 0L;
//      String suffix = ".jpeg";
//      MenuaiSyncRecord menuaiSyncRecord = new MenuaiSyncRecord();
//      menuaiSyncRecord.setRecordId(Id.next());
//      menuaiSyncRecord.setCanteenId(canteenId);
//      menuaiSyncRecord.setShopstallId(MenuaiContants.COMMON_STALL_ID);
//      menuaiSyncRecord.setDishesId(syncSmallPicDto.getDishesId());
//      menuaiSyncRecord.setDishesName(syncSmallPicDto.getDishesName());
//      menuaiSyncRecord.setPicType(syncSmallPicDto.getPicType());
//      menuaiSyncRecord.setOperateType(syncSmallPicDto.getOperateType());
//      menuaiSyncRecord.setRecordTime(LocalDateTime.now());
//      menuaiSyncRecord.setPicName(syncSmallPicDto.getSaveName());
//      menuaiSyncRecord.setAiIp("");
//      String pictureName = String.valueOf(UUID.randomUUID());
//      Map<String, String> syncSmallPicMap = new HashMap();
//      syncSmallPicMap.put("uid", String.valueOf(MenuaiContants.COMMON_STALL_ID));
//      syncSmallPicMap.put("food", syncSmallPicDto.getDishesName());
//      syncSmallPicMap.put("file", SysUtil.getCutFileUrl(syncSmallPicDto.getPictureUrl()));
//      syncSmallPicMap.put("filename", pictureName + suffix);
//      syncSmallPicMap.put("action", "syncSmallPic");
//      MqUtil.pushToTenantAllDevice(syncSmallPicMap, LeMqConstant.Topic.AI_GATEWAY_MQTT);
//      menuaiSyncRecord.setRecordCode(10000);
//      menuaiSyncRecord.setRecordResult("成功");
//      this.menuaiSyncRecordMapper.insert(menuaiSyncRecord);
//   }
//
//   public void removeEmptyTray(MenuaiTrayRemoveDTO content) {
//      MenuaiRemoveModel removeModel = this.menuaiPictureMapper.selectRemovePictureDetail(content.getId());
//      Map<String, String> removeEmptyTrayMap = Maps.newHashMap();
//      removeEmptyTrayMap.put("uid", String.valueOf(removeModel.getStallId()));
//      removeEmptyTrayMap.put("action", "removeEmptyTray");
//      MqUtil.pushToTenantAllDevice(removeEmptyTrayMap, LeMqConstant.Topic.AI_GATEWAY_MQTT);
//      String objectName = CharSequenceUtil.subAfter(removeModel.getPictureUrl(), this.ossProperties.getBucketName() + "/", true);
//      if (!StrUtil.contains(objectName, "/menu_data/")) {
//         try {
//            log.info("删除oss文件系统文件: {}", objectName);
//            this.ossTemplate.removeObject(this.ossProperties.getBucketName(), objectName);
//         } catch (Exception var6) {
//            log.info("删除图片异常: ", var6);
//            throw new LeException("删除图片异常 ^_^");
//         }
//      }
//
//      this.menuaiPictureMapper.deleteById(content.getId());
//   }
}
