Search in sources :

Example 1 with SysDepart

use of org.jeecg.modules.system.entity.SysDepart in project jeecg-boot by jeecgboot.

the class SysDepartController method getDepartName.

/**
 * 根据部门编码获取部门信息
 *
 * @param orgCode
 * @return
 */
@GetMapping("/getDepartName")
public Result<SysDepart> getDepartName(@RequestParam(name = "orgCode") String orgCode) {
    Result<SysDepart> result = new Result<>();
    LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<>();
    query.eq(SysDepart::getOrgCode, orgCode);
    SysDepart sysDepart = sysDepartService.getOne(query);
    result.setSuccess(true);
    result.setResult(sysDepart);
    return result;
}
Also used : SysDepart(org.jeecg.modules.system.entity.SysDepart) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 2 with SysDepart

use of org.jeecg.modules.system.entity.SysDepart in project jeecg-boot by jeecgboot.

the class SysDepartController method exportXls.

/**
 * 导出excel
 *
 * @param request
 */
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(SysDepart sysDepart, HttpServletRequest request) {
    // Step.1 组装查询条件
    QueryWrapper<SysDepart> queryWrapper = QueryGenerator.initQueryWrapper(sysDepart, request.getParameterMap());
    // Step.2 AutoPoi 导出Excel
    ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
    List<SysDepart> pageList = sysDepartService.list(queryWrapper);
    // 按字典排序
    Collections.sort(pageList, new Comparator<SysDepart>() {

        @Override
        public int compare(SysDepart arg0, SysDepart arg1) {
            return arg0.getOrgCode().compareTo(arg1.getOrgCode());
        }
    });
    // 导出文件名称
    mv.addObject(NormalExcelConstants.FILE_NAME, "部门列表");
    mv.addObject(NormalExcelConstants.CLASS, SysDepart.class);
    LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("部门列表数据", "导出人:" + user.getRealname(), "导出信息"));
    mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
    return mv;
}
Also used : ExportParams(org.jeecgframework.poi.excel.entity.ExportParams) JeecgEntityExcelView(org.jeecgframework.poi.excel.view.JeecgEntityExcelView) ModelAndView(org.springframework.web.servlet.ModelAndView) SysDepart(org.jeecg.modules.system.entity.SysDepart) LoginUser(org.jeecg.common.system.vo.LoginUser)

Example 3 with SysDepart

use of org.jeecg.modules.system.entity.SysDepart in project jeecg-boot by jeecgboot.

the class SysDepartController method edit.

/**
 * 编辑数据 编辑部门的部分数据,并保存到数据库
 *
 * @param sysDepart
 * @return
 */
// @RequiresRoles({"admin"})
@RequestMapping(value = "/edit", method = { RequestMethod.PUT, RequestMethod.POST })
@CacheEvict(value = { CacheConstant.SYS_DEPARTS_CACHE, CacheConstant.SYS_DEPART_IDS_CACHE }, allEntries = true)
public Result<SysDepart> edit(@RequestBody SysDepart sysDepart, HttpServletRequest request) {
    String username = JwtUtil.getUserNameByToken(request);
    sysDepart.setUpdateBy(username);
    Result<SysDepart> result = new Result<SysDepart>();
    SysDepart sysDepartEntity = sysDepartService.getById(sysDepart.getId());
    if (sysDepartEntity == null) {
        result.error500("未找到对应实体");
    } else {
        boolean ok = sysDepartService.updateDepartDataById(sysDepart, username);
        // TODO 返回false说明什么?
        if (ok) {
            // 清除部门树内存
            // FindsDepartsChildrenUtil.clearSysDepartTreeList();
            // FindsDepartsChildrenUtil.clearDepartIdModel();
            result.success("修改成功!");
        }
    }
    return result;
}
Also used : SysDepart(org.jeecg.modules.system.entity.SysDepart) Result(org.jeecg.common.api.vo.Result) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 4 with SysDepart

use of org.jeecg.modules.system.entity.SysDepart in project jeecg-boot by jeecgboot.

the class SysDepartController method delete.

/**
 *   通过id删除
 * @param id
 * @return
 */
