package com.ruoyi.model.controller;

import java.util.List;

import com.ruoyi.model.domain.AppletOrderItemDateLog;
import com.ruoyi.model.service.IAppletOrderItemDateLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.model.domain.AppletOrderDateFrequency;
import com.ruoyi.model.service.IAppletOrderDateFrequencyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 日订单Controller
 * 
 * @author daixiande
 * @date 2025-05-28
 */
@RestController
@RequestMapping("/model/appletOrderDateFrequency")
public class AppletOrderDateFrequencyController extends BaseController {

    @Autowired
    private IAppletOrderDateFrequencyService appletOrderDateFrequencyService;

    @Autowired
    private IAppletOrderItemDateLogService appletOrderItemDateLogService;

    /**
     * 查询日订单列表
     */
    @PreAuthorize("@ss.hasPermi('model:appletOrderDateFrequency:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppletOrderDateFrequency appletOrderDateFrequency) {
        startPage();
        List<AppletOrderDateFrequency> list = appletOrderDateFrequencyService.selectAppletOrderDateFrequencyList(appletOrderDateFrequency);
        list.forEach(appletOrderDateFrequencyService::buildUserData);
        return getDataTable(list);
    }

    /**
     * 导出日订单列表
     */
    @PreAuthorize("@ss.hasPermi('model:appletOrderDateFrequency:export')")
    @Log(title = "日订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppletOrderDateFrequency appletOrderDateFrequency) {
        List<AppletOrderDateFrequency> list = appletOrderDateFrequencyService.selectAppletOrderDateFrequencyList(appletOrderDateFrequency);
        ExcelUtil<AppletOrderDateFrequency> util = new ExcelUtil<AppletOrderDateFrequency>(AppletOrderDateFrequency.class);
        return util.exportExcel(list, "日订单数据");
    }

    /**
     * 获取日订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:appletOrderDateFrequency:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(appletOrderDateFrequencyService.selectAppletOrderDateFrequencyById(id));
    }

    /**
     * 获取日订单打卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:appletOrderDateFrequency:query')")
    @GetMapping(value = "/check/{id}")
    public AjaxResult getCheck(@PathVariable("id") Long id) {
        AppletOrderItemDateLog check = appletOrderItemDateLogService.selectAppletOrderItemDateLogByItemDateId(id);
        return AjaxResult.success(check);
    }

    /**
     * 新增日订单
     */
    @PreAuthorize("@ss.hasPermi('model:appletOrderDateFrequency:add')")
    @Log(title = "日订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletOrderDateFrequency appletOrderDateFrequency) {
        return toAjax(appletOrderDateFrequencyService.insertAppletOrderDateFrequency(appletOrderDateFrequency));
    }

    /**
     * 修改日订单
     */
    @PreAuthorize("@ss.hasPermi('model:appletOrderDateFrequency:edit')")
    @Log(title = "日订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletOrderDateFrequency appletOrderDateFrequency) {
        return toAjax(appletOrderDateFrequencyService.updateAppletOrderDateFrequency(appletOrderDateFrequency));
    }

    /**
     * 删除日订单
     */
    @PreAuthorize("@ss.hasPermi('model:appletOrderDateFrequency:remove')")
    @Log(title = "日订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appletOrderDateFrequencyService.deleteAppletOrderDateFrequencyByIds(ids));
    }
}
