package com.ylx.massage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylx.common.core.domain.R;
import com.ylx.massage.domain.MerchantDailyAttendance;
import com.ylx.massage.domain.dto.MerchantDailyAttendanceQueryDTO;
import com.ylx.massage.service.MerchantDailyAttendanceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 商户每日考勤统计表(MerchantDailyAttendance)表控制层
 *
 * @author makejava
 * @since 2026-06-05 11:16:04
 */
@RestController
@RequestMapping("merchantDailyAttendance")
public class MerchantDailyAttendanceController  {
    /**
     * 服务对象
     */
    @Resource
    private MerchantDailyAttendanceService merchantDailyAttendanceService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param queryDTO 查询参数
     * @return R 所有数据
     */
    @GetMapping("/queryDailyAttendance")
    public R selectAll(Page<MerchantDailyAttendance> page, MerchantDailyAttendanceQueryDTO queryDTO) {
        try {
            return R.ok(this.merchantDailyAttendanceService.queryDailyAttendance(page, queryDTO));
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    /**
     * 查询商户指定日期的工作时间明细
     *
     * @param merchantId 商户ID
     * @param attendanceDate 考勤日期，格式：yyyy-MM-dd
     * @return R 工作时间明细
     */
    @GetMapping("/queryDailyWorkTime")
    public R queryDailyWorkTime(@RequestParam("merchantId") Integer merchantId, @RequestParam("attendanceDate") String attendanceDate) {
        try {
            return R.ok(this.merchantDailyAttendanceService.queryDailyWorkTime(merchantId, attendanceDate));
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return R.ok(this.merchantDailyAttendanceService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param merchantDailyAttendance 实体对象
     * @return 新增结果
     */
    @PostMapping
    public R insert(@RequestBody MerchantDailyAttendance merchantDailyAttendance) {
        return R.ok(this.merchantDailyAttendanceService.save(merchantDailyAttendance));
    }

    /**
     * 修改数据
     *
     * @param merchantDailyAttendance 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody MerchantDailyAttendance merchantDailyAttendance) {
        return R.ok(this.merchantDailyAttendanceService.updateById(merchantDailyAttendance));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return R.ok(this.merchantDailyAttendanceService.removeByIds(idList));
    }
}

