Java Code Examples for org.springframework.cache.annotation.CacheEvict

The following examples show how to use org.springframework.cache.annotation.CacheEvict. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: jeecg-cloud   Source File: SysDepartController.java    License: Apache License 2.0 6 votes vote down vote up
/**
    *   通过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;
  }
 
Example 2
Source Project: jeecg-cloud   Source File: SysDictItemController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @功能:删除字典数据
 * @param id
 * @return
 */
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
@CacheEvict(value=CacheConstant.SYS_DICT_CACHE, allEntries=true)
public Result<SysDictItem> delete(@RequestParam(name="id",required=true) String id) {
	Result<SysDictItem> result = new Result<SysDictItem>();
	SysDictItem joinSystem = sysDictItemService.getById(id);
	if(joinSystem==null) {
		result.error500("未找到对应实体");
	}else {
		boolean ok = sysDictItemService.removeById(id);
		if(ok) {
			result.success("删除成功!");
		}
	}
	return result;
}
 
Example 3
Source Project: syhthems-platform   Source File: UserServiceImpl.java    License: MIT License 6 votes vote down vote up
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@CacheEvict(cacheNames = "UserDetails",
        key = "'CustomUserDetailsServiceImpl:loadUserByUsername:(' + #user.getUsername() + ')'",
        cacheManager = "JDKCacheManager",
        condition = "#user != null && #user.getUsername() != null ")
public int updateLogin(User user) {
    Assert.notNull(user, "用户不能为空");
    User u = new User();
    u.setUserId(user.getUserId());
    if (BaseConstants.YES.equals(user.getFirstLogin())) {
        u.setFirstLogin(BaseConstants.NO);
    }
    BeanUtils.copyObjectVersionValue(user, u);
    u.setLastLoginTime(new Date());
    return super.updateByPrimaryKeySelectiveWithVersion(u);
}
 
Example 4
Source Project: jeecg-boot-with-activiti   Source File: SysDictItemController.java    License: MIT License 6 votes vote down vote up
/**
 * @功能:编辑
 * @param sysDictItem
 * @return
 */
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
@CacheEvict(value=CacheConstant.SYS_DICT_CACHE, allEntries=true)
public Result<SysDictItem> edit(@RequestBody SysDictItem sysDictItem) {
	Result<SysDictItem> result = new Result<SysDictItem>();
	SysDictItem sysdict = sysDictItemService.getById(sysDictItem.getId());
	if(sysdict==null) {
		result.error500("未找到对应实体");
	}else {
		sysDictItem.setUpdateTime(new Date());
		boolean ok = sysDictItemService.updateById(sysDictItem);
		//TODO 返回false说明什么?
		if(ok) {
			result.success("编辑成功!");
		}
	}
	return result;
}
 
Example 5
Source Project: sk-admin   Source File: UserServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void updateAvatar(MultipartFile multipartFile) {
    User user = userRepository.findByUsername(SecurityUtils.getCurrentUsername());
    UserAvatar userAvatar = user.getUserAvatar();
    String oldPath = "";
    if (userAvatar != null) {
        oldPath = userAvatar.getPath();
    }
    File file = FileUtils.upload(multipartFile, properties.getPath().getAvatar());
    assert file != null;
    userAvatar = userAvatarRepository.save(new UserAvatar(userAvatar, file.getName(), file.getPath(), FileUtils.getSize(multipartFile.getSize())));
    user.setUserAvatar(userAvatar);
    userRepository.save(user);
    if (StringUtils.isNotBlank(oldPath)) {
        FileUtil.del(oldPath);
    }
}
 
Example 6
Source Project: spring-microservice-exam   Source File: UserService.java    License: MIT License 6 votes vote down vote up
/**
 * 批量删除用户
 *
 * @param ids ids
 * @return int
 * @author tangyi
 * @date 2019/07/04 11:44:45
 */
@Transactional
@Override
@CacheEvict(value = "user", allEntries = true)
public int deleteAll(Long[] ids) {
    String currentUser = SysUtil.getUser(), applicationCode = SysUtil.getSysCode(), tenantCode = SysUtil.getTenantCode();
    for (Long id : ids) {
        // 删除用户角色关系
        userRoleMapper.deleteByUserId(id);
        // 删除用户授权信息
        UserAuths userAuths = new UserAuths();
        userAuths.setNewRecord(false);
        userAuths.setUserId(id);
        userAuths.setCommonValue(currentUser, applicationCode, tenantCode);
        userAuthsService.deleteByUserId(userAuths);
    }
    return super.deleteAll(ids);
}
 
