package com.hw.ems.base.controller;

import com.hw.common.core.utils.poi.ExcelUtil;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.web.page.TableDataInfo;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.ems.base.domain.BaseLineLoss;
import com.hw.ems.base.service.IBaseLineLossService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 线损对象信息Controller
 *
 * @author sf
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/loss")
public class BaseLineLossController extends BaseController {
    @Autowired
    private IBaseLineLossService baseLineLossService;

    /**
     * 查询线损对象信息列表
     */
    @RequiresPermissions("energy:loss:list")
    @GetMapping("/list")
    public TableDataInfo list(BaseLineLoss baseLineLoss) {
        startPage();
//        List<BaseLineLoss> list = baseLineLossService.selectBaseLineLossList(baseLineLoss);
        List<BaseLineLoss> list = baseLineLossService.selectBaseLineLossListLike(baseLineLoss);
        return getDataTable(list);
    }


    /**
     * 导出线损对象信息列表
     */
    @RequiresPermissions("energy:loss:export")
    @Log(title = "线损对象信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseLineLoss baseLineLoss) {
        List<BaseLineLoss> list = baseLineLossService.selectBaseLineLossList(baseLineLoss);
        ExcelUtil<BaseLineLoss> util = new ExcelUtil<BaseLineLoss>(BaseLineLoss.class);
        util.exportExcel(response, list, "线损对象信息数据");
    }

    /**
     * 获取线损对象信息详细信息
     */
    @RequiresPermissions("energy:loss:query")
    @GetMapping(value = "/{objid}")
    public AjaxResult getInfo(@PathVariable("objid") Long objid) {
        return success(baseLineLossService.selectBaseLineLossByObjid(objid));
    }

    /**
     * 新增线损对象信息
     */
    @RequiresPermissions("energy:loss:add")
    @Log(title = "线损对象信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseLineLoss baseLineLoss) {
        return toAjax(baseLineLossService.insertBaseLineLoss(baseLineLoss));
    }

    /**
     * 修改线损对象信息
     */
    @RequiresPermissions("energy:loss:edit")
    @Log(title = "线损对象信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseLineLoss baseLineLoss) {
        return toAjax(baseLineLossService.updateBaseLineLoss(baseLineLoss));
    }

    /**
     * 删除线损对象信息
     */
    @RequiresPermissions("energy:loss:remove")
    @Log(title = "线损对象信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objids}")
    public AjaxResult remove(@PathVariable Long[] objids) {
        return toAjax(baseLineLossService.deleteBaseLineLossByObjids(objids));
    }
}
