package com.xzzn.web.controller.ems;

import com.xzzn.common.annotation.Log;
import com.xzzn.common.core.controller.BaseController;
import com.xzzn.common.core.domain.AjaxResult;
import com.xzzn.common.core.page.TableDataInfo;
import com.xzzn.common.enums.BusinessType;
import com.xzzn.ems.domain.EmsPointCalcConfig;
import com.xzzn.ems.service.IEmsPointCalcConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ems/pointCalcConfig")
public class EmsPointCalcConfigController extends BaseController {

    @Autowired
    private IEmsPointCalcConfigService pointCalcConfigService;

    @GetMapping("/list")
    public TableDataInfo list(EmsPointCalcConfig pointCalcConfig) {
        startPage();
        List<EmsPointCalcConfig> list = pointCalcConfigService.selectPointCalcConfigList(pointCalcConfig);
        return getDataTable(list);
    }

    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(pointCalcConfigService.selectPointCalcConfigById(id));
    }

    @Log(title = "计算点配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsPointCalcConfig pointCalcConfig) {
        return toAjax(pointCalcConfigService.insertPointCalcConfig(pointCalcConfig, getUsername()));
    }

    @Log(title = "计算点配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsPointCalcConfig pointCalcConfig) {
        return toAjax(pointCalcConfigService.updatePointCalcConfig(pointCalcConfig, getUsername()));
    }

    @Log(title = "计算点配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pointCalcConfigService.deletePointCalcConfigByIds(ids));
    }
}
