package com.ruoyi.applet.contoller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cyl.h5.pojo.vo.H5OrderVO;
import com.cyl.h5.service.H5OrderService;
import com.cyl.h5.service.H5PetCareService;
import com.cyl.h5.service.H5PetService;
import com.cyl.manager.oms.domain.OmsOrderService;
import com.cyl.manager.oms.domain.Order;
import com.cyl.manager.oms.domain.OrderItem;
import com.cyl.manager.oms.domain.OrderOperateHistory;
import com.cyl.manager.oms.mapper.OmsOrderServiceMapper;
import com.cyl.manager.oms.mapper.OrderItemMapper;
import com.cyl.manager.oms.mapper.OrderMapper;
import com.cyl.manager.oms.mapper.OrderOperateHistoryMapper;
import com.cyl.manager.oms.service.OrderService;
import com.cyl.manager.ums.domain.Pet;
import com.cyl.manager.ums.domain.PetCare;
import com.cyl.manager.ums.mapper.PetMapper;
import com.cyl.manager.ums.pojo.vo.PetVO;
import com.ruoyi.applet.pojo.dto.AppletOrderDateVo;
import com.ruoyi.applet.pojo.vo.AppletOrderDateAddressReturn;
import com.ruoyi.applet.pojo.vo.AppletOrderDateVoReturn;
import com.ruoyi.applet.service.IMallOrderService;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.model.domain.*;
import com.ruoyi.model.service.*;
import com.ruoyi.model.service.impl.AppletOrderItemServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Synchronized;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

@Api(description = "订单模块 - 接单大厅流程")
@RestController
@RequestMapping("/applet/order")
public class ApiAppletOrderController extends BaseController {

    @Autowired
    private IAppletOrderService appletOrderService;
    @Autowired
    private IAppletOrderItemService appletOrderItemService;
    @Autowired
    private IAppUsersService appUsersService;
    @Autowired
    private IAppletUsersTeacherService appletUsersTeacherService;
    @Autowired
    private IAppletConfigService configService;
    @Autowired
    private IMallOrderService mallOrderService;
    @Autowired
    private IAppletOrderItemDateService appletOrderItemDateService;
    //下单小程序：那边来的订单信息
    @Autowired
    private H5OrderService h5OrderService;
    @Autowired
    private OrderService service;
    @Autowired
    private AppletOrderItemServiceImpl appletOrderItemServiceImpl;

    @Autowired
    private H5PetService h5PetService;
    @Autowired
    private H5PetCareService petCareService;
    @Autowired
    private PetMapper petMapper;

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private OrderItemMapper orderItemMapper;

    @Autowired
    private OmsOrderServiceMapper omsOrderServiceMapper;

    @Autowired
    private IAppletAddressService appletAddressService;

    @Autowired
    private IAppletOutDateService appletOutDateService;

    @Autowired
    private IAppletOrderDateFrequencyService appletOrderDateFrequencyService;

    @Autowired
    private OrderOperateHistoryMapper orderOperateHistoryMapper;



