package com.flossom.miniProgram.controller;

import java.util.List;

import com.flossom.common.core.domain.R;
import com.flossom.common.core.domain.entity.WxNursingLog;
import com.flossom.common.core.domain.req.WxNursingLogReq;
import com.flossom.common.core.web.controller.BaseController;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.common.core.web.page.TableDataInfo;
import com.flossom.miniProgram.service.IWxNursingLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 用户护理日志Controller
 *
 * @author flossom
 * @date 2024-01-29
 */
@RestController
@RequestMapping("/nursingLog")
public class WxNursingLogController extends BaseController {

    @Autowired
    private IWxNursingLogService wxNursingLogService;

    /**
     * 查询用户护理记录
     */
    @GetMapping("/record")
    public TableDataInfo record(@RequestParam(value = "instrumentId", required = false) Long instrumentId) {
        startPage();
        List<WxNursingLog> list = wxNursingLogService.selectWxNursingLogList(instrumentId);
        return getDataTable(list);
    }

    /**
     * 查询用户护理记录的当月统计信息
     */
    @GetMapping("/statistics")
    public R statistics(@RequestParam(value = "instrumentId") Long instrumentId) {
        return R.ok(wxNursingLogService.statistics(instrumentId));
    }


    /**
     * 新增用户护理日志
     */
    @PostMapping("/add")
    public R add(@Validated @RequestBody WxNursingLogReq wxNursingLogReq) {
        wxNursingLogService.insertWxNursingLog(wxNursingLogReq);
        return R.ok();
    }
}
