package com.willalp.web.controller.app;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.willalp.canteen.domain.*;
import com.willalp.canteen.domain.req.CustomMenuSaveReq;
import com.willalp.canteen.domain.req.CustomOrderPaymentReq;
import com.willalp.canteen.domain.req.CustomReq;
import com.willalp.canteen.domain.resp.CuisineListResp;
import com.willalp.canteen.domain.resp.CustomGetOrderResp;
import com.willalp.canteen.domain.resp.UsableOrderResp;
import com.willalp.canteen.domain.vo.CustomGetOrderVo;
import com.willalp.canteen.domain.vo.GetFoodUpLoadItemVo;
import com.willalp.canteen.domain.vo.GetFoodUpLoadVo;
import com.willalp.canteen.service.*;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.core.domain.entity.SysUser;
import com.willalp.common.core.domain.model.LoginUser;
import com.willalp.common.core.redis.RedisCache;
import com.willalp.common.enums.ConsumeChangeEnum;
import com.willalp.common.enums.NumberRuleEnum;
import com.willalp.common.enums.PartternIdEnum;
import com.willalp.common.exception.base.BaseException;
import com.willalp.common.utils.PeriodUtil;
import com.willalp.common.utils.StringUtils;
import com.willalp.common.utils.bean.BeanUtils;
import com.willalp.device.domain.vo.DeviceInitVo;
import com.willalp.device.service.IDeviceService;
import com.willalp.integral.domain.Integral;
import com.willalp.integral.service.IIntegralService;
import com.willalp.number.domain.req.NumberRuleReq;
import com.willalp.number.service.IHsSysNumberRuleService;
import com.willalp.system.domain.SysUserOrganization;
import com.willalp.system.service.ISysConfigService;
import com.willalp.system.service.ISysUserOrganizationService;
import com.willalp.system.service.ISysUserService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * @author hs
 */
@RestController
@RequestMapping("/custom")
public class CustomController extends BaseController {

    private static final Log LOG = LogFactory.getLog(CustomController.class);

    @Autowired
    IHsCanteenMenuService hsCanteenMenuService;

    @Autowired
    IHsCanteenMenuRegisterService hsCanteenMenuRegisterService;

    @Autowired
    IHsCanteenMenuCustomService hsCanteenMenuCustomService;

    @Autowired
    ISysUserService sysUserService;

    @Autowired
    IHsSysNumberRuleService hsSysNumberRuleService;

    @Autowired
    IHsCanteenMenuService canteenMenuService;

    @Autowired
    IHsCanteenOrderService hsCanteenOrderService;

    @Autowired
    IHsCanteenOrderDetailService hsCanteenOrderDetailService;

    @Autowired
    IIntegralService integralService;

    @Autowired
    ISysUserOrganizationService sysUserOrganizationService;

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private IDeviceService deviceService;

    @Autowired
    private ISysConfigService sysConfigService;


    private final String IC_CARD = "IC_CARD";
    private final String HS_CODE = "HS_CODE";