    @ApiOperation("接单大厅列表-带分页")
    @GetMapping("/list")
    public AjaxResult outDateList(AppletOrder appletOrder){
        if(appletOrder.getType()==null){
            return AjaxResult.error("type状态不能为空");
        }
        if(appletOrder.getUserIdJson() == null){
            return AjaxResult.error("userIdJson用户信息标识不能为空");
        }
        //根据用户标识得到用户信息
        AppUsers appUsers = appUsersService.selectAppUsersByUserId(appletOrder.getUserId());
        BigDecimal petPayment = new BigDecimal(0);
        //得到当前用户角色
        if(appUsers.getUserBcs()!=0){
            //根据当前等级得到当前的返点比例
            AppletConfig petPaymentBcs = configService.selectAppletConfigByClassAndNum("pet_payment_bcs", appUsers.getUserBcs());
            petPayment = petPaymentBcs.getParamValueNo();
        }

        startPage();
        List<AppletOrder> list = null;
        List<AppletOrderItem> itemList = null;
        if(appletOrder.getType().equals("0")){

            //查询当前伴宠师地址
            List<AppletAddress> addressList = appletAddressService.lambdaQuery()
                    .eq(AppletAddress::getUserId, appUsers.getUserId())
                    .list();

            //没有接单地址，无法接单
            if (addressList.size() == 0){
                return AjaxResult.error("补全接单地址，开始接单");
            }

            boolean addressBoolean = false;

            for (AppletAddress appletAddress : addressList) {
                if (StringUtils.isNotEmpty(appletAddress.getLatitude()) &&
                        StringUtils.isNotEmpty(appletAddress.getLongitude()) &&
                        StringUtils.isNotEmpty(appletAddress.getRangeNo()) &&
                        "true".equals(appletAddress.getStatus())){
                    addressBoolean = true;
                    break;
                }
            }

            list = appletOrderService.lambdaQuery()
                    .eq(AppletOrder::getStatus, 0)
                    .eq(AppletOrder::getType, appletOrder.getType())
                    .and(n -> {
                        n.eq(AppletOrder::getCompanionLevel, appUsers.getUserBcsRole())
                                .or()
                                .eq(AppletOrder::getCompanionLevel, 0);//0代表所有等级都可以查询到
                    })
                    .like(appletOrder.getUserIdJson() != null, AppletOrder::getUserIdJson, appletOrder.getUserIdJson())
                    .and(addressList.size() > 0 && addressBoolean, q -> {
                        for (AppletAddress appletAddress : addressList) {
                            //
                            if (StringUtils.isNotEmpty(appletAddress.getLatitude()) &&
                                StringUtils.isNotEmpty(appletAddress.getLongitude()) &&
                                StringUtils.isNotEmpty(appletAddress.getRangeNo()) &&
                                "true".equals(appletAddress.getStatus())){
                                //计算地址范围 getRangeNo getLatitude getLongitude
                                BigDecimal latitude = new BigDecimal(appletAddress.getLatitude());
                                BigDecimal longitude = new BigDecimal(appletAddress.getLongitude());
                                BigDecimal range = new BigDecimal(appletAddress.getRangeNo());//公里数
                                
                                // 将公里数转换为经纬度范围
                                // 1度纬度约等于111公里
                                // 1度经度约等于111*cos(纬度)公里
                                BigDecimal latRange = range.divide(new BigDecimal("111"), 6, RoundingMode.HALF_UP);
                                BigDecimal lngRange = range.divide(new BigDecimal("111").multiply(new BigDecimal(Math.cos(latitude.doubleValue() * Math.PI / 180))), 6, RoundingMode.HALF_UP);
                                
                                // 计算经纬度范围
                                BigDecimal latMin = latitude.subtract(latRange);
                                BigDecimal latMax = latitude.add(latRange);
                                BigDecimal lngMin = longitude.subtract(lngRange);
                                BigDecimal lngMax = longitude.add(lngRange);

                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                                //查询当前地址不接单的日期
                                List<String> dates = appletOutDateService
                                        .lambdaQuery()
                                        .select(AppletOutDate::getDate)
                                        .eq(AppletOutDate::getAddressId, appletAddress.getId())
                                        .list().stream()
                                        .map(n -> sdf.format(n.getDate()))
                                        .collect(Collectors.toList());


                                q.or(w -> {
                                    if(dates.size() > 0){
                                        //根据当前日期从serviceList中查询不符合条件的订单id
                                        List<Long> orderIds = omsOrderServiceMapper.selectList(
                                                Wrappers.<OmsOrderService>lambdaQuery()
                                                .select(OmsOrderService::getOrderId)
                                                .groupBy(OmsOrderService::getOrderId)
                                                .in(OmsOrderService::getServiceDate, dates))
                                                .stream().map(n -> n.getOrderId()).collect(Collectors.toList());

                                        if (orderIds.size() > 0){
                                            w.notIn(AppletOrder::getOrderId, orderIds);
                                        }
                                    }

                                    w.between(AppletOrder::getLatitude, latMin, latMax)
                                    .between(AppletOrder::getLongitude, lngMin, lngMax);
                                });
                            }
                        }
                    })
                    .list();

//            list = appletOrderService.selectAppletOrderListLikeUserIdJson(appletOrder);
            for (AppletOrder order : list) {
                H5OrderVO h5OrderVO = h5OrderService.orderDetail(order.getOrderId());
                // 得到服务信息
                List<OmsOrderService> service = h5OrderVO.getOrderServiceList();

                // 使用一个 Set 来跟踪已经添加的 PetVO 的 id
                Set<Integer> addedPetIds = new HashSet<>();
                List<PetVO> petVOList = new ArrayList<>();

                for (OmsOrderService service1 : service) {
                    // 宠物标识不为空的时候查询数据
                    if (service1.getPetId() != null) {
                        PetVO petVO = h5PetService.selectPetById(service1.getPetId());

                        // 检查 petVO 的 id 是否已经添加过
                        if (petVO != null && !addedPetIds.contains(petVO.getId())) {
                            service1.setPetVo(petVO);
                            petVOList.add(petVO);
                            addedPetIds.add(petVO.getId()); // 标记该 id 已添加
                        }
                    }
                }
                //得到当前用户角色
                if(appUsers.getUserBcs()!=0){
                    //保留两位小数点
                    BigDecimal multiply = order.getPrice().multiply(petPayment).setScale(2, RoundingMode.HALF_UP);
                    order.setOrderGive(multiply);
                }else{
                    order.setOrderGive(new BigDecimal(0));
                }
                h5OrderVO.setPetVOList(petVOList);
                order.setH5OrderVO(h5OrderVO);
            }
            TableDataInfo dataTable = getDataTable(list);
            return AjaxResult.success(dataTable);
        }
        if (appletOrder.getType().equals("1")){
            AppletOrder orderQ = new AppletOrder();
            orderQ.setUserIdJson(appletOrder.getUserIdJson());
            orderQ.setType("1");
            orderQ.setStatus(0);
            list = appletOrderService.selectAppletOrderList(orderQ);

            for (AppletOrder order : list) {
                H5OrderVO h5OrderVO = h5OrderService.orderDetail(order.getOrderId());
                // 得到服务信息
                List<OmsOrderService> service = h5OrderVO.getOrderServiceList();
                // 使用一个 Set 来跟踪已经添加的 PetVO 的 id
                Set<Integer> addedPetIds = new HashSet<>();
                List<PetVO> petVOList = new ArrayList<>();
                for (OmsOrderService service1 : service) {
                    // 宠物标识不为空的时候查询数据
                    if (service1.getPetId() != null) {
                        PetVO petVO = h5PetService.selectPetById(service1.getPetId());
                        // 检查 petVO 的 id 是否已经添加过
                        if (petVO != null && !addedPetIds.contains(petVO.getId())) {
                            service1.setPetVo(petVO);
                            petVOList.add(petVO);
                            addedPetIds.add(petVO.getId()); // 标记该 id 已添加
                        }
                    }
                }
                //得到当前用户角色
                if(appUsers.getUserBcs()!=0){
                    //保留两位小数点
                    BigDecimal multiply = order.getPrice().multiply(petPayment).setScale(2, RoundingMode.HALF_UP);
                    order.setOrderGive(multiply);
                }else{
                    order.setOrderGive(new BigDecimal(0));
                }
                h5OrderVO.setPetVOList(petVOList);
                order.setH5OrderVO(h5OrderVO);




            }
            TableDataInfo dataTable = getDataTable(list);
            return AjaxResult.success(dataTable);
        }
        if (appletOrder.getType().equals("2")){
            AppletOrderItem appletOrderItem = new AppletOrderItem();
            appletOrderItem.setStatus(2);
            appletOrderItem.setUserId(appletOrder.getUserId());
            itemList = appletOrderItemService.selectAppletOrderItemList(appletOrderItem);
            for (AppletOrderItem orderItem:itemList){
                H5OrderVO h5OrderVO = h5OrderService.orderDetail(orderItem.getOrderId());
                // 得到服务信息
                List<OmsOrderService> service = h5OrderVO.getOrderServiceList();
                // 使用一个 Set 来跟踪已经添加的 PetVO 的 id
                Set<Integer> addedPetIds = new HashSet<>();
                List<PetVO> petVOList = new ArrayList<>();
                for (OmsOrderService service1 : service) {
                    // 宠物标识不为空的时候查询数据
                    if (service1.getPetId() != null) {
                        PetVO petVO = h5PetService.selectPetById(service1.getPetId());
                        // 检查 petVO 的 id 是否已经添加过
                        if (petVO != null && !addedPetIds.contains(petVO.getId())) {
                            service1.setPetVo(petVO);
                            petVOList.add(petVO);
                            addedPetIds.add(petVO.getId()); // 标记该 id 已添加
                        }
                    }
                }

                orderItem.setOrderGive(orderItem.getOrderGivePrice());
                h5OrderVO.setPetVOList(petVOList);
                orderItem.setH5OrderVO(h5OrderVO);
            }
            TableDataInfo dataTable = getDataTable(itemList);
            return AjaxResult.success(dataTable);
        }
        return AjaxResult.success();
    }