Example 7
Source Project: teaching   Source File: SysDepartController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 编辑数据 编辑部门的部分数据,并保存到数据库
 * 
 * @param sysDepart
 * @return
 */
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
@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;
}
 
Example 8
Source Project: open-cloud   Source File: BaseAppServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 修改应用
 *
 * @param app 应用
 * @return 应用信息
 */
@Caching(evict = {
        @CacheEvict(value = {"apps"}, key = "#app.appId"),
        @CacheEvict(value = {"apps"}, key = "'client:'+#app.appId")
})
@Override
public BaseApp updateInfo(BaseApp app) {
    app.setUpdateTime(new Date());
    baseAppMapper.updateById(app);
    // 修改客户端附加信息
    BaseApp appInfo = getAppInfo(app.getAppId());
    Map info = BeanConvertUtils.objectToMap(appInfo);
    BaseClientDetails client = (BaseClientDetails) jdbcClientDetailsService.loadClientByClientId(appInfo.getApiKey());
    client.setAdditionalInformation(info);
    jdbcClientDetailsService.updateClientDetails(client);
    return app;
}
 
Example 9
Source Project: teaching   Source File: SysDictItemController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @功能:删除字典数据
 * @param id
 * @return
 */
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
@CacheEvict(value=CacheConstant.SYS_DICT_CACHE, allEntries=true)
public Result<SysDictItem> delete(@RequestParam(name="id",required=true) String id) {
	Result<SysDictItem> result = new Result<SysDictItem>();
	SysDictItem joinSystem = sysDictItemService.getById(id);
	if(joinSystem==null) {
		result.error500("未找到对应实体");
	}else {
		boolean ok = sysDictItemService.removeById(id);
		if(ok) {
			result.success("删除成功!");
		}
	}
	return result;
}
 
Example 10
Source Project: spring-microservice-exam   Source File: RoleMenuService.java    License: MIT License 6 votes vote down vote up
/**
 * @param role  role
 * @param menus 菜单ID集合
 * @return int
 * @author tangyi
 * @date 2018/10/28 14:29
 */
@Transactional
@CacheEvict(value = "menu", allEntries = true)
public int saveRoleMenus(Long role, List<Long> menus) {
	int update = -1;
	if (CollectionUtils.isNotEmpty(menus)) {
		// 删除旧的管理数据
		roleMenuMapper.deleteByRoleId(role);
		List<RoleMenu> roleMenus = new ArrayList<>();
		for (Long menuId : menus) {
			RoleMenu roleMenu = new RoleMenu();
			roleMenu.setId(IdGen.snowflakeId());
			roleMenu.setRoleId(role);
			roleMenu.setMenuId(menuId);
			roleMenus.add(roleMenu);
		}
		update = roleMenuMapper.insertBatch(roleMenus);
	}
	return update;
}
 
Example 11
/**
 * DO NOT pass in the mutated cache value. This method relies on the existing
 * cached value to check the differences
 */
@CacheEvict(cacheNames = "playlistCache", key = "#playlist.id")
public void updatePlaylist(Playlist playlist, boolean filesChangedBroadcastContext) {
    Playlist oldPlaylist = getPlaylist(playlist.getId());
    playlistDao.updatePlaylist(playlist);
    runAsync(() -> {
        BroadcastedPlaylist bp = new BroadcastedPlaylist(playlist, filesChangedBroadcastContext);
        if (playlist.getShared()) {
            brokerTemplate.convertAndSend("/topic/playlists/updated", bp);
        } else {
            if (oldPlaylist.getShared()) {
                brokerTemplate.convertAndSend("/topic/playlists/deleted", playlist.getId());
            }
            Stream.concat(Stream.of(playlist.getUsername()), getPlaylistUsers(playlist.getId()).stream())
                    .forEach(u -> brokerTemplate.convertAndSendToUser(u, "/queue/playlists/updated", bp));
        }
    });
}
 
