package com.fs.qw.controller;


import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.qw.mapper.QwUserMapper;
import com.fs.qw.param.SopUserLogsVO;
import com.fs.sop.domain.QwSop;
import com.fs.sop.mapper.QwSopMapper;
import com.fs.sop.params.SopUserLogsParam;
import com.fs.sop.service.ISopUserLogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * sopUserLogsController
 *
 * @author fs
 * @date 2024-12-27
 */
@RestController
@RequestMapping("/qwSop/sopUserLogs")
public class SopUserLogsController extends BaseController
{
    @Autowired
    private ISopUserLogsService sopUserLogsService;

    @Autowired
    private QwSopMapper sopMapper;

    @Autowired
    private QwUserMapper qwUserMapper;


    /**
     * 查询sopUserLogs列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SopUserLogsParam sopUserLogs)
    {

        QwSop qwSop = sopMapper.selectQwSopById(sopUserLogs.getSopId());
        Integer filterMode = qwSop.getFilterMode();

        List<SopUserLogsVO> list=null;
        if(filterMode == null || filterMode == 1){
            startPage();
            list = sopUserLogsService.selectSopUserLogsList(sopUserLogs);
        }else {
            startPage();
            list = sopUserLogsService.selectSopUserLogsGroupListByParam(sopUserLogs);
        }


        list.forEach(item->{
            item.setQwUserName(qwUserMapper.selectQwUserByQwUserIdAndCorpId(item.getQwUserId(), item.getCorpId()));
        });

        return getDataTable(list);
    }


    /**
     * 获取sopUserLogs详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:sop:list')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(sopUserLogsService.selectSopUserLogsById(id));
    }

}