    /**
     * 设备初始化并绑定就餐地验证
     *
     * @param dn 就餐地编码
     * @return
     */
    @RequestMapping("/uploadsr")
    @ResponseBody
    public AjaxResult initDevice(String dn, String bodyText) {
        if (StringUtils.isNotBlank(dn)) {
            if (StringUtils.isNotBlank(bodyText) && !StringUtils.equals("null", bodyText)) {
                try {
                    int length = bodyText.length();
                    String type = null;
                    String dataStr = null;
                    JSONObject jsonObject = new JSONObject();
                    //IC卡
                    if (length == 8) {
                        type = IC_CARD;
                        dataStr = bodyText;
                        System.out.println("使用IC卡：" + bodyText);
                    } else
                        //HS码
                        if (length > 8) {
                            type = HS_CODE;
                            dataStr = bodyText;
                            LOG.debug("使用HS码：" + bodyText);
                        } else {
                            return AjaxResult.error("无效二维码，请使用[HS码]再次扫描");
                        }
//                        else if (length > 86) {
//                            //同时刷卡扫码
//                            if (bodyText.indexOf("{") != 0) {
//                                type = IC_CARD;
//                                dataStr = bodyText.substring(0, bodyText.indexOf("{"));
//                            } else {
//                                type = HS_CODE;
//                                dataStr = bodyText.substring(bodyText.indexOf("{"), bodyText.indexOf("}") + 1);
//                            }
//                            System.out.println(bodyText);
//                            System.out.println("同时使用：" + dataStr);
//                        } else {
//                            return AjaxResult.error("无效的非法结果");
//                        }
                    jsonObject.put("type", type);
                    jsonObject.put("data", dataStr);
                    redisCache.setCacheObject(dn, jsonObject, 20, TimeUnit.SECONDS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return AjaxResult.success();
    }

    /**
     * 设备初始化并绑定就餐地验证
     *
     * @param deviceInitVo 初始化参数
     * @return
     */
    @RequestMapping("/init")
    @ResponseBody
    public AjaxResult initDevice(@RequestBody DeviceInitVo deviceInitVo) {
        String deviceNo = deviceService.deviceInit(deviceInitVo);
        AjaxResult success = AjaxResult.success();
        success.put("data", deviceNo);
        return success;
    }

    /**
     * 消费机获取自由消费菜单
     *
     * @param customName
     * @return
     */
    @RequestMapping("/menu")
    @ResponseBody
    public AjaxResult getCustomMenu(String customName) {
        //获取自由菜单
        HsCanteenMenu menu = new HsCanteenMenu();
        menu.setPatternId(PartternIdEnum.FREEDOM.getValue());
        try {
            menu = hsCanteenMenuService.selectHsCanteenMenuList(menu).get(0);
        } catch (Exception e) {
            throw new BaseException("菜单不存在");
        }

        //菜单菜品
        HsCanteenMenuRegister register = new HsCanteenMenuRegister();
        register.setMenuNumber(menu.getMenuNumber());
        List<CuisineListResp> regs = new ArrayList<>();
        regs = hsCanteenMenuRegisterService.selectCuisineList(register, 0, 0);
        //定制菜单
        if (customName != null && customName != "") {
            HsCanteenMenuCustom custom = new HsCanteenMenuCustom();
            custom.setCustomName(customName);
            custom.setMenuNumber(menu.getMenuNumber());
            List<HsCanteenMenuCustom> customs = new ArrayList<>();
            customs = hsCanteenMenuCustomService.selectHsCanteenMenuCustomList(custom);
            List<String> numbers = customs.stream().map(o -> o.getCuisineNumber()).collect(Collectors.toList());
            regs = regs.stream().filter(o -> numbers.contains(o.getCuisineNumber())).collect(Collectors.toList());
        }
        regs = regs.stream().map(item -> {
            if (item.getCuisinePicture() != null) {
                item.setCuisinePicture("http://" + getIp() + item.getCuisinePicture());
            }
            return item;
        }).collect(Collectors.toList());
        return AjaxResult.success(regs);
    }


    /**
     * 定制菜单保存
     *
     * @param req
     * @return
     */
    @RequestMapping("/save")
    @ResponseBody
    public AjaxResult saveCustomMenu(CustomMenuSaveReq req) {
        List<HsCanteenMenuCustom> customs = new ArrayList<>();
        req.getCuisines().stream().forEach(o -> {
            HsCanteenMenuCustom custom = new HsCanteenMenuCustom();
            custom.setCustomId(IdWorker.getIdStr());
            custom.setMenuNumber(req.getMenuNumber());
            custom.setCustomName(req.getCustomName());
            custom.setCuisineNumber(o);
            custom.setJgid(req.getJgid());
            customs.add(custom);
        });
        try {
            hsCanteenMenuCustomService.saveBatch(customs);
        } catch (Exception e) {
            throw new BaseException("保存失败");
        }
        return AjaxResult.success("保存成功");
    }

    /**
     * 定制菜单删除内容
     *
     * @param customIds
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public AjaxResult remove(Long[] customIds) {
        hsCanteenMenuCustomService.removeByIds(Arrays.asList(customIds));
        return AjaxResult.success();
    }

    /**
     * 下单
     *
     * @param req
     * @return
     */
    @RequestMapping("/order")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult customOrder(CustomOrderPaymentReq req) {
        Date date = new Date();
        //可记账不可记账菜品
        List<HsCanteenOrderDetail> freeRegs = new ArrayList<>();
        List<HsCanteenOrderDetail> regs = new ArrayList<>();
        List<Integral> integrals = new ArrayList<>();//消费记录
        List<HsCanteenOrder> orders = new ArrayList<>();//订单
        List<HsCanteenOrderDetail> details = new ArrayList<>();//订单明细
        BigDecimal orderTotal = BigDecimal.ZERO;
        //获取用户
        SysUserOrganization user = new SysUserOrganization();
        user.setLoginName(req.getUserNumber());
        user.setOrganizationCode(req.getJgid());
        List<SysUserOrganization> userList = sysUserOrganizationService.selectSysUserOrganizationList(user);
        if (userList.size() == 0) {
            return AjaxResult.error("用户信息不存在");
        }
        user = userList.get(0);
        //收费菜单
        HsCanteenMenu customMenu = new HsCanteenMenu();
        customMenu.setPatternId(PartternIdEnum.FREEDOM.getValue());
        List<HsCanteenMenu> customMenus = new ArrayList<>();
        customMenus = hsCanteenMenuService.selectHsCanteenMenuList(customMenu);
        if (customMenus.size() > 0) {
            customMenu = customMenus.get(0);
        }
        //菜品分类判断是否可以记账
        HsCanteenMenu freeMenu = new HsCanteenMenu();
        freeMenu.setPatternId(PartternIdEnum.FREE_CREDIT.getValue());//消费模式
        //时间段
        String morningStr = sysConfigService.selectConfigByKey("morning");
        String noonStr = sysConfigService.selectConfigByKey("noon");
        String nightStr = sysConfigService.selectConfigByKey("night");
        Integer periodId = PeriodUtil.judgmentPeriod(date, morningStr.split(","), noonStr.split(","), nightStr.split(","));
        freeMenu.setPeriodId(periodId);//时段
        freeMenu.setUseDate(date);//使用时段
        List<HsCanteenMenu> freeMenus = new ArrayList<>();
        freeMenus = hsCanteenMenuService.selectHsCanteenMenuList(freeMenu);
        if (freeMenus.size() > 0) {//过滤所属角色菜单
            SysUserOrganization finalUser = user;
            freeMenus = freeMenus.stream().filter(o ->
                    Arrays.asList(o.getConsumerType().split(",")).contains(finalUser.getUserType()))
                    .collect(Collectors.toList());
            if (freeMenus.size() > 0) {
                List<HsCanteenMenuRegister> freeCuisines = new ArrayList<>();
                HsCanteenMenuRegister freeCuisine = new HsCanteenMenuRegister();
                freeCuisine.setMenuNumber(freeMenus.get(0).getMenuNumber());
                freeCuisines = hsCanteenMenuRegisterService.selectHsCanteenMenuRegisterList(freeCuisine);
                List<String> cuisineStr = freeCuisines.stream().map(o -> o.getCuisineNumber()).collect(Collectors.toList());
                req.getDetails().stream().forEach(o -> {
                    if (cuisineStr.contains(o.getCuisineNumber())) {
                        o.setMenuNumber(freeCuisine.getMenuNumber());
                        freeRegs.add(o);
                    } else {
                        regs.add(o);
                    }
                });
            }
        }
        if (freeRegs.size() > 0) {
            orderTotal = regs.stream().map(HsCanteenOrderDetail::getTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
            if (user.getQuota().compareTo(orderTotal) < 0) {
                return AjaxResult.error("记账额度不足");
            }
            //生成消费记录
            Integral integral = new Integral();
            integral.setId(IdWorker.getIdStr());//积分主键
            integral.setMoneyType(Integer.valueOf(ConsumeChangeEnum.OFFLINEBOOKING.getValue()));//消费
            integral.setRechargeEquipmentCode(req.getDeviceNumber());//设备编号
            integral.setRechargeEquipmentName(req.getDeviceName());//设备名称
            integral.setLoginName(req.getUserNumber());//账号编号
            integral.setRechargeTime(date);//支付时间
            integral.setRechargeIntegral(orderTotal.negate());//积分(负数)
            integral.setIsDelete(0);//有效标志
            integral.setOrganizationCode(req.getJgid());//机构代码
            //记账订单
            HsCanteenOrder hsCanteenOrderFree = new HsCanteenOrder();
            BeanUtils.copyBeanProp(hsCanteenOrderFree, req);
            hsCanteenOrderFree.setMenuNumber(freeRegs.get(0).getMenuNumber());
            hsCanteenOrderFree.setOrderId(IdWorker.getIdStr());//id
            hsCanteenOrderFree.setPaytime(date);
            //获取订单编码
            NumberRuleReq numberRuleReq = new NumberRuleReq();
            numberRuleReq.setRuleId(NumberRuleEnum.ORDER.getValue());
            numberRuleReq.setInput(String.valueOf(DateUtil.year(date)).substring(2, 4));
            String number = hsSysNumberRuleService.getNumber(numberRuleReq);
            hsCanteenOrderFree.setOrderNumber(number);
            hsCanteenOrderFree.setOrderTotal(BigDecimal.ZERO);
            orders.add(hsCanteenOrderFree);
            freeRegs.stream().forEach(o -> {
                o.setDetailId(IdWorker.getIdStr());
                o.setOrderNumber(hsCanteenOrderFree.getOrderNumber());
            });
            details.addAll(freeRegs);
        } else {
            regs.addAll(req.getDetails());
        }

        if (regs.size() > 0) {//支付订单
            orderTotal = regs.stream().map(HsCanteenOrderDetail::getTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
            if (user.getIntegral().compareTo(orderTotal) < 0) {
                return AjaxResult.error("账户积分不足");
            }
            //扣减积分
            user.setIntegral(user.getIntegral().subtract(orderTotal));

            //生成消费记录
            Integral integral = new Integral();
            integral.setId(IdWorker.getIdStr());//积分主键
            integral.setMoneyType(Integer.valueOf(ConsumeChangeEnum.OFFLINECONSUME.getValue()));//消费
            integral.setRechargeEquipmentCode(req.getDeviceNumber());//设备编号
            integral.setRechargeEquipmentName(req.getDeviceName());//设备名称
            integral.setLoginName(req.getUserNumber());//账号编号
            integral.setRechargeTime(date);//支付时间
            integral.setRechargeIntegral(orderTotal.negate());//积分(负数)
            integral.setIsDelete(0);//有效标志
            integral.setOrganizationCode(req.getJgid());//机构代码
            //订单
            HsCanteenOrder hsCanteenOrder = new HsCanteenOrder();
            BeanUtils.copyBeanProp(hsCanteenOrder, req);
            hsCanteenOrder.setOrderId(IdWorker.getIdStr());//id
            hsCanteenOrder.setOrderTotal(orderTotal);//订单总额
            hsCanteenOrder.setMenuNumber(customMenu.getMenuNumber());
            hsCanteenOrder.setPaytime(date);
            //获取订单编码
            NumberRuleReq numberRuleReq = new NumberRuleReq();
            numberRuleReq.setRuleId(NumberRuleEnum.ORDER.getValue());
            numberRuleReq.setInput(String.valueOf(DateUtil.year(date)).substring(2, 4));
            String number = hsSysNumberRuleService.getNumber(numberRuleReq);
            hsCanteenOrder.setOrderNumber(number);
            orders.add(hsCanteenOrder);
            //消费记录增加订单编号
            integral.setOrderNumber(number);
            integrals.add(integral);
            HsCanteenMenu finalCustomMenu = customMenu;
            regs.stream().forEach(o -> {
                o.setMenuNumber(finalCustomMenu.getMenuNumber());
                o.setDetailId(IdWorker.getIdStr());
                o.setOrderNumber(hsCanteenOrder.getOrderNumber());
            });
            details.addAll(regs);
        }

        try {
            sysUserOrganizationService.updateById(user);
            hsCanteenOrderService.saveBatch(orders);//订单主表
            hsCanteenOrderDetailService.saveBatch(details);//订单明细
            integralService.saveBatch(integrals);
        } catch (Exception e) {
            throw new BaseException("保存失败");
        }

        return AjaxResult.success("保存成功");
    }

    /**
     * 获取待取订单
     *
     * @return
     */
    @RequestMapping("/getOrder")
    @ResponseBody
    public AjaxResult getOrder(@RequestBody CustomReq req) {
        String token = "login_tokens:" + req.getToken();
        LoginUser user = redisCache.getCacheObject(token);
        if (user == null) {
            throw new BaseException("不存在用户信息");
        }
        //设备信息
//        Device device = new Device();
//        device.setDeviceNo(req.getDeviceNo());
//        device.setDeviceOrgId(req.getJgid());
//        List<Device> deviceList = deviceService.selectDeviceList(device);
//        if (CollectionUtil.isEmpty(deviceList)) {
//            return AjaxResult.error("不存在设备信息");
//        }
//        device = deviceList.get(0);
        //返回值
        UsableOrderResp usableOrderResp = new UsableOrderResp();
        //查询参数
        Date date = new Date();
        //时间段
        String morningStr = sysConfigService.selectConfigByKey("morning");
        String noonStr = sysConfigService.selectConfigByKey("noon");
        String nightStr = sysConfigService.selectConfigByKey("night");
        Integer periodId = PeriodUtil.judgmentPeriod(date, morningStr.split(","), noonStr.split(","), nightStr.split(","));
        String dateStr = DateUtil.formatDate(date);
        CustomGetOrderVo customGetOrderVo = new CustomGetOrderVo();
        customGetOrderVo.setPeriodId(periodId);
        customGetOrderVo.setUseDate(dateStr);
        customGetOrderVo.setUserNumber(user.getUsername());
        customGetOrderVo.setJgid(req.getJgid());
        customGetOrderVo.setPlaceNumber(req.getPlaceNumber());
        //查询订单信息
        CustomGetOrderResp order = new CustomGetOrderResp();
        List<CustomGetOrderResp> orders = hsCanteenOrderService.getOrderNow(customGetOrderVo);
        orders = orders.stream().filter(o -> o.getZfbz() == 0).collect(Collectors.toList());
        if (orders.size() > 0) {//订单详情
            order = orders.get(0);
            BeanUtils.copyBeanProp(usableOrderResp, order);
            HsCanteenOrderDetail detail = new HsCanteenOrderDetail();
            detail.setOrderNumber(order.getOrderNumber());
            List<HsCanteenOrderDetail> details;
            details = hsCanteenOrderDetailService.selectHsCanteenOrderDetailList(detail);
            if (details.size() > 0) {
                usableOrderResp.setDetails(details);
                HsCanteenOrder o = new HsCanteenOrder();
                o.setOrderNumber(order.getOrderNumber());
                List<HsCanteenOrder> os = new ArrayList<>();
                os = hsCanteenOrderService.selectHsCanteenOrderList(o);
                if (os.size() > 0) {
                    o = os.get(0);
                    o.setZfbz(2);
                    hsCanteenOrderService.saveOrUpdate(o);
                }
            } else {
                throw new BaseException("此订单没有菜品");
            }
            SysUser sysUser = sysUserService.selectUserByUserName(usableOrderResp.getUserNumber());
            if (null != sysUser) {
                usableOrderResp.setNickName(sysUser.getNickName());
            } else {
                usableOrderResp.setNickName(usableOrderResp.getUserNumber());
            }
            return AjaxResult.success(usableOrderResp);
        } else {
            throw new BaseException("没有订单信息");
        }
    }

    /**
     * 完成订单
     *
     * @param orderNumber
     * @param jgid
     * @return
     */
    @RequestMapping("/completeOrder")
    @ResponseBody
    public AjaxResult CompleteOrder(String orderNumber, String jgid) {
        HsCanteenOrder order = new HsCanteenOrder();
        order.setOrderNumber(orderNumber);
        order.setJgid(jgid);
        List<HsCanteenOrder> orders = hsCanteenOrderService.selectHsCanteenOrderList(order);
        orders = orders.stream().filter(o -> o.getZfbz() == 0).collect(Collectors.toList());
        if (orders.size() > 0) {
            order = orders.get(0);
            order.setZfbz(2);
            hsCanteenOrderService.saveOrUpdate(order);
        } else {
            return AjaxResult.error("订单信息不存在");
        }
        return AjaxResult.success("完成订单");
    }

    /**
     * 已取餐未取餐数量
     *
     * @return
     */
    @RequestMapping("/getOrdersState")
    @ResponseBody
    public AjaxResult getState(@RequestBody CustomReq req) {
        Map<String, Object> result = new HashMap<>();
        Date date = new Date();
        //时间段
        String morningStr = sysConfigService.selectConfigByKey("morning");
        String noonStr = sysConfigService.selectConfigByKey("noon");
        String nightStr = sysConfigService.selectConfigByKey("night");
        Integer periodId = PeriodUtil.judgmentPeriod(date, morningStr.split(","),
                noonStr.split(","),
                nightStr.split(","));

        String dateStr = DateUtil.formatDate(date);
        CustomGetOrderVo customGetOrderVo = new CustomGetOrderVo();
        customGetOrderVo.setPeriodId(periodId);
        customGetOrderVo.setUseDate(dateStr);
        customGetOrderVo.setJgid(req.getJgid());
        customGetOrderVo.setPlaceNumber(req.getPlaceNumber());
        //查询订单信息
        List<CustomGetOrderResp> orders = hsCanteenOrderService.getOrderNow(customGetOrderVo);
        result.put("orders", orders);
        if (0 == orders.size()) {
            return AjaxResult.success(result);
        }
        CustomGetOrderResp menuNow = hsCanteenOrderService.getMenuNow(customGetOrderVo);
        result.put("menu", menuNow);
        if (menuNow != null) {
            List<HsCanteenOrderDetail> orderDetails = hsCanteenOrderDetailService.getBaseMapper().selectList(new QueryWrapper<HsCanteenOrderDetail>()
                    .eq("menu_number", menuNow.getMenuNumber()));
            result.put("orderDetails", orderDetails);
        }
        Map<Integer, List<CustomGetOrderResp>> groupMap = orders.stream().collect(Collectors.groupingBy(CustomGetOrderResp::getZfbz));
        //未取餐
        result.put("wait", orders.size());
        //已取餐
        if (groupMap.get(2) != null) {
            result.put("finish", groupMap.get(2).size());
        } else {
            result.put("finish", 0);
        }
        return AjaxResult.success(result);
    }


    /**
     * 定时上传取餐数据
     *
     * @return
     */
    @RequestMapping("/timing/upload/getFoodData")
    public AjaxResult timingUpLoadGetFoodData(@RequestBody GetFoodUpLoadVo getFoodUpLoad) {
        List<HsCanteenOrder> ordersUpdate = new ArrayList<>(16);
        List<String> numbers = new ArrayList<String>();
        List<String> numbersUpdate = new ArrayList<String>();
        if (getFoodUpLoad.getList().size() <= 0) {
            return AjaxResult.error();
        }
        for (GetFoodUpLoadItemVo food : getFoodUpLoad.getList()) {
            numbers.add(food.getOrderNumber());
        }
        List<HsCanteenOrder> orders = hsCanteenOrderService.getBaseMapper().selectList(
                new QueryWrapper<HsCanteenOrder>().in("order_number", numbers));
        orders.forEach(order -> {
            for (GetFoodUpLoadItemVo food : getFoodUpLoad.getList()) {
                if (StringUtils.equals(order.getOrderNumber(), food.getOrderNumber()) &&
                        order.getZfbz() != 2) {
                    order.setZfbz(2);
                    ordersUpdate.add(order);
                    numbersUpdate.add(order.getOrderNumber());
                }
            }
        });
        if (0 < ordersUpdate.size()) {
            if (hsCanteenOrderService.updateBatchById(ordersUpdate)) {
                return AjaxResult.success(numbersUpdate);
            }
        } else {
            return AjaxResult.error("ALL Data Already Update Please Remove");
        }
        return AjaxResult.error();
    }
}
