package com.fs.qw;


import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.qw.domain.QwAutoTags;
import com.fs.qw.param.QwAutoTagsParam;
import com.fs.qw.service.IQwAutoTagsService;
import com.fs.qw.vo.QwAutoTagsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 自动打标签主Controller
 *
 * @author fs
 * @date 2024-07-20
 */
@RestController
@RequestMapping("/qw/autoTags")
public class QwAutoTagsController extends BaseController
{
    @Autowired
    private IQwAutoTagsService qwAutoTagsService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询自动打标签主列表
     */
    @PreAuthorize("@ss.hasPermi('qw:autoTags:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwAutoTagsParam qwAutoTags)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        qwAutoTags.setCompanyId( loginUser.getCompany().getCompanyId());
        List<QwAutoTagsVO> list = qwAutoTagsService.selectQwAutoTagsListVO(qwAutoTags);
        return getDataTable(list);
    }

    /**
     * 导出自动打标签主列表
     */
    @PreAuthorize("@ss.hasPermi('qw:autoTags:export')")
    @Log(title = "自动打标签主", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwAutoTagsParam qwAutoTags)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        qwAutoTags.setCompanyId( loginUser.getCompany().getCompanyId());
        List<QwAutoTagsVO> list = qwAutoTagsService.selectQwAutoTagsListVO(qwAutoTags);
        ExcelUtil<QwAutoTagsVO> util = new ExcelUtil<QwAutoTagsVO>(QwAutoTagsVO.class);
        return util.exportExcel(list, "自动打标签主数据");
    }

    /**
     * 获取自动打标签主详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:autoTags:query')")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id)
    {
        return qwAutoTagsService.selectQwAutoTagsByIdVO(id);
    }

    /**
     * 新增自动打标签主
     */
    @PreAuthorize("@ss.hasPermi('qw:autoTags:add')")
    @Log(title = "自动打标签主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwAutoTags qwAutoTags)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        qwAutoTags.setCreateName(loginUser.getUser().getNickName());
        qwAutoTags.setCompanyId( loginUser.getCompany().getCompanyId());
        qwAutoTags.setCreateTime(new Date());
        return toAjax(qwAutoTagsService.insertQwAutoTags(qwAutoTags));
    }

    /**
     * 修改自动打标签主
     */
    @PreAuthorize("@ss.hasPermi('qw:autoTags:edit')")
    @Log(title = "自动打标签主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwAutoTags qwAutoTags)
    {
        return toAjax(qwAutoTagsService.updateQwAutoTags(qwAutoTags));
    }

    /**
     * 删除自动打标签主
     */
    @PreAuthorize("@ss.hasPermi('qw:autoTags:remove')")
    @Log(title = "自动打标签主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwAutoTagsService.deleteQwAutoTagsByIds(ids));
    }
}
