package com.fs.company.controller.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.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.qw.domain.QwWelcome;
import com.fs.qw.service.IQwWelcomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 入群欢迎语管理Controller
 *
 * @author fs
 * @date 2024-06-22
 */
@RestController
@RequestMapping("/qw/welcome")
public class QwWelcomeController extends BaseController
{
    @Autowired
    private IQwWelcomeService qwWelcomeService;

    @Autowired
    private TokenService tokenService;
    /**
     * 查询入群欢迎语管理列表
     */
    @PreAuthorize("@ss.hasPermi('qw:welcome:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwWelcome qwWelcome)
    {
        startPage();
        List<QwWelcome> list = qwWelcomeService.selectQwWelcomeList(qwWelcome);
        return getDataTable(list);
    }

    /**
     * 获取入群欢迎语管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:welcome:query')")
    @GetMapping(value = "/{welcomeId}")
    public AjaxResult getInfo(@PathVariable("welcomeId") Long welcomeId)
    {
        return AjaxResult.success(qwWelcomeService.selectQwWelcomeByWelcomeId(welcomeId));
    }

    /**
     * 新增入群欢迎语管理
     */
    @PreAuthorize("@ss.hasPermi('qw:welcome:add')")
    @Log(title = "入群欢迎语管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody QwWelcome qwWelcome) throws Exception {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        qwWelcome.setCompanyId(loginUser.getCompany().getCompanyId());
        qwWelcome.setCreateName(loginUser.getUser().getNickName());
        return qwWelcomeService.insertQwWelcome(qwWelcome);
    }

    /**
     * 修改入群欢迎语管理
     */
    @PreAuthorize("@ss.hasPermi('qw:welcome:edit')")
    @Log(title = "入群欢迎语管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody QwWelcome qwWelcome) throws Exception {
        return qwWelcomeService.updateQwWelcome(qwWelcome);
    }

    /**
     * 删除入群欢迎语管理
     */
    @PreAuthorize("@ss.hasPermi('qw:welcome:remove')")
    @Log(title = "入群欢迎语管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{welcomeIds}")
    public R remove(@PathVariable Long welcomeIds,@RequestParam(value = "templateId") String templateId)
    {


        return qwWelcomeService.deleteQwWelcomeByWelcomeId(welcomeIds,templateId);
    }
}
