package com.kxs.system.biz.controller.kxsapp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kxs.common.core.util.AssertUtil;
import com.kxs.common.core.util.R;
import com.kxs.system.api.dto.kxsapp.AddStudyPersonDTO;
import com.kxs.system.api.model.KxsMorning;
import com.kxs.system.biz.service.KxsMorningService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.web.bind.annotation.*;

/**
 * 首页(Morning)控制层
 *
 * @author 系统
 * @since 2023-12-15 12:16:33
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("morning")
public class MorningController {

    /**
     * 服务对象
     */
    private final KxsMorningService kxsMorningService;

    /**
     * 商学院-晨会列表
     *
     * @param page 分页对象
     * @return 商学院-晨会列表
     */
    @GetMapping("/page")
    public R page(@ParameterObject Page<KxsMorning> page,@RequestParam("month") String month) {
        AssertUtil.isYyyyMM(month);
        String skbYear = month.substring(0, 4);
        String subMonth = month.substring(5, 7);
        //拼接sql
        return R.ok(kxsMorningService.page(page,
                new QueryWrapper<KxsMorning>()
                        .apply("YEAR(create_time) = {0} AND MONTH(create_time) = {1}", skbYear, subMonth)
                        .orderByDesc("create_time")));
    }



    /**
     * 商学院-晨会列表-增加学习人数
     *
     * @param addStudyPersonDTO 参数对象
     * @return 商学院-晨会列表
     */
    @PostMapping("/addStudyPerson")
    public R addStudyPerson(@Valid @RequestBody AddStudyPersonDTO addStudyPersonDTO) {
        return kxsMorningService.addStudyPerson(addStudyPersonDTO.getId(),addStudyPersonDTO.getType());
    }




}