    //接单大厅 - 根据订单标识查询订单详情的接口
    @ApiOperation("接单大厅 - 根据订单标识查询订单详情的接口")
    @GetMapping("/getByOrderId")
    public AjaxResult getByOrderId(AppletOrder appletOrder){
        if(appletOrder.getId() == null){
            return AjaxResult.error("订单标识不能为空");
        }
        if(appletOrder.getUserId() == null){
            return AjaxResult.error("用户标识不能为空");
        }

        //根据用户标识得到用户信息
        AppUsers appUsers = appUsersService.selectAppUsersByUserId(appletOrder.getUserId());
        BigDecimal petPayment = new BigDecimal(0);
        //得到当前用户角色
        if(appUsers.getUserBcs()!=0){
            //根据当前等级得到当前的返点比例
            AppletConfig petPaymentBcs = configService.selectAppletConfigByClassAndNum("pet_payment_bcs", appUsers.getUserBcs());
            petPayment = petPaymentBcs.getParamValueNo();
        }
        AppletOrder order = appletOrderService.selectAppletOrderById(appletOrder.getId());
        //如果是流失订单
        if (order==null){
//            AppletOrderItem orderQ = new AppletOrderItem();
//            orderQ.setUserId(appletOrder.getUserId());
//            orderQ.setOrderId(appletOrder.getOrderId());
            AppletOrderItem orderItem = appletOrderItemService.selectAppletOrderItemById(appletOrder.getId());
            H5OrderVO h5OrderVO = h5OrderService.orderDetail(orderItem.getOrderId());
            // 得到服务信息
            List<OmsOrderService> service = h5OrderVO.getOrderServiceList();
            // 使用一个 Set 来跟踪已经添加的 PetVO 的 id
            Set<Integer> addedPetIds = new HashSet<>();
            List<PetVO> petVOList = new ArrayList<>();
            for (OmsOrderService service1 : service) {
                // 宠物标识不为空的时候查询数据
                if (service1.getPetId() != null) {
                    PetVO petVO = h5PetService.selectPetById(service1.getPetId());
                    // 检查 petVO 的 id 是否已经添加过
                    if (petVO != null && !addedPetIds.contains(petVO.getId())) {
                        service1.setPetVo(petVO);
                        petVOList.add(petVO);
                        addedPetIds.add(petVO.getId()); // 标记该 id 已添加
                    }
                }

            }

            //得到当前用户角色
            if(appUsers.getUserBcs()!=0){
                //保留两位小数点
                BigDecimal multiply = orderItem.getPrice().multiply(petPayment).setScale(2, RoundingMode.HALF_UP);
                orderItem.setOrderGive(multiply);
            }else{
                orderItem.setOrderGive(new BigDecimal(0));
            }
            h5OrderVO.setPetVOList(petVOList);
            orderItem.setH5OrderVO(h5OrderVO);
//        order.setManagerOrderDetailVO(service.selectById(order.getOrderId()));
            Map<String, Object> map = new HashMap();
            map.put("order",orderItem);
            AppletConfig config = new AppletConfig();
            config.setParamClass("pet_payment_bcs");
            List<AppletConfig> appletConfigs = configService.selectAppletConfigList(config);
            map.put("pet_payment_bcs",appletConfigs);
            return AjaxResult.success("接单大厅查看详情",map);
        }



        H5OrderVO h5OrderVO = h5OrderService.orderDetail(order.getOrderId());
        // 得到服务信息
        List<OmsOrderService> service = h5OrderVO.getOrderServiceList();
        // 使用一个 Set 来跟踪已经添加的 PetVO 的 id
        Set<Integer> addedPetIds = new HashSet<>();
        List<PetVO> petVOList = new ArrayList<>();
        for (OmsOrderService service1 : service) {
            // 宠物标识不为空的时候查询数据
            if (service1.getPetId() != null) {
                PetVO petVO = h5PetService.selectPetById(service1.getPetId());
                // 检查 petVO 的 id 是否已经添加过
                if (petVO != null && !addedPetIds.contains(petVO.getId())) {
                    service1.setPetVo(petVO);
                    petVOList.add(petVO);
                    addedPetIds.add(petVO.getId()); // 标记该 id 已添加
                }
            }

        }

        //得到当前用户角色
        if(appUsers.getUserBcs()!=0){
            //保留两位小数点
            BigDecimal multiply = order.getPrice().multiply(petPayment).setScale(2, RoundingMode.HALF_UP);
            order.setOrderGive(multiply);
        }else{
            order.setOrderGive(new BigDecimal(0));
        }
        h5OrderVO.setPetVOList(petVOList);
        order.setH5OrderVO(h5OrderVO);
//        order.setManagerOrderDetailVO(service.selectById(order.getOrderId()));
        Map<String, Object> map = new HashMap();
        map.put("order",order);
        AppletConfig config = new AppletConfig();
        config.setParamClass("pet_payment_bcs");
        List<AppletConfig> appletConfigs = configService.selectAppletConfigList(config);
        map.put("pet_payment_bcs",appletConfigs);
        return AjaxResult.success("接单大厅查看详情",map);
    }


