package com.joju.datamanager.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.joju.datamanager.common.result.Result;
import com.joju.datamanager.common.result.ResultUtil;
import com.joju.datamanager.model.lisris.LisRis;
import com.joju.datamanager.service.LisRisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: lisris报告接口
 * @author: Mr.zs
 * @create: 2024-04-17 12:28
 **/
@RestController
@RequestMapping("/lisRis")
public class LisRisController {

    @Autowired
    LisRisService lisRisService;

    @GetMapping("/getLisRis")
    public Result getLisRis() {
        String today = DateUtil.today();
        DateTime tomorrow = DateUtil.tomorrow();
        String tomorrowStr = DateUtil.formatDate(tomorrow);
        List<LisRis> lisRises = lisRisService.list(new QueryWrapper<LisRis>().between("bgfbsj", today, tomorrowStr));
        if (CollUtil.isNotEmpty(lisRises)) {
            return ResultUtil.successData(lisRises);
        }
        return ResultUtil.failureMsg("获取失败");
    }

    @PostMapping("/insertLisRis")
    public Result insertLisRis(@RequestBody List<LisRis> lisRises) {
        boolean b = lisRisService.saveBatch(lisRises);
        if (b) {
            return ResultUtil.success();
        }
        return ResultUtil.failureMsg("插入失败!");
    }

}
