Java Code Examples for cn.hutool.core.util.ObjectUtil#isNotNull()

The following examples show how to use cn.hutool.core.util.ObjectUtil#isNotNull() . 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 File: BaseDao.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 获取列
 *
 * @param fieldList 字段列表
 * @return 列信息列表
 */
private List<String> getColumns(List<Field> fieldList) {
	// 构造列
	List<String> columnList = CollUtil.newArrayList();
	for (Field field : fieldList) {
		Column columnAnnotation = field.getAnnotation(Column.class);
		String columnName;
		if (ObjectUtil.isNotNull(columnAnnotation)) {
			columnName = columnAnnotation.name();
		} else {
			columnName = field.getName();
		}
		columnList.add(StrUtil.format("`{}`", columnName));
	}
	return columnList;
}
 
Example 2
Source File: LogoutFilter.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response){
    try {
        Subject subject = getSubject(request, response);
        String redirectUrl = getRedirectUrl(request, response, subject);
        SysUser user = ShiroUtils.getSysUser();
        if (ObjectUtil.isNotNull(user)) {
            String loginName = user.getLoginName();
            // 记录用户退出日志
            AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success")));
            // 清理缓存
            cache.remove(loginName);
        }
        // 退出登录
        subject.logout();
        issueRedirect(request, response, redirectUrl);
    } catch (Exception e) {
        log.error("Encountered session exception during logout.  This can generally safely be ignored." , e);
    }
    return false;
}
 
Example 3
Source File: SysUserController.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
@ApiOperation("新增用户")
@ApiImplicitParam(name = "user", value = "新增用户信息", dataType = "SysUser")
@RequiresPermissions("system:user:add")
@Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@Transactional(rollbackFor = Exception.class)
@ResponseBody
public AjaxResult addSave(SysUser user) {
    if (ObjectUtil.isNotNull(user.getUserId()) && SysUser.isAdmin(user.getUserId())) {
        return error("不允许修改超级管理员用户");
    }
    if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(user.getLoginName()))){
        return error("保存用户'" + user.getLoginName() + "'失败,账号已存在");
    }
    user.setSalt(ShiroUtils.randomSalt());
    user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
    user.setCreateBy(ShiroUtils.getLoginName());
    return toAjax(userService.insertUser(user));
}
 
Example 4
Source File: BaseDao.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 获取列
 *
 * @param fieldList 字段列表
 * @return 列信息列表
 */
private List<String> getColumns(List<Field> fieldList) {
	// 构造列
	List<String> columnList = CollUtil.newArrayList();
	for (Field field : fieldList) {
		Column columnAnnotation = field.getAnnotation(Column.class);
		String columnName;
		if (ObjectUtil.isNotNull(columnAnnotation)) {
			columnName = columnAnnotation.name();
		} else {
			columnName = field.getName();
		}
		columnList.add(StrUtil.format("`{}`", columnName));
	}
	return columnList;
}
 
Example 5
Source File: StoreSeckillController.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
@Log("发布")
@ApiOperation(value = "发布")
@PutMapping(value = "/yxStoreSeckill")
@PreAuthorize("@el.check('admin','YXSTORESECKILL_ALL','YXSTORESECKILL_EDIT')")
public ResponseEntity update(@Validated @RequestBody YxStoreSeckill resources){
    if(ObjectUtil.isNotNull(resources.getStartTimeDate())){
        resources.setStartTime(OrderUtil.
                dateToTimestamp(resources.getStartTimeDate()));
    }
    if(ObjectUtil.isNotNull(resources.getEndTimeDate())){
        resources.setStopTime(OrderUtil.
                dateToTimestamp(resources.getEndTimeDate()));
    }
    if(ObjectUtil.isNull(resources.getId())){
        resources.setAddTime(String.valueOf(OrderUtil.getSecondTimestampTwo()));
        return new ResponseEntity(yxStoreSeckillService.save(resources),HttpStatus.CREATED);
    }else{
        yxStoreSeckillService.saveOrUpdate(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }
}
 
Example 6
Source File: MenuServiceImpl.java    From eladmin with Apache License 2.0 6 votes vote down vote up
@Override
public List<MenuDto> queryAll(MenuQueryCriteria criteria, Boolean isQuery) throws Exception {
    Sort sort = new Sort(Sort.Direction.ASC, "menuSort");
    if(isQuery){
        criteria.setPidIsNull(true);
        List<Field> fields = QueryHelp.getAllFields(criteria.getClass(), new ArrayList<>());
        for (Field field : fields) {
            //设置对象的访问权限,保证对private的属性的访问
            field.setAccessible(true);
            Object val = field.get(criteria);
            if("pidIsNull".equals(field.getName())){
                continue;
            }
            if (ObjectUtil.isNotNull(val)) {
                criteria.setPidIsNull(null);
                break;
            }
        }
    }
    return menuMapper.toDto(menuRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),sort));
}
 
