package com.jjt.ws.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
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.jjt.common.annotation.Log;
import com.jjt.common.core.controller.BaseController;
import com.jjt.common.core.domain.AjaxResult;
import com.jjt.common.enums.BusinessType;
import com.jjt.ws.domain.TwinWorkshopEnergy;
import com.jjt.ws.service.ITwinWorkshopEnergyService;
import com.jjt.common.utils.poi.ExcelUtil;
import com.jjt.common.core.page.TableDataInfo;

/**
 * 车间能源管理Controller
 *
 * @author wukai
 * @date 2025-01-17
 */
@Api(tags="车间能源管理")
@RestController
@RequestMapping("/ws/energy")
public class TwinWorkshopEnergyController extends BaseController{
    @Resource
    private ITwinWorkshopEnergyService twinWorkshopEnergyService;

    /**
     * 查询车间能源管理列表
     */
    @ApiOperation("查询车间能源管理列表")
    @PreAuthorize("@ss.hasPermi('ws:energy:list')")
    @GetMapping("/list")
    public TableDataInfo list(TwinWorkshopEnergy twinWorkshopEnergy)
    {
        startPage();
        List<TwinWorkshopEnergy> list = twinWorkshopEnergyService.selectTwinWorkshopEnergyList(twinWorkshopEnergy);
        return getDataTable(list);
    }

    /**
     * 导出车间能源管理列表
     */
    @ApiOperation("导出车间能源管理列表")
    @PreAuthorize("@ss.hasPermi('ws:energy:export')")
    @Log(title = "车间能源管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TwinWorkshopEnergy twinWorkshopEnergy)
    {
        List<TwinWorkshopEnergy> list = twinWorkshopEnergyService.selectTwinWorkshopEnergyList(twinWorkshopEnergy);
        ExcelUtil<TwinWorkshopEnergy> util = new ExcelUtil<TwinWorkshopEnergy>(TwinWorkshopEnergy.class);
        util.exportExcel(response, list, "车间能源管理数据");
    }

    /**
     * 获取车间能源管理详细信息
     */
    @ApiOperation("获取车间能源管理详细信息")
    @PreAuthorize("@ss.hasPermi('ws:energy:query')")
    @GetMapping(value = "/{energyId}")
    public AjaxResult getInfo(@PathVariable("energyId") Long energyId)
    {
        return success(twinWorkshopEnergyService.selectTwinWorkshopEnergyByEnergyId(energyId));
    }

    /**
     * 新增车间能源管理
     */
    @ApiOperation("新增车间能源管理")
    @PreAuthorize("@ss.hasPermi('ws:energy:add')")
    @Log(title = "车间能源管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TwinWorkshopEnergy twinWorkshopEnergy)
    {
        return toAjax(twinWorkshopEnergyService.insertTwinWorkshopEnergy(twinWorkshopEnergy));
    }

    /**
     * 修改车间能源管理
     */
    @ApiOperation("修改车间能源管理")
    @PreAuthorize("@ss.hasPermi('ws:energy:edit')")
    @Log(title = "车间能源管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TwinWorkshopEnergy twinWorkshopEnergy)
    {
        return toAjax(twinWorkshopEnergyService.updateTwinWorkshopEnergy(twinWorkshopEnergy));
    }

    /**
     * 删除车间能源管理
     */
    @ApiOperation("删除车间能源管理")
    @PreAuthorize("@ss.hasPermi('ws:energy:remove')")
    @Log(title = "车间能源管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{energyIds}")
    public AjaxResult remove(@PathVariable Long[] energyIds)
    {
        return toAjax(twinWorkshopEnergyService.deleteTwinWorkshopEnergyByEnergyIds(energyIds));
    }
}