Example 12
Source Project: open-cloud   Source File: BaseAuthorityServiceImpl.java    License: MIT License 6 votes vote down vote up
/**
 * 应用授权-添加单个权限
 *
 * @param appId
 * @param expireTime
 * @param authorityId
 */
@CacheEvict(value = {"apps"}, key = "'client:'+#appId")
@Override
public void addAuthorityApp(String appId, Date expireTime, String authorityId) {
    BaseAuthorityApp authority = new BaseAuthorityApp();
    authority.setAppId(appId);
    authority.setAuthorityId(Long.parseLong(authorityId));
    authority.setExpireTime(expireTime);
    authority.setCreateTime(new Date());
    authority.setUpdateTime(authority.getCreateTime());
    QueryWrapper<BaseAuthorityApp> appQueryWrapper = new QueryWrapper();
    appQueryWrapper.lambda()
            .eq(BaseAuthorityApp::getAppId, appId)
            .eq(BaseAuthorityApp::getAuthorityId, authorityId);
    int count = baseAuthorityAppMapper.selectCount(appQueryWrapper);
    if (count > 0) {
        return;
    }
    authority.setCreateTime(new Date());
    baseAuthorityAppMapper.insert(authority);
}
 
Example 13
Source Project: jeecg-cloud   Source File: SysPermissionServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE,allEntries=true)
public void addPermission(SysPermission sysPermission) throws JeecgBootException {
	//----------------------------------------------------------------------
	//判断是否是一级菜单,是的话清空父菜单
	if(CommonConstant.MENU_TYPE_0.equals(sysPermission.getMenuType())) {
		sysPermission.setParentId(null);
	}
	//----------------------------------------------------------------------
	String pid = sysPermission.getParentId();
	if(oConvertUtils.isNotEmpty(pid)) {
		//设置父节点不为叶子节点
		this.sysPermissionMapper.setMenuLeaf(pid, 0);
	}
	sysPermission.setCreateTime(new Date());
	sysPermission.setDelFlag(0);
	sysPermission.setLeaf(true);
	this.save(sysPermission);
}
 
Example 14
Source Project: jeecg-boot-with-activiti   Source File: SysDepartController.java    License: MIT License 6 votes vote down vote up
/**
 * 添加新数据 添加用户新建的部门对象数据,并保存到数据库
 * 
 * @param sysDepart
 * @return
 */
@RequestMapping(value = "/add", method = RequestMethod.POST)
@CacheEvict(value= {CacheConstant.SYS_DEPARTS_CACHE,CacheConstant.SYS_DEPART_IDS_CACHE}, allEntries=true)
public Result<SysDepart> add(@RequestBody SysDepart sysDepart, HttpServletRequest request) {
	Result<SysDepart> result = new Result<SysDepart>();
	String username = JwtUtil.getUserNameByToken(request);
	try {
		sysDepart.setCreateBy(username);
		sysDepartService.saveDepartData(sysDepart, username);
		//清除部门树内存
		// FindsDepartsChildrenUtil.clearSysDepartTreeList();
		// FindsDepartsChildrenUtil.clearDepartIdModel();
		result.success("添加成功!");
	} catch (Exception e) {
		log.error(e.getMessage(),e);
		result.error500("操作失败");
	}
	return result;
}
 
Example 15
@Override
@Transactional(rollbackFor = Exception.class)
@CacheEvict(value = "menu_details", allEntries = true)
public SmakerResult removeMenuById(Integer id) {
	// 查询父节点为当前节点的节点
	List<SysMenu> menuList = this.list(Wrappers.<SysMenu>query()
			.lambda().eq(SysMenu::getParentId, id));
	if (CollUtil.isNotEmpty(menuList)) {
		return SmakerResult.builder()
				.code(CommonConstants.FAIL)
				.msg("菜单含有下级不能删除").build();
	}

	sysRoleMenuMapper
			.delete(Wrappers.<SysRoleMenu>query()
					.lambda().eq(SysRoleMenu::getMenuId, id));

	//删除当前菜单及其子菜单
	return new SmakerResult(this.removeById(id));
}
 