Example 7
Source File: GoodsServiceImpl.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 收藏判断
 * @param goodsId
 * @param userId
 * @return
 */
@Override
public boolean isCollect(int goodsId, int userId) {
    QueryWrapper<StoreGoodsCollect> wrapper = new QueryWrapper<>();
    wrapper.eq("goods_id",goodsId).eq("user_id",userId);
    StoreGoodsCollect goodsCollect = storeGoodsCollectMapper.selectOne(wrapper);
    if(ObjectUtil.isNotNull(goodsCollect)) return true;
    return false;
}
 
Example 8
Source File: SysUserController.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
@ApiOperation("修改用户")
@ApiImplicitParam(name = "user", value = "修改用户信息", dataType = "SysUser")
@RequiresPermissions("system:user:edit")
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@Transactional(rollbackFor = Exception.class)
@ResponseBody
public AjaxResult editSave(SysUser user) {
    if (ObjectUtil.isNotNull(user.getUserId()) && SysUser.isAdmin(user.getUserId())) {
        return error("不允许修改超级管理员用户");
    }
    user.setUpdateBy(ShiroUtils.getLoginName());
    return toAjax(userService.updateUser(user));
}
 
Example 9
Source File: SysUserServiceImpl.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 校验email是否唯一
 *
 * @param user 用户信息
 * @return 校验结果
 */
@Override
public String checkEmailUnique(SysUser user) {
    SysUser info = userMapper.checkEmailUnique(user.getEmail());
    if (ObjectUtil.isNotNull(info) && !info.getUserId().equals(user.getUserId())) {
        return UserConstants.USER_EMAIL_NOT_UNIQUE;
    }
    return UserConstants.USER_EMAIL_UNIQUE;
}
 
Example 10
Source File: PageController.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 跳转到 登录页
 *
 * @param redirect 是否是跳转回来的
 */
@GetMapping("/login")
public ModelAndView login(Boolean redirect) {
    ModelAndView mv = new ModelAndView();

    if (ObjectUtil.isNotNull(redirect) && ObjectUtil.equal(true, redirect)) {
        mv.addObject("message", "请先登录!");
    }
    mv.setViewName("login");
    return mv;
}
 
Example 11
Source File: ExcelUtil.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 添加单元格
 */
private void addCell(Excel attr, Row row, T vo, Field field, int column, CellStyle cs){
    Cell cell;
    try{
        // 设置行高
        row.setHeight((short) (attr.height() * 20));
        // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列.
        if (attr.isExport()){
            // 创建cell
            cell = row.createCell(column);
            cell.setCellStyle(cs);

            // 用于读取对象中的属性
            Object value = getTargetValue(vo, field, attr);
            String dateFormat = attr.dateFormat();
            String readConverterExp = attr.readConverterExp();
            if (StrUtil.isNotEmpty(dateFormat) && ObjectUtil.isNotNull(value)){
                cell.setCellValue(DateUtil.format(((Date) value), dateFormat));
            }else if (StrUtil.isNotEmpty(readConverterExp) && ObjectUtil.isNotNull(value)){
                cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp));
            }else{
                cell.setCellType(CellType.STRING);
                // 如果数据存在就填入,不存在填入空格.
                cell.setCellValue(ObjectUtil.isNull(value) ? attr.defaultValue() : value + attr.suffix());
            }
        }
    }catch (Exception e){
        log.error("导出Excel失败%s", e);
    }
}
 