    //接单大厅 - 拒绝、无法接单
    @ApiOperation("接单大厅 - 拒绝、无法接单")
    @PostMapping("/endByOrderId")
    public AjaxResult endByOrderId(@RequestBody AppletOrder appletOrder){
        if(appletOrder.getId() == null){
            return AjaxResult.error("订单标识不能为空");
        }
        if(appletOrder.getUserId() == null){
            return AjaxResult.error("userId用户信息标识不能为空");
        }
        if(appletOrder.getReason() == null){
            return AjaxResult.error("无法接单原因不能为空");
        }
        AppletOrder order = appletOrderService.selectAppletOrderById(appletOrder.getId());
        //生成我的订单信息
        AppletOrderItem appletOrderItem = new AppletOrderItem();
        appletOrderItem.setCreateTime(order.getCreateTime());
        appletOrderItem.setType(order.getType());
        appletOrderItem.setStatus(2);
        appletOrderItem.setReason(appletOrder.getReason());
//        appletOrderItem.setStartTime(LocalDateTime.now());
        appletOrderItem.setUserId(appletOrder.getUserId());
        //根据用户标识查询用户认证信息
        AppUsers appUsers = appUsersService.selectAppUsersByUserId(appletOrder.getUserId());
        AppletUsersTeacher appletUsersTeacher = appletUsersTeacherService.selectAppletUsersTeacherByUserId(appletOrder.getUserId());
        appletOrderItem.setName(appletUsersTeacher.getName());
        appletOrderItem.setPhone(appletUsersTeacher.getPhone());
        appletOrderItem.setOrderStatus(3); //相当于已经取消

        //得到当前用户的伴宠师等级
        Integer userBcs = appUsers.getUserBcs();
        //查询用户的当前分配比例
        AppletConfig petPaymentBcs = configService.selectAppletConfigByClassAndNum("pet_payment_bcs", userBcs);
        //得到配置百分比
        BigDecimal percent = petPaymentBcs.getParamValueNo();
        //得到订单支付金额
        BigDecimal orderPrice = order.getPrice();
        //计算订单佣金 = 支付金额 * 百分比
        BigDecimal orderGivePrice = orderPrice.multiply(percent);
        appletOrderItem.setPrice(orderPrice);
        appletOrderItem.setOrderGiveProportion(percent);
        appletOrderItem.setOrderGivePrice(orderGivePrice);
        appletOrderItem.setAddress(order.getAddress());
        appletOrderItem.setOrderSn(order.getOrderSn());
        appletOrderItem.setOrderId(order.getOrderId());
        appletOrderItem.setIsPet(0);
        appletOrderItem.setIsDate(0);
        appletOrderItem.setIsAddress(0);
        appletOrderItem.setPayTime(order.getPayTime());


        appletOrderItemService.insertAppletOrderItem(appletOrderItem);



        appletOrder.setType("0");//派单归为派单中
        appletOrder.setStatus(0);
        appletOrder.setNum(order.getNum()+1);
        appletOrder.setUpdateTime(LocalDateTime.now());
        //根据系统派单规则给到所有的接单者 、、还需要修改现在给所有人

        //appletUserId 用json形式储存  == 》这个地方还需要调优
        AppUsers usersGo = new AppUsers();
        usersGo.setUserBcs(1);
        List<AppUsers> appUsersList = appUsersService.selectAppUsersList(usersGo);
        //得到所有的伴宠师id
        String appletUserId = "";
        for (AppUsers users : appUsersList) {
            if(!appletOrder.getUserId().equals(users.getUserId())){
                appletUserId += users.getUserId()+",";
            }
        }
        appletOrder.setUserIdJson(appletUserId);

        //清空接单人字段
        appletOrder.setUserIdJson("");

        appletOrderService.updateAppletOrder(appletOrder);
        return AjaxResult.success("拒单成功",appletOrder);
    }



