package com.xinelu.manage.controller.servicepackage;

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.domain.R;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.dto.servicepackage.ServicePackageAddDTO;
import com.xinelu.manage.dto.servicepackage.ServicePackageDto;
import com.xinelu.manage.service.servicepackage.IServicePackageService;
import com.xinelu.manage.vo.servicepackage.ServicePackageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 服务包基础信息Controller
 *
 * @author xinelu
 * @date 2024-03-03
 */
@Api(tags = "服务包基础信息控制器")
@RestController
@RequestMapping("/manage/servicepackage")
public class ServicePackageController extends BaseController {
    @Resource
    private IServicePackageService servicePackageService;

    /**
     * 查询服务包基础信息列表
     */
    @ApiOperation("分页查询服务包基础信息列表")
    @PreAuthorize("@ss.hasPermi('manage:servicepackage:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServicePackageDto servicePackage) {
        return servicePackageService.selectServicePackageList(servicePackage);
    }

	/**
	 * 查询服务包基础信息列表
	 */
	@ApiOperation("查询服务包基础信息列表")
	@GetMapping("/getList")
	public R<List<ServicePackageVO>> getList(ServicePackageDto servicePackage) {
		return R.ok(servicePackageService.selectList(servicePackage));
	}

    /**
     * 导出服务包基础信息列表
     */
    @ApiOperation("导出服务包基础信息列表")
    @PreAuthorize("@ss.hasPermi('manage:servicepackage:export')")
    @Log(title = "服务包基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServicePackageDto servicePackage) {
        TableDataInfo tableDataInfo = servicePackageService.selectServicePackageList(servicePackage);
        ExcelUtil<ServicePackageVO> util = new ExcelUtil<ServicePackageVO>(ServicePackageVO.class);
        List<ServicePackageVO> voList = (List<ServicePackageVO>) tableDataInfo.getRows();
        util.exportExcel(response, voList, "服务包基础信息数据");
    }

    /**
     * 获取服务包基础信息详细信息
     */
    @ApiOperation("获取服务包基础信息详细信息")
    @PreAuthorize("@ss.hasPermi('manage:servicepackage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(servicePackageService.selectServicePackageById(id));
    }

	/**
	 * 获取服务包基础信息
	 */
	@ApiOperation("获取服务包基础信息")
	@GetMapping(value = "/getById/{id}")
	public R<ServicePackageVO> getById(@PathVariable("id") Long id) {
		return R.ok(servicePackageService.getById(id));
	}

    /**
     * 新增服务包基础信息
     */
    @ApiOperation("新增服务包基础信息")
    @PreAuthorize("@ss.hasPermi('manage:servicepackage:add')")
    @Log(title = "服务包基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ServicePackageAddDTO servicePackageAddDTO) {
        return toAjax(servicePackageService.insertServicePackage(servicePackageAddDTO));
    }

    /**
     * 修改服务包基础信息
     */
    @ApiOperation("修改服务包基础信息")
    @PreAuthorize("@ss.hasPermi('manage:servicepackage:edit')")
    @Log(title = "服务包基础信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ServicePackageAddDTO servicePackageAddDTO) {
        return toAjax(servicePackageService.updateServicePackage(servicePackageAddDTO));
    }

    /**
     * 删除服务包基础信息
     */
    @ApiOperation("删除服务包基础信息")
    @PreAuthorize("@ss.hasPermi('manage:servicepackage:remove')")
    @Log(title = "服务包基础信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(servicePackageService.deleteServicePackageByIds(ids));
    }

    /**
     * 修改服务包发布状态
     */
    @ApiOperation("修改服务包发布状态")
    @PutMapping("/editReleaseStatus")
    public AjaxResult editReleaseStatus(Long id, Integer whetherRelease) {
        return toAjax(servicePackageService.editReleaseStatus(id, whetherRelease));
    }
}
