package com.ruoyi.system.controller;

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

import com.ruoyi.system.domain.ServiceCate;
import com.ruoyi.system.service.IServiceCateService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ServiceGoods;
import com.ruoyi.system.service.IServiceGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务内容Controller
 * 
 * @author ruoyi
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/system/ServiceGoods")
public class ServiceGoodsController extends BaseController
{
    @Autowired
    private IServiceGoodsService serviceGoodsService;
@Autowired
private IServiceCateService  serviceCateService;
    /**
     * 查询服务内容列表
     */
    @PreAuthorize("@ss.hasPermi('system:ServiceGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceGoods serviceGoods)
    {
        startPage();
        List<ServiceGoods> list = serviceGoodsService.selectServiceGoodsList(serviceGoods);
        for(ServiceGoods serviceGoodsdata:list){
            ServiceCate serviceCate=serviceCateService.selectServiceCateById(serviceGoodsdata.getCateId());
            if(serviceCate!=null){
                serviceGoodsdata.setCateName(serviceCate.getTitle());
            }
            serviceGoodsdata.setIcon("https://img.huafurenjia.cn/"+serviceGoodsdata.getIcon());

        }
        return getDataTable(list);
    }

    /**
     * 导出服务内容列表
     */
    @PreAuthorize("@ss.hasPermi('system:ServiceGoods:export')")
    @Log(title = "服务内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceGoods serviceGoods)
    {
        List<ServiceGoods> list = serviceGoodsService.selectServiceGoodsList(serviceGoods);
        ExcelUtil<ServiceGoods> util = new ExcelUtil<ServiceGoods>(ServiceGoods.class);
        util.exportExcel(response, list, "服务内容数据");
    }

    /**
     * 获取服务内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ServiceGoods:query')")
    @GetMapping(value = "/selectServiceCateList")
    public AjaxResult selectServiceCateList()
    {
        return success(serviceCateService.selectServiceCateList(new ServiceCate()));
    }


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

    /**
     * 新增服务内容
     */
    @PreAuthorize("@ss.hasPermi('system:ServiceGoods:add')")
    @Log(title = "服务内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceGoods serviceGoods)
    {
        return toAjax(serviceGoodsService.insertServiceGoods(serviceGoods));
    }

    /**
     * 修改服务内容
     */
    @PreAuthorize("@ss.hasPermi('system:ServiceGoods:edit')")
    @Log(title = "服务内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceGoods serviceGoods)
    {
        return toAjax(serviceGoodsService.updateServiceGoods(serviceGoods));
    }
    /**
     * 定时任务状态修改
     */
    @PreAuthorize("@ss.hasPermi('system:ServiceGoods:changeStatus')")
    @Log(title = "修改状态", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody ServiceGoods serviceGoods)
    {
        ServiceGoods newServiceGoods = serviceGoodsService.selectServiceGoodsById(serviceGoods.getId());
        newServiceGoods.setStatus(serviceGoods.getStatus());
        return toAjax(serviceGoodsService.updateServiceGoods(newServiceGoods));
    }

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