puzhibing
2024-01-30 03f1f3372a10a08f96f3308bfa099e86a55046d0
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/management/MgtStaffController.java
@@ -3,10 +3,13 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.dto.MgtBaseGetDto;
import com.ruoyi.system.api.domain.poji.sys.SysUser;
import com.ruoyi.system.api.service.RemoteUserService;
import com.ruoyi.system.domain.dto.*;
import com.ruoyi.system.domain.vo.MgtDeptStaffListVo;
import com.ruoyi.system.domain.vo.MgtStaffPageVo;
@@ -17,14 +20,15 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import static com.ruoyi.common.core.web.domain.AjaxResult.success;
/**
 * @author jqs34
@@ -33,12 +37,13 @@
 * @description: TODO
 * @date 2023 2023/6/11 18:36
 */
@Api(value = "平台端员工相关接口", tags = "平台端员工相关接口", description = "平台端员工相关接口")
@Api(value = "管理后台员工相关接口", tags = "管理后台员工相关接口", description = "管理后台员工相关接口")
@RestController
@RequestMapping("/mgt/staff")
public class MgtStaffController {
    @Resource
    private RemoteUserService sysUserService;
    @Resource
    private StaffSuggestService staffSuggestService;
@@ -49,9 +54,42 @@
    @RequestMapping(value = "/listMgtDeptStaff", method = RequestMethod.POST)
    @ApiOperation(value = "获取部门员工列表")
    public R<List<MgtDeptStaffListVo>> listMgtDeptStaff() {
        List<MgtDeptStaffListVo> mgtDeptStaffListVoList= sysStaffService.listMgtDeptStaff();
        // 获取当前登陆人的可视权限
        SysUser sysUser = SecurityUtils.getSysUser();
        // 如果当前登陆人权限是查看部门数据
        Long deptId = null;
        // 如果当前登陆人是查看个人数据
        Long userId  = null;
        if (sysUser!=null){
            String dataScope = sysUser.getDataScope();
            if (!sysUser.getUserName().equals("admin")){
                if (org.springframework.util.StringUtils.hasLength(dataScope)){
                    switch (dataScope){
                        case "3":
                            // 本部门数据 查询当前登陆人属于哪个部门 查询这个部门下所有员工关联的所有店铺
                            deptId = sysUser.getDeptId();
                            break;
                        case "5":
                            // 仅个人数据 查询当前登陆人关联店铺下的用户
                            userId = sysUser.getUserId();
                            break;
                    }
                }
            }
        }
        List<MgtDeptStaffListVo> mgtDeptStaffListVoList= sysStaffService.listMgtDeptStaff(deptId,userId);
        return R.ok(mgtDeptStaffListVoList);
    }
    @RequestMapping(value = "/listDeptStaff", method = RequestMethod.POST)
    @ApiOperation(value = "获取所有部门员工列表")
    public R<List<MgtDeptStaffListVo>> listDeptStaff() {
        List<MgtDeptStaffListVo> mgtDeptStaffListVoList= sysStaffService.listMgtDeptStaff(null,null);
        return R.ok(mgtDeptStaffListVoList);
    }
    @RequestMapping(value = "/listMgtDeptStaffByPermission", method = RequestMethod.POST)
    @ApiOperation(value = "通过权限获取部门员工列表")
@@ -76,12 +114,17 @@
    @RequestMapping(value = "/exportPageMgtStaffSuggest", method = RequestMethod.POST)
    @ApiOperation(value = "导出员工建议列表")
    public void exportPageMgtStaffSuggest(@RequestBody MgtStaffSuggestPageDto mgtStaffSuggestPageDto, HttpServletResponse response) {
    public void exportPageMgtStaffSuggest(MgtStaffSuggestPageDto mgtStaffSuggestPageDto, HttpServletResponse response) {
        Long userId = SecurityUtils.getUserId();
        mgtStaffSuggestPageDto.setUserId(userId);
        Page<MgtStaffSuggestPageVo> page = new Page<>();
        page.setSize(2000);
        page.setCurrent(1);
        if(mgtStaffSuggestPageDto.getPageSize() > 5000){
            page.setSize(5000);
            page.setCurrent(1);
        }else{
            page.setSize(mgtStaffSuggestPageDto.getPageSize());
            page.setCurrent(mgtStaffSuggestPageDto.getPageNum());
        }
        List<MgtStaffSuggestPageVo> staffSuggestPageVoList = staffSuggestService.pageMgtStaffSuggest(page,mgtStaffSuggestPageDto);
        ExcelUtil<MgtStaffSuggestPageVo> util = new ExcelUtil<MgtStaffSuggestPageVo>(MgtStaffSuggestPageVo.class);
        util.exportExcel(response, staffSuggestPageVoList, "员工建议列表");
@@ -145,4 +188,14 @@
        sysStaffService.mgtDeleteStaff(mgtBaseGetDto);
        return R.ok();
    }
    @ApiOperation(value = "导入员工数据")
    @PostMapping("/importSysStaff")
    public AjaxResult importSysStaff(@RequestPart("file") MultipartFile file) throws Exception
    {
        ExcelUtil<MgtSysStaffImportDto> util = new ExcelUtil<MgtSysStaffImportDto>(MgtSysStaffImportDto.class);
        List<MgtSysStaffImportDto> sysStaffImportDtoList = util.importExcel(file.getInputStream());
        String message = sysStaffService.importSysStaff(sysStaffImportDtoList);
        return success(message);
    }
}