Example 12
Source File: SysUserServiceImpl.java    From pre with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SysUser findSecurityUserByUser(SysUser sysUser) {
    LambdaQueryWrapper<SysUser> select = Wrappers.<SysUser>lambdaQuery()
            .select(SysUser::getUserId, SysUser::getUsername, SysUser::getPassword);
    if (StrUtil.isNotEmpty(sysUser.getUsername())) {
        select.eq(SysUser::getUsername, sysUser.getUsername());
    } else if (StrUtil.isNotEmpty(sysUser.getPhone())) {
        select.eq(SysUser::getPhone, sysUser.getPhone());
    } else if (ObjectUtil.isNotNull(sysUser.getUserId()) && sysUser.getUserId() != 0) {
        select.eq(SysUser::getUserId, sysUser.getUserId());
    }
    return baseMapper.selectOne(select);
}
 
Example 13
Source File: SysShiroService.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
private Session createSession(SysUserOnline userOnline){
    OnlineSession onlineSession = new OnlineSession();
    if (ObjectUtil.isNotNull(userOnline)){
        onlineSession.setId(userOnline.getSessionId());
        onlineSession.setHost(userOnline.getIpaddr());
        onlineSession.setBrowser(userOnline.getBrowser());
        onlineSession.setOs(userOnline.getOs());
        onlineSession.setDeptName(userOnline.getDeptName());
        onlineSession.setLoginName(userOnline.getLoginName());
        onlineSession.setStartTimestamp(userOnline.getStartTimestamp());
        onlineSession.setLastAccessTime(userOnline.getLastAccessTime());
        onlineSession.setTimeout(userOnline.getExpireTime());
    }
    return onlineSession;
}
 
Example 14
Source File: SysMenuServiceImpl.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 根据角色ID查询菜单
 *
 * @param role 角色对象
 * @param userId 用户ID
 * @return 菜单列表
 */
@Override
public List<Ztree> roleMenuTreeData(SysRole role, Long userId) {
    Long roleId = role.getRoleId();
    List<Ztree> ztrees;
    List<SysMenu> menuList = selectMenuAll(userId);
    if (ObjectUtil.isNotNull(roleId)) {
        List<String> roleMenuList = menuMapper.selectMenuTree(roleId);
        ztrees = initZtree(menuList, roleMenuList, true);
    } else {
        ztrees = initZtree(menuList, null, true);
    }
    return ztrees;
}
 
Example 15
Source File: SysDeptController.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 修改
 */
@GetMapping("/edit/{deptId}")
public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap) {
    SysDept dept = deptService.selectDeptById(deptId);
    if (ObjectUtil.isNotNull(dept) && 100L == deptId) {
        dept.setParentName("无");
    }
    mmap.put("dept", dept);
    return prefix + "/edit";
}
 
Example 16
Source File: BaseForm.java    From datax-web with MIT License 5 votes vote down vote up
/**
 * 解析出mybatis plus分页查询参数
 */
public Page getPlusPagingQueryEntity() {
    Page page = new Page();
    //如果无current,默认返回1000条数据
    page.setCurrent(this.getPageNo());
    page.setSize(this.getPageSize());
    if (ObjectUtil.isNotNull(this.get("ifCount"))) {
        page.setSearchCount(BooleanUtil.toBoolean(this.getString("ifCount")));
    } else {
        //默认给true
        page.setSearchCount(true);
    }
    return page;
}
 
Example 17
Source File: ResponseResultHandler.java    From spring-boot-api-project-seed with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
    ResponseResult responseResultAnn = (ResponseResult) RequestContextHolderUtil.getRequest().getAttribute(ResponseResultInterceptor.RESPONSE_RESULT);
    return ObjectUtil.isNotNull(responseResultAnn);
}
 
