package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.business.domain.BusinessTemplatePropValue;
import com.ruoyi.business.service.IBusinessTemplatePropValueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;
import java.util.Map;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模版属性值Controller
 * 
 * @author ruoyi
 * @date 2024-03-31
 */
@RestController
@RequestMapping("/business/templatePropValue")
public class BusinessTemplatePropValueController extends BaseController
{
    @Autowired
    private IBusinessTemplatePropValueService businessTemplatePropValueService;

    /**
     * 查询模版属性值列表
     */
    @PreAuthorize("@ss.hasPermi('business:templatePropValue:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessTemplatePropValue businessTemplatePropValue)
    {
        startPage();
        List<BusinessTemplatePropValue> list = businessTemplatePropValueService.list();
        return getDataTable(list);
    }

    /**
     * 统计问卷
     */
    @GetMapping("/countGroup")
    public AjaxResult countGroup(String surveyId)
    {
        Object o = businessTemplatePropValueService.countGroup(surveyId);
        return AjaxResult.success(o);
    }

    /**
     * 导出模版属性值列表
     */
    @PreAuthorize("@ss.hasPermi('business:templatePropValue:export')")
    @Log(title = "模版属性值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessTemplatePropValue businessTemplatePropValue)
    {
        List<BusinessTemplatePropValue> list = businessTemplatePropValueService.list();
        ExcelUtil<BusinessTemplatePropValue> util = new ExcelUtil<BusinessTemplatePropValue>(BusinessTemplatePropValue.class);
        util.exportExcel(response, list, "模版属性值数据");
    }

    /**
     * 获取模版属性值详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:templatePropValue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(businessTemplatePropValueService.getById(id));
    }

    /**
     * 新增模版属性值
     */
    @PreAuthorize("@ss.hasPermi('business:templatePropValue:add')")
    @Log(title = "模版属性值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessTemplatePropValue businessTemplatePropValue)
    {
        return toAjax(businessTemplatePropValueService.save(businessTemplatePropValue));
    }


    /**
     * 新增模版属性值
     */
    @Log(title = "模版属性值", businessType = BusinessType.INSERT)
    @PostMapping("/addList")
    public AjaxResult addList(@RequestBody Map<String,Object> data)
    {
        return toAjax(businessTemplatePropValueService.addList(data));
    }

    /**
     * 修改模版属性值
     */
    @PreAuthorize("@ss.hasPermi('business:templatePropValue:edit')")
    @Log(title = "模版属性值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessTemplatePropValue businessTemplatePropValue)
    {
        return toAjax(businessTemplatePropValueService.updateById(businessTemplatePropValue));
    }

    /**
     * 删除模版属性值
     */
    @PreAuthorize("@ss.hasPermi('business:templatePropValue:remove')")
    @Log(title = "模版属性值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(businessTemplatePropValueService.removeByIds(Arrays.asList(ids)));
    }
}
