package com.yida.data.school.news.controller.out;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.notice.EduNoticeSchool;
import com.yida.data.common.core.entity.system.Dept;
import com.yida.data.school.news.service.EduNoticeSchoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.time.LocalTime;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "通知咨询-学校通知(不鉴权)")
@RestController
@RequestMapping("/out/news/school")
@RequiredArgsConstructor
public class OutEduNoticeSchoolController {

    private final EduNoticeSchoolService eduNoticeSchoolService;

    @ApiOperation("查询公告数量")
    @GetMapping("/countNotice")
    public ResultBean<Integer> countNotice(String startDate, String endDate, Long[] schoolIds) {
        return ResultBean.buildSuccess(
            ArrayUtil.isNotEmpty(schoolIds) ? (int) eduNoticeSchoolService.count(Wrappers.<EduNoticeSchool>lambdaQuery()
                .eq(EduNoticeSchool::getIsDraft, 0)
                .in(EduNoticeSchool::getSchoolId, Arrays.asList(schoolIds))
                .between(EduNoticeSchool::getCreateDate, LocalDateTimeUtil.parseDate(startDate).atStartOfDay(),
                    LocalDateTimeUtil.parseDate(endDate).atTime(LocalTime.MAX))) : 0);
    }
}
