package jnpf.attendance.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.Operation;
import jnpf.attendance.service.AttendanceNoticeService;
import jnpf.base.ActionResult;
import jnpf.model.attendance.dto.NoticeContentInfoDto;
import jnpf.model.attendance.vo.NoticeConfirmListVo;
import jnpf.model.attendance.vo.NoticeContentInfoVo;
import jnpf.util.CustomTenantUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.websocket.server.PathParam;

/**
 * 考勤消息通知
 *
 * @author shitou
 * @email shitou@niujiekeji.com
 * @date 2024-08-08 10:49:41
 */
@Slf4j
@RestController
@RequestMapping("/attendance/notice")
public class AttendanceNoticeController {
    @Resource
    private CustomTenantUtil customTenantUtil;
    @Autowired
    private AttendanceNoticeService attendanceNoticeService;


    @Operation(summary = "内容详情")
    @GetMapping(value = "/getContentInfo")
    public ActionResult<NoticeContentInfoVo> getContentInfo(@Valid NoticeContentInfoDto req) {
        try {
            log.info("内容详情，入参=>{}", JSONObject.toJSON(req));
            long st = System.currentTimeMillis();
            NoticeContentInfoVo data = attendanceNoticeService.getContentInfo(req);
            long ent = System.currentTimeMillis();
            log.info("内容详情，耗时=>{}", ent - st + " 毫秒");
            return ActionResult.success(data);
        } catch (Exception e) {
            e.printStackTrace();
            return ActionResult.fail(e.getMessage());
        }
    }

    @Operation(summary = "考勤通知-确认")
    @PostMapping(value = "/confirm/{id}")
    public ActionResult noticeConfirm(@PathVariable("id") String id) {
        attendanceNoticeService.noticeConfirm(id);
        return ActionResult.success();
    }

    @Operation(summary = "考勤通知-确认列表")
    @GetMapping(value = "confirmList/{id}")
    public ActionResult<NoticeConfirmListVo> getNoticeConfirmList(@PathVariable("id") String id) {
        return ActionResult.success(attendanceNoticeService.getNoticeConfirmList(id));
    }
}
