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.QwFriendWelcome;
import com.fs.qw.param.QwFriendWelcomeParam;
import com.fs.qw.service.IQwFriendWelcomeService;
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/friendWelcome")
public class QwFriendWelcomeController extends BaseController
{
    @Autowired
    private IQwFriendWelcomeService qwFriendWelcomeService;

    @Autowired
    private TokenService tokenService;
    /**
     * 查询好友欢迎语列表
     */
    @PreAuthorize("@ss.hasPermi('qw:friendWelcome:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwFriendWelcomeParam qwFriendWelcomeParam)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        qwFriendWelcomeParam.setCompanyId(loginUser.getCompany().getCompanyId());
        List<QwFriendWelcome> list = qwFriendWelcomeService.selectQwFriendWelcomeListVO(qwFriendWelcomeParam);
        return getDataTable(list);
    }

    /**
     * 查询好友欢迎语列表
     */
    @PreAuthorize("@ss.hasPermi('qw:friendWelcome:myList')")
    @GetMapping("/myList")
    public TableDataInfo myList(QwFriendWelcomeParam qwFriendWelcomeParam)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        qwFriendWelcomeParam.setCompanyId(loginUser.getCompany().getCompanyId());
        qwFriendWelcomeParam.setCompanyUserId(loginUser.getUser().getUserId());
        List<QwFriendWelcome> list = qwFriendWelcomeService.selectQwFriendWelcomeListMyVO(qwFriendWelcomeParam);
        return getDataTable(list);
    }

    /**
     * 导出好友欢迎语列表
     */
    @PreAuthorize("@ss.hasPermi('qw:friendWelcome:export')")
    @Log(title = "好友欢迎语", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwFriendWelcomeParam qwFriendWelcomeParam)
    {
        List<QwFriendWelcome> list = qwFriendWelcomeService.selectQwFriendWelcomeListVO(qwFriendWelcomeParam);
        ExcelUtil<QwFriendWelcome> util = new ExcelUtil<QwFriendWelcome>(QwFriendWelcome.class);
        return util.exportExcel(list, "好友欢迎语数据");
    }

    /**
     * 获取好友欢迎语详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:friendWelcome:query')")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id)
    {
//        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
//        Long companyId = loginUser.getCompany().getCompanyId();
        return R.ok().put("row", qwFriendWelcomeService.selectQwFriendWelcomeById(id));
    }

    /**
     * 新增好友欢迎语
     */
    @PreAuthorize("@ss.hasPermi('qw:friendWelcome:add')")
    @Log(title = "好友欢迎语", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody QwFriendWelcomeParam qwFriendWelcomeParam)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long companyId = loginUser.getCompany().getCompanyId();
        qwFriendWelcomeParam.setCompanyId(companyId);
        qwFriendWelcomeParam.setCreateTime(new Date());
        qwFriendWelcomeParam.setUpdateTime(new Date());
        return qwFriendWelcomeService.insertQwFriendWelcomeVO(qwFriendWelcomeParam);
    }

    /**
     * 修改好友欢迎语
     */
    @PreAuthorize("@ss.hasPermi('qw:friendWelcome:edit')")
    @Log(title = "好友欢迎语", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody QwFriendWelcome qwFriendWelcome)
    {
        return qwFriendWelcomeService.updateQwFriendWelcome(qwFriendWelcome);
    }

    /**
     * 删除好友欢迎语
     */
    @PreAuthorize("@ss.hasPermi('qw:friendWelcome:remove')")
    @Log(title = "好友欢迎语", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwFriendWelcomeService.deleteQwFriendWelcomeByIds(ids));
    }
}
