package com.xinelu.manage.controller.servicepackagecontent;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.servicepackagecontent.ServicePackageContent;
import com.xinelu.manage.service.servicepackagecontent.IServicePackageContentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 服务包内容Controller
 *
 * @author xinelu
 * @date 2024-03-04
 */
@RestController
@RequestMapping("/manage/servicepackagecontent")
public class ServicePackageContentController extends BaseController {
    @Resource
    private IServicePackageContentService servicePackageContentService;

    /**
     * 查询服务包内容列表
     */
    @PreAuthorize("@ss.hasPermi('manage:servicepackagecontent:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServicePackageContent servicePackageContent) {
        startPage();
        List<ServicePackageContent> list = servicePackageContentService.selectServicePackageContentList(servicePackageContent);
        return getDataTable(list);
    }

    /**
     * 导出服务包内容列表
     */
    @PreAuthorize("@ss.hasPermi('manage:servicepackagecontent:export')")
    @Log(title = "服务包内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServicePackageContent servicePackageContent) {
        List<ServicePackageContent> list = servicePackageContentService.selectServicePackageContentList(servicePackageContent);
        ExcelUtil<ServicePackageContent> util = new ExcelUtil<ServicePackageContent>(ServicePackageContent.class);
        util.exportExcel(response, list, "服务包内容数据");
    }

    /**
     * 获取服务包内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:servicepackagecontent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(servicePackageContentService.selectServicePackageContentById(id));
    }

    /**
     * 新增服务包内容
     */
    @PreAuthorize("@ss.hasPermi('manage:servicepackagecontent:add')")
    @Log(title = "服务包内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServicePackageContent servicePackageContent) {
        return toAjax(servicePackageContentService.insertServicePackageContent(servicePackageContent));
    }

    /**
     * 修改服务包内容
     */
    @PreAuthorize("@ss.hasPermi('manage:servicepackagecontent:edit')")
    @Log(title = "服务包内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServicePackageContent servicePackageContent) {
        return toAjax(servicePackageContentService.updateServicePackageContent(servicePackageContent));
    }

    /**
     * 删除服务包内容
     */
    @PreAuthorize("@ss.hasPermi('manage:servicepackagecontent:remove')")
    @Log(title = "服务包内容", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(servicePackageContentService.deleteServicePackageContentByIds(ids));
    }
}