Example 16
Source Project: teaching   Source File: SysDictController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @功能:删除
 * @param id
 * @return
 */
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
@CacheEvict(value=CacheConstant.SYS_DICT_CACHE, allEntries=true)
public Result<SysDict> delete(@RequestParam(name="id",required=true) String id) {
	Result<SysDict> result = new Result<SysDict>();
	boolean ok = sysDictService.removeById(id);
	if(ok) {
		result.success("删除成功!");
	}else{
		result.error500("删除失败!");
	}
	return result;
}
 
Example 17
Source Project: spring-microservice-exam   Source File: UserService.java    License: MIT License 5 votes vote down vote up
/**
 * 导入用户
 *
 * @param userInfoDtos userInfoDtos
 * @return boolean
 * @author tangyi
 * @date 2019/07/04 12:46:01
 */
@Transactional
@CacheEvict(value = "user", allEntries = true)
public boolean importUsers(List<UserInfoDto> userInfoDtos) {
    String currentUser = SysUtil.getUser(), applicationCode = SysUtil.getSysCode(), tenantCode = SysUtil.getTenantCode();
    Date currentDate = DateUtils.asDate(LocalDateTime.now());
    for (UserInfoDto userInfoDto : userInfoDtos) {
        User user = new User();
        BeanUtils.copyProperties(userInfoDto, user);
        user.setModifier(currentUser);
        user.setModifyDate(currentDate);
        if (this.update(user) < 1) {
            user.setCommonValue(currentUser, applicationCode, tenantCode);
            user.setStatus(CommonConstant.STATUS_NORMAL);
            this.insert(user);
        }
        // 先删除用户授权信息
        UserAuths userAuths = new UserAuths();
        userAuths.setIdentifier(userInfoDto.getIdentifier());
        // 默认密码
        if (StringUtils.isBlank(userInfoDto.getCredential())) {
            userInfoDto.setCredential(encodeCredential(CommonConstant.DEFAULT_PASSWORD));
        }
        userAuths.setCredential(userInfoDto.getCredential());
        userAuths.setModifier(currentUser);
        userAuths.setModifyDate(currentDate);
        userAuths.setTenantCode(tenantCode);
        userAuthsService.deleteByIdentifier(userAuths);
        // 重新insert
        userAuths.setCommonValue(currentUser, applicationCode, tenantCode);
        userAuths.setUserId(user.getId());
        userAuths.setIdentityType(userInfoDto.getIdentityType());
        userAuthsService.insert(userAuths);
    }
    return true;
}
 
Example 18
Source Project: open-cloud   Source File: BaseAuthorityServiceImpl.java    License: MIT License 5 votes vote down vote up
/**
 * 应用授权
 *
 * @param appId        应用ID
 * @param expireTime   过期时间,null表示长期,不限制
 * @param authorityIds 权限集合
 * @return
 */
@CacheEvict(value = {"apps"}, key = "'client:'+#appId")
@Override
public void addAuthorityApp(String appId, Date expireTime, String... authorityIds) {
    if (appId == null) {
        return;
    }
    BaseApp baseApp = baseAppService.getAppInfo(appId);
    if (baseApp == null) {
        return;
    }
    // 清空应用已有授权
    QueryWrapper<BaseAuthorityApp> appQueryWrapper = new QueryWrapper();
    appQueryWrapper.lambda().eq(BaseAuthorityApp::getAppId, appId);
    baseAuthorityAppMapper.delete(appQueryWrapper);
    BaseAuthorityApp authority = null;
    if (authorityIds != null && authorityIds.length > 0) {
        for (String id : authorityIds) {
            authority = new BaseAuthorityApp();
            authority.setAuthorityId(Long.parseLong(id));
            authority.setAppId(appId);
            authority.setExpireTime(expireTime);
            authority.setCreateTime(new Date());
            authority.setUpdateTime(authority.getCreateTime());
            baseAuthorityAppMapper.insert(authority);

        }
    }
    // 获取应用最新的权限列表
    List<OpenAuthority> authorities = findAuthorityByApp(appId);
    // 动态更新tokenStore客户端
    OpenHelper.updateOpenClientAuthorities(redisTokenStore,baseApp.getApiKey(),authorities);
}
 