// @RequiresRoles({"admin"})
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
@CacheEvict(value = { CacheConstant.SYS_DEPARTS_CACHE, CacheConstant.SYS_DEPART_IDS_CACHE }, allEntries = true)
public Result<SysDepart> delete(@RequestParam(name = "id", required = true) String id) {
    Result<SysDepart> result = new Result<SysDepart>();
    SysDepart sysDepart = sysDepartService.getById(id);
    if (sysDepart == null) {
        result.error500("未找到对应实体");
    } else {
        boolean ok = sysDepartService.delete(id);
        if (ok) {
            // 清除部门树内存
            // FindsDepartsChildrenUtil.clearSysDepartTreeList();
            // FindsDepartsChildrenUtil.clearDepartIdModel();
            result.success("删除成功!");
        }
    }
    return result;
}
Also used : SysDepart(org.jeecg.modules.system.entity.SysDepart) Result(org.jeecg.common.api.vo.Result) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 5 with SysDepart

use of org.jeecg.modules.system.entity.SysDepart in project jeecg-boot by jeecgboot.

the class LoginController method userInfo.

/**
 * 用户信息
 *
 * @param sysUser
 * @param result
 * @return
 */
private Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {
    String syspassword = sysUser.getPassword();
    String username = sysUser.getUsername();
    // 获取用户部门信息
    JSONObject obj = new JSONObject();
    List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
    obj.put("departs", departs);
    if (departs == null || departs.size() == 0) {
        obj.put("multi_depart", 0);
    } else if (departs.size() == 1) {
        sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
        obj.put("multi_depart", 1);
    } else {
        // 查询当前是否有登录部门
        // update-begin--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
        SysUser sysUserById = sysUserService.getById(sysUser.getId());
        if (oConvertUtils.isEmpty(sysUserById.getOrgCode())) {
            sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
        }
        // update-end--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
        obj.put("multi_depart", 2);
    }
    // update-begin--Author:sunjianlei Date:20210802 for:获取用户租户信息
    String tenantIds = sysUser.getRelTenantIds();
    if (oConvertUtils.isNotEmpty(tenantIds)) {
        List<Integer> tenantIdList = new ArrayList<>();
        for (String id : tenantIds.split(",")) {
            tenantIdList.add(Integer.valueOf(id));
        }
        // 该方法仅查询有效的租户,如果返回0个就说明所有的租户均无效。
        List<SysTenant> tenantList = sysTenantService.queryEffectiveTenant(tenantIdList);
        if (tenantList.size() == 0) {
            result.error500("与该用户关联的租户均已被冻结,无法登录!");
            return result;
        } else {
            obj.put("tenantList", tenantList);
        }
    }
    // update-end--Author:sunjianlei Date:20210802 for:获取用户租户信息
    // 生成token
    String token = JwtUtil.sign(username, syspassword);
    // 设置token缓存有效时间
    redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
    redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
    obj.put("token", token);
    obj.put("userInfo", sysUser);
    obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
    result.setResult(obj);
    result.success("登录成功");
    return result;
}
Also used : SysTenant(org.jeecg.modules.system.entity.SysTenant) JSONObject(com.alibaba.fastjson.JSONObject) SysUser(org.jeecg.modules.system.entity.SysUser) SysDepart(org.jeecg.modules.system.entity.SysDepart) EncryptedString(org.jeecg.common.util.encryption.EncryptedString)

Aggregations

SysDepart (org.jeecg.modules.system.entity.SysDepart)41 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)17 Result (org.jeecg.common.api.vo.Result)17 JSONObject (com.alibaba.fastjson.JSONObject)14 SysUser (org.jeecg.modules.system.entity.SysUser)14 ArrayList (java.util.ArrayList)12 DepartIdModel (org.jeecg.modules.system.model.DepartIdModel)9 CacheEvict (org.springframework.cache.annotation.CacheEvict)9 EncryptedString (org.jeecg.common.util.encryption.EncryptedString)8 SysDepartTreeModel (org.jeecg.modules.system.model.SysDepartTreeModel)6 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)3 IPage (com.baomidou.mybatisplus.core.metadata.IPage)3 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 LoginUser (org.jeecg.common.system.vo.LoginUser)3 SysUserDepart (org.jeecg.modules.system.entity.SysUserDepart)3 ISysDepartService (org.jeecg.modules.system.service.ISysDepartService)3 ExportParams (org.jeecgframework.poi.excel.entity.ExportParams)3 ImportParams (org.jeecgframework.poi.excel.entity.ImportParams)3