Example 18
Source File: SystemGroupDataController.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
@Log("修改数据配置")
@ApiOperation(value = "修改数据配置")
@PutMapping(value = "/yxSystemGroupData")
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true)
@PreAuthorize("@el.check('admin','YXSYSTEMGROUPDATA_ALL','YXSYSTEMGROUPDATA_EDIT')")
public ResponseEntity update(@RequestBody String jsonStr){

    JSONObject jsonObject = JSON.parseObject(jsonStr);
    if(ObjectUtil.isNotNull(jsonObject.get("name"))){
        if(StrUtil.isEmpty(jsonObject.get("name").toString())){
            throw new BadRequestException("名称必须填写");
        }
    }

    if(ObjectUtil.isNotNull(jsonObject.get("title"))){
        if(StrUtil.isEmpty(jsonObject.get("title").toString())){
            throw new BadRequestException("标题必须填写");
        }
    }

    if(ObjectUtil.isNotNull(jsonObject.get("pic"))){
        if(StrUtil.isEmpty(jsonObject.get("pic").toString())){
            throw new BadRequestException("图片必须上传");
        }
    }

    YxSystemGroupData yxSystemGroupData = new YxSystemGroupData();

    yxSystemGroupData.setGroupName(jsonObject.get("groupName").toString());
    jsonObject.remove("groupName");
    yxSystemGroupData.setValue(jsonObject.toJSONString());
    if(jsonObject.getInteger("status") == null){
        yxSystemGroupData.setStatus(1);
    }else{
        yxSystemGroupData.setStatus(jsonObject.getInteger("status"));
    }

    if(jsonObject.getInteger("sort") == null){
        yxSystemGroupData.setSort(0);
    }else{
        yxSystemGroupData.setSort(jsonObject.getInteger("sort"));
    }


    yxSystemGroupData.setId(Integer.valueOf(jsonObject.get("id").toString()));
    yxSystemGroupDataService.saveOrUpdate(yxSystemGroupData);
    return new ResponseEntity(HttpStatus.NO_CONTENT);
}
 
Example 19
Source File: PayController.java    From supplierShop with MIT License 4 votes vote down vote up
/**
 * 调用统一下单接口,并组装生成支付所需参数对象.
 *
 * @param request 统一下单请求参数
 * @param <T>     请使用{@link com.github.binarywang.wxpay.bean.order}包下的类
 * @return 返回 {@link com.github.binarywang.wxpay.bean.order}包下的类对象
 */
@PostMapping(value = "/shop/pay-do-pay")
@ApiOperation(value = "开始支付",notes = "开始支付")
public R doPay(@Validated @RequestBody String jsonStr){
    JSONObject jsonObject = JSON.parseObject(jsonStr);
    String orderNo = jsonObject.get("order_no").toString();
    //1-余额支付 2-微信支付
    int payType = 1;

    if(StrUtil.isEmpty(orderNo)){
        return R.error(4000,"订单号缺失");
    }
    if(ObjectUtil.isNotNull(jsonObject.get("pay_type"))){
        payType = Integer.valueOf(jsonObject.get("pay_type").toString());
    }

    int userId = userOperator.getUser().getId();
    StoreOrder storeOrder = orderService.orderInfo(orderNo,userId);
    if(ObjectUtil.isNull(storeOrder)){
        return R.error(4000,"订单不存在");
    }


    if(payType == 1){
        orderService.payYue(storeOrder);
        return R.success("余额支付成功");
    }else{
        //判断库存
        QueryWrapper<StoreOrderGoods> wrapperGoods = new QueryWrapper<>();
        wrapperGoods.eq("order_id",storeOrder.getOrderId());
        List<StoreOrderGoods> orderGoodsList = storeOrderGoodsMapper
                .selectList(wrapperGoods);
        for (StoreOrderGoods storeGood : orderGoodsList) {
            int storeCount = orderService.checkStore(storeGood.getGoodsId(),storeGood.getSpecKey());
            if(storeCount < storeGood.getGoodsNum()){
                return R.error(4000,"库存不足");
            }
        }

        WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
        StoreMember member = memberService.getById(userId);
        orderRequest.setBody("商品购买");
        orderRequest.setOutTradeNo(orderNo);
        BigDecimal bigDecimal = new BigDecimal(100);
        orderRequest.setTotalFee(bigDecimal.multiply(storeOrder.getOrderAmount()).intValue());//元转成分
        orderRequest.setOpenid(member.getOpenid());
        orderRequest.setSpbillCreateIp("127.0.0.1");
        orderRequest.setNotifyUrl("https://app2.dayouqiantu.cn/shop/notify");
        orderRequest.setTradeType("JSAPI");
        try {
            WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
            return R.success(orderResult);
        } catch (WxPayException e) {
            return R.error(4000,e.getMessage());
        }

    }



}
 
Example 20
Source File: AliYunSmsUtils.java    From pre with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) {
    SmsResponse smsResponse = AliYunSmsUtils.sendSms("17521296869", "prex", "登录");
    if (ObjectUtil.isNotNull(smsResponse)) {
        System.out.println(smsResponse);
    }
}