package com.xzzn.web.controller.ems;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.xzzn.common.annotation.Log;
import com.xzzn.common.core.controller.BaseController;
import com.xzzn.common.core.domain.AjaxResult;
import com.xzzn.common.enums.BusinessType;
import com.xzzn.ems.domain.EmsStrategyTimeConfig;
import com.xzzn.ems.service.IEmsStrategyTimeConfigService;

/**
 * 时间配置Controller
 *
 * @author xzzn
 * @date 2025-07-11
 */
@RestController
@RequestMapping("/strategy/timeConfig")
public class EmsStrategyTimeConfigController extends BaseController
{
    @Autowired
    private IEmsStrategyTimeConfigService emsStrategyTimeConfigService;

    /**
     * 查询时间配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:list')")
    @GetMapping("/list")
    public AjaxResult list(EmsStrategyTimeConfig emsStrategyTimeConfig)
    {
        return  success(emsStrategyTimeConfigService.getStrategyTimeList(emsStrategyTimeConfig));
    }

    /**
     * 获取时间配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(emsStrategyTimeConfigService.selectEmsStrategyTimeConfigById(id));
    }

    /**
     * 新增时间配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:add')")
    @Log(title = "时间配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<EmsStrategyTimeConfig> emsStrategyTimeConfigList)
    {
        boolean result = emsStrategyTimeConfigService.insertEmsStrategyTimeConfig(emsStrategyTimeConfigList);
        if (result){
            return success();
        }else {
            return error("编辑失败请重试！");
        }

    }

    /**
     * 修改时间配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:edit')")
    @Log(title = "时间配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsStrategyTimeConfig emsStrategyTimeConfig)
    {
        return toAjax(emsStrategyTimeConfigService.updateEmsStrategyTimeConfig(emsStrategyTimeConfig));
    }

    /**
     * 删除时间配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    @Log(title = "时间配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emsStrategyTimeConfigService.deleteEmsStrategyTimeConfigByIds(ids));
    }
}
