package com.ruoyi.web.work.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.work.domain.Packages;
import com.ruoyi.web.work.service.IPackagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 接包管理
 * @author lsw
 * @date 2024-04-19
 */
@RestController
@RequestMapping("/work/packages")
public class PackagesController extends BaseController {
    @Autowired
    private IPackagesService packagesService;

    @PreAuthorize("@ss.hasPermi('work:packages:list')")
    @GetMapping("/list")
    public TableDataInfo list(Packages packages){
        startPage();
        List<Packages> list = packagesService.selectList(packages);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('work:packages:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id){
        return AjaxResult.success(packagesService.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('work:packages:add')")
    @Log(title = "接包管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Packages packages){
        return toAjax(packagesService.save(packages));
    }

    @PreAuthorize("@ss.hasPermi('work:packages:edit')")
    @Log(title = "接包管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Packages packages){
        return toAjax(packagesService.updateById(packages));
    }

    @PreAuthorize("@ss.hasPermi('work:packages:remove')")
    @Log(title = "接包管理", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(packagesService.removeByIds(Arrays.asList(ids)));
    }
}