Example 19
Source Project: sk-admin   Source File: QuartzJobServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@CacheEvict(allEntries = true)
public void updateIsPause(QuartzJob quartzJob) {
    if (quartzJob.getId().equals(1L)) {
        throw new SkException("该任务不可操作");
    }
    if (quartzJob.getIsPause()) {
        quartzManage.resumeJob(quartzJob);
        quartzJob.setIsPause(false);
    } else {
        quartzManage.pauseJob(quartzJob);
        quartzJob.setIsPause(true);
    }
    quartzJobDao.save(quartzJob);
}
 
Example 20
Source Project: sk-admin   Source File: DeptServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void delete(Set<DeptDTO> deptDtos) {
    for (DeptDTO deptDto : deptDtos) {
        deptRepository.deleteById(deptDto.getId());
    }
}
 
Example 21
Source Project: sk-admin   Source File: UserServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public UserDTO create(User resources) {
    if (userRepository.findByUsername(resources.getUsername()) != null) {
        throw new EntityExistException(User.class, "username", resources.getUsername());
    }
    if (userRepository.findByEmail(resources.getEmail()) != null) {
        throw new EntityExistException(User.class, "email", resources.getEmail());
    }
    return userMapper.toDto(userRepository.save(resources));
}
 
Example 22
Source Project: sk-admin   Source File: UserServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void update(User resources) {
    User user = userRepository.findById(resources.getId()).orElseGet(User::new);
    ValidationUtil.isNull(user.getId(), "User", "id", resources.getId());
    User user1 = userRepository.findByUsername(resources.getUsername());
    User user2 = userRepository.findByEmail(resources.getEmail());

    if (user1 != null && !user.getId().equals(user1.getId())) {
        throw new EntityExistException(User.class, "username", resources.getUsername());
    }

    if (user2 != null && !user.getId().equals(user2.getId())) {
        throw new EntityExistException(User.class, "email", resources.getEmail());
    }

    // 如果用户的角色改变了,需要手动清理下缓存
    if (!resources.getRoles().equals(user.getRoles())) {
        String key = "role::loadPermissionByUser:" + user.getUsername();
        redisUtils.del(key);
        key = "role::findByUsers_Id:" + user.getId();
        redisUtils.del(key);
    }

    user.setUsername(resources.getUsername());
    user.setEmail(resources.getEmail());
    user.setEnabled(resources.getEnabled());
    user.setRoles(resources.getRoles());
    user.setDept(resources.getDept());
    user.setJob(resources.getJob());
    user.setPhone(resources.getPhone());
    user.setNickName(resources.getNickName());
    user.setSex(resources.getSex());
    userRepository.save(user);
}
 
Example 23
Source Project: sk-admin   Source File: UserServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void updateCenter(User resources) {
    User user = userRepository.findById(resources.getId()).orElseGet(User::new);
    user.setNickName(resources.getNickName());
    user.setPhone(resources.getPhone());
    user.setSex(resources.getSex());
    userRepository.save(user);
}
 
Example 24
Source Project: yshopmall   Source File: StoreProductController.java    License: Apache License 2.0 5 votes vote down vote up
@Log("删除商品")
@ApiOperation(value = "删除商品")
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true)
@DeleteMapping(value = "/yxStoreProduct/{id}")
@PreAuthorize("@el.check('admin','YXSTOREPRODUCT_ALL','YXSTOREPRODUCT_DELETE')")
public ResponseEntity delete(@PathVariable Integer id){

    yxStoreProductService.delete(id);
    return new ResponseEntity(HttpStatus.OK);
}
 
Example 25
Source Project: jeecg-cloud   Source File: SysDictController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @功能:批量删除
 * @param ids
 * @return
 */
//@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
@CacheEvict(value= CacheConstant.SYS_DICT_CACHE, allEntries=true)
public Result<SysDict> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
	Result<SysDict> result = new Result<SysDict>();
	if(oConvertUtils.isEmpty(ids)) {
		result.error500("参数不识别!");
	}else {
		sysDictService.removeByIds(Arrays.asList(ids.split(",")));
		result.success("删除成功!");
	}
	return result;
}
 
Example 26
Source Project: spring-microservice-exam   Source File: UserService.java    License: MIT License 5 votes vote down vote up
/**
 * 注册,注意要清除缓存
 *
 * @param userDto userDto
 * @return boolean
 * @author tangyi
 * @date 2019/07/03 13:30:03
 */