    //接单大厅 - 立即接单
    @ApiOperation("接单大厅 - 立即接单")
    @PostMapping("/startByOrderId")
    @Synchronized
    @Transactional(timeout = 30)
    public AjaxResult startByOrderId(@RequestBody AppletOrder appletOrder){
        if(appletOrder.getId() == null){
            return AjaxResult.error("订单标识不能为空");
        }
        if(appletOrder.getUserId() == null){
            return AjaxResult.error("userId用户信息标识不能为空");
        }

        AppletOrder order = appletOrderService.selectAppletOrderById(appletOrder.getId());
        if (order == null){
            return AjaxResult.error("无效订单");
        }
        if(order.getStatus() == 1){
            return AjaxResult.error("该订单已被接单");
        }
        //生成我的订单信息
        AppletOrderItem appletOrderItem = new AppletOrderItem();
        long id = System.currentTimeMillis();
        appletOrderItem.setId(id);
        appletOrderItem.setCreateTime(order.getCreateTime());
        appletOrderItem.setType(order.getType());
        appletOrderItem.setStatus(1);
//        appletOrderItem.setReason(appletOrder.getReason());
        appletOrderItem.setStartTime(LocalDateTime.now());
        appletOrderItem.setUserId(appletOrder.getUserId());
        //根据用户标识查询用户认证信息
        AppUsers appUsers = appUsersService.selectAppUsersByUserId(appletOrder.getUserId());
        AppletUsersTeacher appletUsersTeacher = appletUsersTeacherService.selectAppletUsersTeacherByUserId(appletOrder.getUserId());
        appletOrderItem.setName(appletUsersTeacher.getName());
        appletOrderItem.setPhone(appletUsersTeacher.getPhone());
        appletOrderItem.setOrderStatus(0);

        //得到当前用户的伴宠师等级
        Integer userBcs = appUsers.getUserBcs();
        //查询用户的当前分配比例
        AppletConfig petPaymentBcs = configService.selectAppletConfigByClassAndNum("pet_payment_bcs", userBcs);
        //得到配置百分比
        BigDecimal percent = petPaymentBcs.getParamValueNo();
        //得到订单支付金额
        BigDecimal orderPrice = order.getPrice();
        //计算订单佣金 = 支付金额 * 百分比
        BigDecimal orderGivePrice = orderPrice.multiply(percent);
        appletOrderItem.setPrice(orderPrice);
        appletOrderItem.setOrderGiveProportion(percent);
        appletOrderItem.setOrderGivePrice(orderGivePrice);
        appletOrderItem.setAddress(order.getAddress());
        appletOrderItem.setOrderSn(order.getOrderSn());
        appletOrderItem.setOrderId(order.getOrderId());
        appletOrderItem.setIsPet(1);
        appletOrderItem.setIsDate(1);
        appletOrderItem.setIsAddress(1);


        appletOrderItemService.insertAppletOrderItem(appletOrderItem);

        order.setStatus(1);//修改状态成已接单
        order.setUserId(appletOrder.getUserId());//
        order.setAcceptTime(LocalDateTime.now());//接单时间
        order.setWhenTakOrders(ChronoUnit.SECONDS.between(order.getPayTime(), order.getAcceptTime()));//接单用时

        // 只更新必要的字段
        appletOrderService.lambdaUpdate()
            .eq(AppletOrder::getId, order.getId())
            .set(AppletOrder::getStatus, order.getStatus())
            .set(AppletOrder::getUserId, order.getUserId())
            .set(AppletOrder::getAcceptTime, order.getAcceptTime())
            .set(AppletOrder::getWhenTakOrders, order.getWhenTakOrders())
            .update();



        H5OrderVO h5OrderVO = h5OrderService.orderDetail(order.getOrderId());
        //根据服务频率 服务日期 生成日订单 【废弃】
//        for (OmsOrderService service : h5OrderVO.getOrderServiceList()) {
//            AppletOrderItemDate appletOrderItemDate = new AppletOrderItemDate();
//
//            appletOrderItemDate.setUserId(appletOrder.getUserId());
//            appletOrderItemDate.setOrderId(id);
//            appletOrderItemDate.setStatus(0);
//            appletOrderItemDate.setOrderServiceId(service.getId());
//            appletOrderItemDate.setServiceDate(service.getServiceDate());
//            appletOrderItemDate.setCityAddress(h5OrderVO.getReceiverProvince() + h5OrderVO.getReceiverCity() + h5OrderVO.getReceiverDistrict());
//            appletOrderItemDate.setAddress(h5OrderVO.getReceiverDetailAddress());
//            appletOrderItemDateService.insertAppletOrderItemDate(appletOrderItemDate);
//        }

        //TODO 这里需要优化流失订单的逻辑

        //生成其他人的流失订单
        String[] split = order.getUserIdJson().split(",");
        for (String s : split) {

            if (Long.parseLong(s) != appletOrder.getUserId()) {
                AppletOrderItem appletOrderItemOther = new AppletOrderItem();
                appletOrderItemOther.setCreateTime(order.getCreateTime());
                appletOrderItemOther.setType(order.getType());
                appletOrderItemOther.setStatus(2);
                appletOrderItemOther.setReason("被其他伴宠师接单");
                appletOrderItemOther.setUserId(Long.valueOf(s));
                //根据用户标识查询用户认证信息
                AppUsers appUsersOther = appUsersService.selectAppUsersByUserId(Long.valueOf(s));

                if (ObjectUtils.isEmpty(appUsersOther)){
                    continue;
                }

                AppletUsersTeacher appletUsersTeacherOther = appletUsersTeacherService.selectAppletUsersTeacherByUserId(Long.valueOf(s));
                if (ObjectUtils.isNotEmpty(appletUsersTeacherOther)){
                    appletOrderItemOther.setName(appletUsersTeacherOther.getName());
                    appletOrderItemOther.setPhone(appletUsersTeacherOther.getPhone());
                }
                appletOrderItemOther.setOrderStatus(3); //相当于已经取消

                //得到当前用户的伴宠师等级
                Integer userBcsOther = appUsersOther.getUserBcs();
                //查询用户的当前分配比例
                AppletConfig petPaymentBcsOther = configService.selectAppletConfigByClassAndNum("pet_payment_bcs", userBcsOther);
                //得到配置百分比
                BigDecimal percentOther = petPaymentBcsOther.getParamValueNo();
                //得到订单支付金额
                BigDecimal orderPriceOther = order.getPrice();
                //计算订单佣金 = 支付金额 * 百分比
                BigDecimal orderGivePriceOther = orderPriceOther.multiply(percentOther);
                appletOrderItemOther.setPrice(orderPrice);
                appletOrderItemOther.setOrderGiveProportion(percent);
                appletOrderItemOther.setOrderGivePrice(orderGivePriceOther);
                appletOrderItemOther.setAddress(order.getAddress());
                appletOrderItemOther.setOrderSn(order.getOrderSn());
                appletOrderItemOther.setOrderId(order.getOrderId());
                appletOrderItemOther.setIsPet(0);
                appletOrderItemOther.setIsDate(0);
                appletOrderItemOther.setIsAddress(0);
                appletOrderItemOther.setPayTime(order.getPayTime());


                appletOrderItemService.insertAppletOrderItem(appletOrderItemOther);
            }

        }


        //生成下单小程序的订单记录
        OrderOperateHistory optHistory = new OrderOperateHistory();
        optHistory.setOrderId(order.getOrderId());
        optHistory.setOrderSn(order.getOrderSn());
        optHistory.setOperateMan("接单伴宠师-" + order.getUserId());
        optHistory.setOrderStatus(Constants.H5OrderStatus.DELIVERED);
        optHistory.setCreateTime(LocalDateTime.now());
        optHistory.setCreateBy(order.getUserId());
        optHistory.setUpdateBy(order.getUserId());
        optHistory.setUpdateTime(LocalDateTime.now());
        orderOperateHistoryMapper.insert(optHistory);

        //修改下单小程序的订单状态
        Order omsOrder = orderMapper.selectById(order.getOrderId());

        if (omsOrder != null && omsOrder.getStatus() == Constants.H5OrderStatus.NOT_DELIVERED){
            omsOrder.setStatus(Constants.H5OrderStatus.DELIVERED);
            omsOrder.setAcceptAppUserId(order.getUserId());
            orderMapper.updateById(omsOrder);
        }else {
            throw new ServiceException("订单已被接单");
        }


        // 生成日订单数据
        appletOrderDateFrequencyService.aceptOrdersGenerateDayOrdersByOrderVO(h5OrderVO, appletOrder.getUserId());

        return AjaxResult.success("接单成功",appletOrder);
    }



