package com.joju.datamanager.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.joju.datamanager.common.annotation.EleganceLog;
import com.joju.datamanager.common.result.Result;
import com.joju.datamanager.common.result.ResultUtil;
import com.joju.datamanager.model.order.Order;
import com.joju.datamanager.model.order.OrderVo;
import com.joju.datamanager.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 患者预约记录接口
 * @author: Mr.zs
 * @create: 2024-03-27 18:52
 **/
@RestController
@RequestMapping(value = "/order")
@Slf4j
public class OrderController {


    @Autowired
    OrderService orderService;


    /**
     * 获取预约到今天的挂号订单信息
     *
     * @param yyrq
     * @return
     */

    @GetMapping("/getOrderByDate")
    @EleganceLog(description = "根据日期获取预约订单")
    public Result getOrderByDate(String yyrq) {
        List<Order> orders = orderService.list(new QueryWrapper<Order>().eq("yyrq", yyrq).eq("status", "0"));
        if (!CollUtil.isEmpty(orders)) {
            return ResultUtil.successData(orders);
        }
        return ResultUtil.failureMsg("获取失败");
    }

    @GetMapping("/getOrderByDateAndDist")
    @EleganceLog(description = "根据日期获取预约订单以及关联的人员信息")
    public Result getOrderByDateAndDist(String yyrq) {
        //查到当日就诊的所有订单以及患者信息，根据真实姓名去重
        List<OrderVo> orderVos = orderService.getOrderByDateAndDist(yyrq);
        if (!CollUtil.isEmpty(orderVos)) {
            return ResultUtil.successData(orderVos);
        }
        return ResultUtil.failureMsg("获取失败");
    }
    @PostMapping("/insertMissedAppoints")
    @EleganceLog(description = "批量插入爽约记录")
    public Result insertMissedApponits(@RequestBody List<OrderVo> orderVos) {
        Integer i = orderService.insertMissedAppoints(orderVos);
        if (i > 0) {
            return ResultUtil.success();
        }
        return ResultUtil.failureMsg("插入失败！");
    }

}
