package com.yunyan.web.controller.business;

import java.util.Arrays;
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.yunyan.common.annotation.Log;
import com.yunyan.common.core.controller.BaseController;
import com.yunyan.common.core.domain.AjaxResult;
import com.yunyan.common.enums.BusinessType;
import com.yunyan.business.domain.Term;
import com.yunyan.business.service.ITermService;
import com.yunyan.common.utils.poi.ExcelUtil;
import com.yunyan.common.core.page.TableDataInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.yunyan.common.core.domain.AjaxResultVo;
import com.yunyan.common.utils.SecurityUtils;
import java.util.Date;

/**
 * 名词管理Controller
 *
 * @author yunyan
 * @date 2023-07-27
 */
@Api(tags = "4.0.2名词管理")
@RestController
@RequestMapping("/business/term")
public class TermController extends BaseController
{
    @Autowired
    private ITermService termService;

    /**
     * 查询名词管理列表
     */
    @ApiOperation(value="查询名词管理列表", notes="查询名词管理列表")
    @PreAuthorize("@ss.hasPermi('business:term:list')")
    @GetMapping("/list")
    public TableDataInfo<Term> list(Term term)
    {
        startPage();
        List<Term> list = termService.selectTermList(term);
        return getDataTable(list);
    }

    @ApiOperation(value="名词管理选取列表(选取用无权限，报告数据中使用)", notes="名词管理选取列表(选取用无权限，报告数据中使用)")
    @GetMapping("/list/select")
    public TableDataInfo<Term> listSelect(Term term)
    {
        startPage();
        List<Term> list = termService.selectTermList(term);
        return getDataTable(list);
    }

    /**
     * 导出名词管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:term:export')")
    @Log(title = "名词管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Term term)
    {
        List<Term> list = termService.selectTermList(term);
        ExcelUtil<Term> util = new ExcelUtil<Term>(Term.class);
        util.exportExcel(response, list, "名词管理数据");
    }

    /**
     * 获取名词管理详细信息
     */
    @ApiOperation(value="获取名词管理详细信息", notes="获取名词管理详细信息")
    @PreAuthorize("@ss.hasPermi('business:term:query')")
    @GetMapping(value = "/{id}")
    public AjaxResultVo getInfo(@PathVariable("id") Long id)
    {
        return AjaxResultVo.success(termService.getById(id));
    }

    /**
     * 新增名词管理
     */
    @ApiOperation(value="新增名词管理", notes="新增名词管理")
    @PreAuthorize("@ss.hasPermi('business:term:add')")
    @Log(title = "名词管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Term dto)
    {
        return toAjax(termService.save(dto));
    }

    /**
     * 修改名词管理
     */
    @ApiOperation(value="修改名词管理", notes="修改名词管理")
    @PreAuthorize("@ss.hasPermi('business:term:edit')")
    @Log(title = "名词管理", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody Term dto)
    {
        return toAjax(termService.updateById(dto));
    }

    /**
     * 删除名词管理
     */
    @ApiOperation(value="删除名词管理", notes="删除名词管理")
    @PreAuthorize("@ss.hasPermi('business:term:remove')")
    @Log(title = "名词管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(termService.removeByIds(Arrays.asList(ids)));
    }

}