    //我的订单流程
    @ApiOperation("小程序-我的订单流程-总订单")
    @GetMapping("/myList")
    public AjaxResult myList(AppletOrderItem orderItem){
        if(orderItem.getOrderStatus()==null){
            return AjaxResult.error("orderStatus状态不能为空");
        }
        if(orderItem.getUserId() == null){
            return AjaxResult.error("userId用户信息标识不能为空");
        }
        List<AppletOrderItem> itemList = appletOrderItemService.selectAppletOrderItemList(orderItem);
//        for (AppletOrderItem item:itemList){
//            H5OrderVO h5OrderVO = h5OrderService.orderDetail(item.getOrderId());
//            //得到服务信息
//            List<OmsOrderService> service = h5OrderVO.getOrderServiceList();
//            List<PetVO> petVOList = new ArrayList<>();
//            for (OmsOrderService service1:service){
//                //宠物标识不为空的时候查询数据
//                if(service1.getPetId()!=null){
//                    PetVO petVO = h5PetService.selectPetById(service1.getPetId());
//                    service1.setPetVo(petVO);
//                    petVOList.add(petVO);
//                }
//            }
//            h5OrderVO.setPetVOList(petVOList);
//            item.setH5OrderVO(h5OrderVO);
//        }
        for (AppletOrderItem item:itemList){
            H5OrderVO h5OrderVO = h5OrderService.orderDetail(item.getOrderId());
            // 得到服务信息
            List<OmsOrderService> service = h5OrderVO.getOrderServiceList();

            // 使用一个 Set 来跟踪已经添加的 PetVO 的 id
            Set<Integer> addedPetIds = new HashSet<>();
            List<PetVO> petVOList = new ArrayList<>();

            for (OmsOrderService service1 : service) {
                // 宠物标识不为空的时候查询数据
                if (service1.getPetId() != null) {
                    PetVO petVO = h5PetService.selectPetById(service1.getPetId());

                    // 检查 petVO 的 id 是否已经添加过
                    if (petVO != null && !addedPetIds.contains(petVO.getId())) {
                        service1.setPetVo(petVO);
                        petVOList.add(petVO);
                        addedPetIds.add(petVO.getId()); // 标记该 id 已添加
                    }
                }
            }




            h5OrderVO.setPetVOList(petVOList);
            item.setH5OrderVO(h5OrderVO);
        }
        TableDataInfo dataTable = getDataTable(itemList);
        return AjaxResult.success("我的订单数据列表",dataTable);
    }



//
//    //我的订单流程
//    @ApiOperation("小程序-我的订单流程-日订单")
//    @GetMapping("/myDateList")
//    public AjaxResult myDateList(AppletOrderDateVo dateVo){
//        if(dateVo.getUserId() == null){
//            return AjaxResult.error("userId用户标识不能为空");
//        }
//        if(dateVo.getStatus() == null){
//            return AjaxResult.error("status当前状态不能为空");
//        }
//
//        //查询我所有的日订单数据
//        AppletOrderItemDate date = new AppletOrderItemDate();
//        date.setUserId(dateVo.getUserId());
//        date.setStatus(dateVo.getStatus());
//        List<AppletOrderItemDate> addressList = appletOrderItemDateService.selectAppletOrderItemDateList(date);
//
//        Set<String> uniqueDates = new HashSet<>();
//        List<AppletOrderDateVoReturn> dateVoReturnList = new ArrayList<>();
//
//        for (AppletOrderItemDate date1 : addressList) {
//            if (uniqueDates.add(date1.getServiceDate())) {
//                AppletOrderDateVoReturn dateVoReturn = new AppletOrderDateVoReturn();
//                dateVoReturn.setServiceDate(date1.getServiceDate());
//
//                if(dateVo.getStatus() == 1){
//                    AppletOrderItem orders = appletOrderItemService.selectAppletOrderItemById(date1.getOrderId());
//                    if(orders.getOrderStatus()==2){
//                        dateVoReturnList.add(dateVoReturn);
//                    }
//                }else{
//                    dateVoReturnList.add(dateVoReturn);
//                }
//
//            }
//        }
//
//
//        //得到日订单集合
//        for (AppletOrderDateVoReturn dateVoReturn : dateVoReturnList) {
//            //得到日订单日期
//            String serviceDate = dateVoReturn.getServiceDate();
//
//            //订单下订单集合
//            AppletOrderItemDate service = new AppletOrderItemDate();
//            service.setServiceDate(serviceDate);
//
//            List<AppletOrderItemDate> serviceList = appletOrderItemDateService.selectAppletOrderItemDateList(service);
//            List<AppletOrderDateAddressReturn> uniqueOrderDetails = serviceList.stream()
//                    .collect(Collectors.toMap(
//                            AppletOrderItemDate::getOrderId, // 使用orderId作为键
//                            item -> new AppletOrderDateAddressReturn(item.getOrderId(), item.getCityAddress(), item.getAddress()), // 创建OrderDetails对象作为值
//                            (existing, replacement) -> existing // 如果有重复的orderId，保留现有的（可以根据需要修改合并逻辑）
//                    ))
//                    .values()
//                    .stream()
//                    .collect(Collectors.toList());
//            // 假设dateVoReturn有一个setOrderList方法
//
//            dateVoReturn.setOrderList(uniqueOrderDetails);
//            dateVoReturn.setNum(uniqueOrderDetails.size());
//
//            for (AppletOrderDateAddressReturn uniqueOrderDetail : uniqueOrderDetails) {
//                AppletOrderItemDate appletOrderItemDate = new AppletOrderItemDate();
//                appletOrderItemDate.setOrderId(uniqueOrderDetail.getOrderId());
//                appletOrderItemDate.setServiceDate(serviceDate);
//
//
//                List<AppletOrderItemDate> appletOrderItemDates = appletOrderItemDateService.selectAppletOrderItemDateList(appletOrderItemDate);
//                for (AppletOrderItemDate appletOrderItemDate1 : appletOrderItemDates) {
//                    // 组装item
//                    QueryWrapper<OrderItem> orderItemQw = new QueryWrapper<>();
//                    orderItemQw.eq("order_service_id", appletOrderItemDate1.getOrderServiceId());
//                    List<OrderItem> orderItemList = orderItemMapper.selectList(orderItemQw);
//                    appletOrderItemDate1.setOrderItemList(orderItemList);
//
//
//                    OmsOrderService omsOrderService = omsOrderServiceMapper.selectById(appletOrderItemDate1.getOrderServiceId());
//                    omsOrderService.setPetVo(h5PetService.selectPetById(omsOrderService.getPetId()));
//                    appletOrderItemDate1.setOrderServiceList(omsOrderService);
//                }
//
//                uniqueOrderDetail.setAppletOrderItemDate(appletOrderItemDates);
//
//
//
//            }
//
//
//        }
//
//
//
//
//
//
//
//        return AjaxResult.success("日订单数据",dateVoReturnList);
//    }



