package com.xinelu.manage.controller.servicewaycontent;

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.servicewaycontent.ServiceWayContent;
import com.xinelu.manage.dto.servicewaycontent.ServiceWayContentAddDTO;
import com.xinelu.manage.dto.servicewaycontent.ServiceWayContentDTO;
import com.xinelu.manage.dto.servicewaycontent.ServiceWayContentEditDTO;
import com.xinelu.manage.service.servicewaycontent.IServiceWayContentService;
import com.xinelu.manage.vo.servicewaycontent.ServiceWayContentAndNumVO;
import com.xinelu.manage.vo.servicewaycontent.ServiceWayContentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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-02-29
 */
@Api(tags = "服务方式内容控制器")
@RestController
@RequestMapping("/manage/servicewaycontent")
public class ServiceWayContentController extends BaseController {
    @Resource
    private IServiceWayContentService serviceWayContentService;

    /**
     * 查询服务方式列表
     */
    @ApiOperation("查询服务方式列表")
    @GetMapping("/serviceWayList")
    public AjaxResult listNum(String serviceWayName, Long id) {
        List<ServiceWayContentAndNumVO> list = serviceWayContentService.selectListNum(serviceWayName, id);
        return AjaxResult.success(list);
    }

    /**
     * 根据服务方式id获取服务方式
     */
    @ApiOperation("根据服务方式id获取服务方式")
    @GetMapping(value = "/serviceWay/{id}")
    public AjaxResult getServiceWayInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(serviceWayContentService.selectServiceWayById(id));
    }

    /**
     * 新增服务方式
     */
    @ApiOperation("新增服务方式")
    @PostMapping("/addServiceWay")
    public AjaxResult addServiceWay(@RequestBody ServiceWayContent serviceWayContent) {
        return toAjax(serviceWayContentService.insertServiceWay(serviceWayContent));
    }

    /**
     * 修改服务方式
     */
    @ApiOperation("修改服务方式")
    @PutMapping("/editServiceWay")
    public AjaxResult editServiceWay(@RequestBody ServiceWayContent serviceWayContent) {
        return toAjax(serviceWayContentService.editServiceWay(serviceWayContent));
    }

    /**
     * 根据id删除服务方式
     */
    @ApiOperation("根据id删除服务方式")
    @DeleteMapping("/removeServiceWay/{id}")
    public AjaxResult removeServiceWay(@PathVariable Long id) {
        return toAjax(serviceWayContentService.deleteServiceWayById(id));
    }

    /**
     * 查询服务方式内容列表
     */
    @ApiOperation("查询服务方式内容列表")
    @PreAuthorize("@ss.hasPermi('manage:servicewaycontent:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceWayContentDTO serviceWayContentDTO) {
        startPage();
        List<ServiceWayContentVO> list = serviceWayContentService.selectServiceWayContentList(serviceWayContentDTO);
        return getDataTable(list);
    }


    /**
     * 导出服务方式内容列表
     */
    @ApiOperation("导出服务方式内容列表")
    @PreAuthorize("@ss.hasPermi('manage:servicewaycontent:export')")
    @Log(title = "服务方式内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceWayContentDTO serviceWayContentDTO) {
        List<ServiceWayContentVO> list = serviceWayContentService.selectServiceWayContentList(serviceWayContentDTO);
        ExcelUtil<ServiceWayContentVO> util = new ExcelUtil<ServiceWayContentVO>(ServiceWayContentVO.class);
        util.exportExcel(response, list, "服务方式内容数据");
    }

    /**
     * 根据服务频次id查询服务内容详细信息
     */
    @ApiOperation("根据服务频次id查询服务内容详细信息")
    @PreAuthorize("@ss.hasPermi('manage:servicewaycontent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(serviceWayContentService.selectServiceWayContentById(id));
    }

    /**
     * 新增服务方式内容
     */
    @PreAuthorize("@ss.hasPermi('manage:servicewaycontent:add')")
    @Log(title = "服务方式内容", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ServiceWayContentAddDTO serviceWayContentAddDTO) {
        return toAjax(serviceWayContentService.insertServiceWayContent(serviceWayContentAddDTO));
    }

    /**
     * 修改服务方式内容
     */
    @PreAuthorize("@ss.hasPermi('manage:servicewaycontent:edit')")
    @Log(title = "服务方式内容", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ServiceWayContentEditDTO serviceWayContentEditDTO) {
        return toAjax(serviceWayContentService.updateServiceWayContent(serviceWayContentEditDTO));
    }

    /**
     * 根据服务频次id删除服务内容
     */
    @ApiOperation("根据服务频次id删除服务内容")
    @PreAuthorize("@ss.hasPermi('manage:servicewaycontent:remove')")
    @Log(title = "服务方式内容", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(serviceWayContentService.deleteByFrequencyId(id));
    }
}