@Transactional
@CacheEvict(value = "user", key = "#userDto.identifier")
public boolean register(UserDto userDto) {
    boolean success = false;
    if (userDto.getIdentityType() == null)
        userDto.setIdentityType(IdentityType.PASSWORD.getValue());
    // 解密
    String password = this.decryptCredential(userDto.getCredential(), userDto.getIdentityType());
    User user = new User();
    BeanUtils.copyProperties(userDto, user);
    // 初始化用户名,系统编号,租户编号
    user.setCommonValue(userDto.getIdentifier(), SysUtil.getSysCode(), SysUtil.getTenantCode());
    user.setStatus(CommonConstant.DEL_FLAG_NORMAL);
    // 初始化头像
    if (StringUtils.isNotBlank(userDto.getAvatarUrl())) {
        Attachment attachment = new Attachment();
        attachment.setCommonValue(userDto.getIdentifier(), SysUtil.getSysCode(), SysUtil.getTenantCode());
        attachment.setBusiType(AttachmentConstant.BUSI_TYPE_USER_AVATAR);
        attachment.setPreviewUrl(userDto.getAvatarUrl());
        if (attachmentService.insert(attachment) > 0)
            user.setAvatarId(attachment.getId());
    }
    // 保存用户基本信息
    if (this.insert(user) > 0) {
        // 保存账号信息
        UserAuths userAuths = new UserAuths();
        userAuths.setCommonValue(userDto.getIdentifier(), user.getApplicationCode(), user.getTenantCode());
        userAuths.setUserId(user.getId());
        userAuths.setIdentifier(userDto.getIdentifier());
        if (userDto.getIdentityType() != null)
            userAuths.setIdentityType(userDto.getIdentityType());
        // 设置密码
        userAuths.setCredential(encoder.encode(password));
        userAuthsService.insert(userAuths);
        // 分配默认角色
        success = this.defaultRole(user, userDto.getTenantCode(), userDto.getIdentifier());
    }
    return success;
}
 
Example 27
Source Project: spring-microservice-exam   Source File: SubjectChoicesService.java    License: MIT License 5 votes vote down vote up
/**
    * 删除
    *
    * @param subjectDto subjectDto
    * @return int
    * @author tangyi
    * @date 2019/06/16 17:50
    */
   @Override
   @Transactional
@CacheEvict(value = "subjectChoices", key = "#subjectDto.id")
public int deleteSubject(SubjectDto subjectDto) {
       SubjectChoices subjectChoices = new SubjectChoices();
       BeanUtils.copyProperties(subjectDto, subjectChoices);
       return this.delete(subjectChoices);
   }
 
Example 28
Source Project: stone   Source File: OptionsServiceImpl.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 批量保存设置
 *
 * @param options options
 */
@Override
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
public void saveOptions(Map<String, String> options) {
    if (null != options && !options.isEmpty()) {
        options.forEach((k, v) -> saveOption(k, v));
    }
}
 
Example 29
Source Project: SpringBlade   Source File: DictServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@CacheEvict(cacheNames = {DICT_LIST, DICT_VALUE}, allEntries = true)
public boolean submit(Dict dict) {
	LambdaQueryWrapper<Dict> lqw = Wrappers.<Dict>query().lambda().eq(Dict::getCode, dict.getCode()).eq(Dict::getDictKey, dict.getDictKey());
	Integer cnt = baseMapper.selectCount((Func.isEmpty(dict.getId())) ? lqw : lqw.notIn(Dict::getId, dict.getId()));
	if (cnt > 0) {
		throw new ApiException("当前字典键值已存在!");
	}
	return saveOrUpdate(dict);
}
 
Example 30
Source Project: yshopmall   Source File: StoreProductController.java    License: Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "恢复数据")
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true)
@DeleteMapping(value = "/yxStoreProduct/recovery/{id}")
@PreAuthorize("@el.check('admin','YXSTOREPRODUCT_ALL','YXSTOREPRODUCT_DELETE')")
public ResponseEntity recovery(@PathVariable Integer id){
    yxStoreProductService.recovery(id);
    return new ResponseEntity(HttpStatus.OK);
}