    @ApiOperation("小程序-我的订单流程-日订单")
    @GetMapping("/myDateList")
    public AjaxResult myDateList(AppletOrderDateVo dateVo) {
        if (dateVo.getUserId() == null) {
            return AjaxResult.error("userId用户标识不能为空");
        }
        if (dateVo.getStatus() == null) {
            return AjaxResult.error("status当前状态不能为空");
        }

        // 查询我所有的日订单数据
        AppletOrderItemDate date = new AppletOrderItemDate();
        date.setUserId(dateVo.getUserId());
        date.setStatus(dateVo.getStatus());
        List<AppletOrderItemDate> addressList = appletOrderItemDateService.selectAppletOrderItemDateList(date);

        // 用于存储按日期分组的订单
        Map<String, List<AppletOrderItemDate>> dateToOrdersMap = new HashMap<>();

        for (AppletOrderItemDate dateItem : addressList) {
            String serviceDate = dateItem.getServiceDate();
            dateToOrdersMap.computeIfAbsent(serviceDate, k -> new ArrayList<>()).add(dateItem);
        }

        List<AppletOrderDateVoReturn> dateVoReturnList = new ArrayList<>();

        // 遍历每个日期
        for (Map.Entry<String, List<AppletOrderItemDate>> entry : dateToOrdersMap.entrySet()) {
            String serviceDate = entry.getKey();
            List<AppletOrderItemDate> ordersForDate = entry.getValue();

            // 遍历该日期的所有订单
            for (AppletOrderItemDate orderItemDate : ordersForDate) {
                AppletOrderDateVoReturn dateVoReturn = new AppletOrderDateVoReturn();
                dateVoReturn.setServiceDate(serviceDate);

                if (dateVo.getStatus() == 1) {
                    AppletOrderItem orders = appletOrderItemService.selectAppletOrderItemById(orderItemDate.getOrderId());
                    if (orders.getOrderStatus() == 2) {
                        // 直接添加，不进行过滤
                        dateVoReturnList.add(dateVoReturn);
                    }
                } else {
                    dateVoReturnList.add(dateVoReturn);
                }

                // 设置订单详情
                List<AppletOrderDateAddressReturn> orderDetailsList = new ArrayList<>();
                AppletOrderDateAddressReturn orderDetails = new AppletOrderDateAddressReturn(
                        orderItemDate.getOrderId(),
                        orderItemDate.getCityAddress(),
                        orderItemDate.getAddress()
                );
                orderDetailsList.add(orderDetails);

                dateVoReturn.setOrderList(orderDetailsList);
                dateVoReturn.setNum(orderDetailsList.size());

                // 设置订单项
                AppletOrderItemDate appletOrderItemDate = new AppletOrderItemDate();
                appletOrderItemDate.setOrderId(orderItemDate.getOrderId());
                appletOrderItemDate.setServiceDate(serviceDate);

                List<AppletOrderItemDate> appletOrderItemDates = appletOrderItemDateService.selectAppletOrderItemDateList(appletOrderItemDate);
                for (AppletOrderItemDate itemDate : appletOrderItemDates) {
                    QueryWrapper<OrderItem> orderItemQw = new QueryWrapper<>();
                    orderItemQw.eq("order_service_id", itemDate.getOrderServiceId());
                    List<OrderItem> orderItemList = orderItemMapper.selectList(orderItemQw);
                    itemDate.setOrderItemList(orderItemList);

                    OmsOrderService omsOrderService = omsOrderServiceMapper.selectById(itemDate.getOrderServiceId());
                    omsOrderService.setPetVo(h5PetService.selectPetById(omsOrderService.getPetId()));
                    itemDate.setOrderServiceList(omsOrderService);
                }

                orderDetails.setAppletOrderItemDate(appletOrderItemDates);
            }
        }

        return AjaxResult.success("日订单数据", dateVoReturnList);
    }

//
//    @ApiOperation("小程序-我的订单流程-日订单")
//    @GetMapping("/myDateList")
//    public AjaxResult myDateList(AppletOrderDateVo dateVo) {
//        if (dateVo.getUserId() == null) {
//            return AjaxResult.error("userId用户标识不能为空");
//        }
//        if (dateVo.getStatus() == null) {
//            return AjaxResult.error("status当前状态不能为空");
//        }
//
//        // 查询我所有的日订单数据
//        AppletOrderItemDate date = new AppletOrderItemDate();
//        date.setUserId(dateVo.getUserId());
//        date.setStatus(dateVo.getStatus());
//        List<AppletOrderItemDate> addressList = appletOrderItemDateService.selectAppletOrderItemDateList(date);
//
//        // 用于存储按日期分组的订单
//        Map<String, List<AppletOrderItemDate>> dateToOrdersMap = new HashMap<>();
//
//        for (AppletOrderItemDate dateItem : addressList) {
//            String serviceDate = dateItem.getServiceDate();
//            dateToOrdersMap.computeIfAbsent(serviceDate, k -> new ArrayList<>()).add(dateItem);
//        }
//
//        List<AppletOrderDateVoReturn> dateVoReturnList = new ArrayList<>();
//
//        // 遍历每个日期
//        for (Map.Entry<String, List<AppletOrderItemDate>> entry : dateToOrdersMap.entrySet()) {
//            String serviceDate = entry.getKey();
//            List<AppletOrderItemDate> ordersForDate = entry.getValue();
//
//            // 创建一个合并的订单对象
//            AppletOrderDateVoReturn dateVoReturn = new AppletOrderDateVoReturn();
//            dateVoReturn.setServiceDate(serviceDate);
//
//            // 合并订单的地址信息（假设所有订单地址相同，或者选择第一个订单的地址）
//            if (!ordersForDate.isEmpty()) {
//                AppletOrderItemDate firstOrder = ordersForDate.get(0);
//                AppletOrderDateAddressReturn orderDetails = new AppletOrderDateAddressReturn(
//                        firstOrder.getOrderId(),
//                        firstOrder.getCityAddress(),
//                        firstOrder.getAddress()
//                );
//
//                List<AppletOrderDateAddressReturn> orderDetailsList = new ArrayList<>();
//                orderDetailsList.add(orderDetails);
//
//                dateVoReturn.setOrderList(orderDetailsList);
//                dateVoReturn.setNum(ordersForDate.size()); // 设置订单数量
//
//                // 设置订单项
//                List<AppletOrderItemDate> appletOrderItemDates = new ArrayList<>();
//                for (AppletOrderItemDate orderItemDate : ordersForDate) {
//                    AppletOrderItemDate itemDate = new AppletOrderItemDate();
//                    itemDate.setOrderId(orderItemDate.getOrderId());
//                    itemDate.setServiceDate(serviceDate);
//
//                    // 查询订单项信息
//                    QueryWrapper<OrderItem> orderItemQw = new QueryWrapper<>();
//                    orderItemQw.eq("order_service_id", itemDate.getOrderServiceId());
//                    List<OrderItem> orderItemList = orderItemMapper.selectList(orderItemQw);
//                    itemDate.setOrderItemList(orderItemList);
//
//                    OmsOrderService omsOrderService = omsOrderServiceMapper.selectById(itemDate.getOrderServiceId());
//                    omsOrderService.setPetVo(h5PetService.selectPetById(omsOrderService.getPetId()));
//                    itemDate.setOrderServiceList(omsOrderService);
//
//                    appletOrderItemDates.add(itemDate);
//                }
//
//                orderDetails.setAppletOrderItemDate(appletOrderItemDates);
//            }
//
//            // 添加合并后的订单到结果列表
//            dateVoReturnList.add(dateVoReturn);
//        }
//
//        return AjaxResult.success("日订单数据", dateVoReturnList);
//    }




    //我的订单流程
    @ApiOperation("小程序-我的订单流程订单详情")
    @GetMapping("/getOrderItemById")
    public AjaxResult getOrderItemById(AppletOrderItem orderItem){
        if(orderItem.getId() == null){
            return AjaxResult.error("订单标识不能为空");
        }
        if(orderItem.getUserId() == null){
            return AjaxResult.error("用户标识不能为空");
        }
        AppletOrderItem order = appletOrderItemService.selectAppletOrderItemById(orderItem.getId());
//        H5OrderVO h5OrderVO1 = h5OrderService.orderDetail(order.getOrderId());

        H5OrderVO h5OrderVO = h5OrderService.orderDetail(order.getOrderId());
        //得到服务信息
        List<OmsOrderService> service = h5OrderVO.getOrderServiceList();
        List<PetVO> petVOList = new ArrayList<>();
        for (OmsOrderService service1:service){
            //宠物标识不为空的时候查询数据
            if(service1.getPetId()!=null){
                PetVO petVO = h5PetService.selectPetById(service1.getPetId());
                service1.setPetVo(petVO);
                petVOList.add(petVO);
            }
            h5OrderVO.setPetVOList(petVOList);
        }
        order.setH5OrderVO(h5OrderVO);
//        order.setManagerOrderDetailVO(service.selectById(order.getOrderId()));
        Map<String, Object> map = new HashMap();
        map.put("order",order);
        AppletConfig config = new AppletConfig();
        config.setParamClass("pet_payment_bcs");
        List<AppletConfig> appletConfigs = configService.selectAppletConfigList(config);
        map.put("pet_payment_bcs",appletConfigs);
        return AjaxResult.success("我的订单流程订单详情",map);
    }




    //订单里面的宠物档案里面数据
    @ApiOperation("订单里面的宠物档案里面数据")
    @GetMapping("/getOrderPetById/{orderId}")
    public AjaxResult getOrderPetById(@PathVariable("orderId") Long orderId){
        H5OrderVO h5OrderVO = h5OrderService.orderDetail(orderId);
        // 得到服务信息
        List<OmsOrderService> service = h5OrderVO.getOrderServiceList();
        // 使用一个 Set 来跟踪已经添加的 PetVO 的 id
        Set<Integer> addedPetIds = new HashSet<>();
        List<Pet> petList = new ArrayList<>();

        for (OmsOrderService service1 : service) {
            // 宠物标识不为空的时候查询数据
            if (service1.getPetId() != null) {
                Pet pet = petMapper.selectById(service1.getPetId());
                // 检查 petVO 的 id 是否已经添加过
                if (pet != null && !addedPetIds.contains(pet.getId())) {
                    service1.setPets(pet);
                    petList.add(pet);
                    addedPetIds.add(pet.getId()); // 标记该 id 已添加
                }
            }

        }

//        List<PetVO> pets = new ArrayList<>();
//        for (OmsOrderService service1 : service) {
//            // 宠物标识不为空的时候查询数据
//            if (service1.getPetId() != null) {
//                PetVO petVO = h5PetService.selectPetById(service1.getPetId());
//                // 检查 petVO 的 id 是否已经添加过
//                if (petVO != null && !addedPetIds.contains(petVO.getId())) {
//                    service1.setPetVo(petVO);
//                    pets.add(petVO);
//                    addedPetIds.add(petVO.getId()); // 标记该 id 已添加
//                }
//            }
//
//        }






        return AjaxResult.success("订单里面的宠物档案里面数据",petList);
    }


    //根据宠物标识查询重新宠物信息
    @ApiOperation("根据宠物标识查询重新宠物信息")
    @GetMapping("/getPetById/{petId}")
    public AjaxResult getPetById(@PathVariable("petId") Integer petId){
        PetVO petVO = h5PetService.selectPetById(petId);
        return AjaxResult.success("根据宠物标识查询重新宠物信息",petVO);
    }



    //根据宠物信息标识查询宠物档案信息列表带分页
    @ApiOperation("根据宠物信息标识查询宠物档案信息列表带分页")
    @GetMapping("/petList")
    public TableDataInfo petList(PetCare petCare) {
        startPage();
        List<PetCare> list = petCareService.selectPetCareList(petCare);
        return getDataTable(list);
    }



    //根据宠物信息查询宠物档案信息
    @ApiOperation("根据宠物信息标识查询宠物档案信息列表带分页")
    @GetMapping("/getPetCareByPetId/{petId}")
    public AjaxResult petCareList(@PathVariable("petId") Integer petId) {
        PetCare petCare1 = petCareService.selectPetCareByPetId(petId);
        return AjaxResult.success("服务档案信息查询成功",petCare1);
    }








    //测试派单
    @ApiOperation("派单")
    @GetMapping("/dispatch/{orderId}")
    public AjaxResult dispatch(@PathVariable("orderId")Long orderId){
        mallOrderService.dispatch(orderId);
        return AjaxResult.success("派单成功");
    }










}
