Java Code Examples for com.baomidou.mybatisplus.core.conditions.query.QueryWrapper#setEntity()

The following examples show how to use com.baomidou.mybatisplus.core.conditions.query.QueryWrapper#setEntity() . 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: UpmsManager.java    From lion with Apache License 2.0 6 votes vote down vote up
@ApiOperation("根据用户名获取用户对象信息")
@ApiParam(name = "username", value = "用户名", required = true)
@Cacheable(cacheNames = CACHE_KEY + "_USER")
public SysUser getUserByUsername(String username) {

    // redis 自定义代码方式缓存使用
    /*
    String redisKey = "upms_user_" + username;
    ValueOperations<String, SysUser> operations = redisTemplate.opsForValue();
    Boolean hasKey = redisTemplate.hasKey(redisKey);
    if (hasKey) {
        SysUser user = operations.get(redisKey);
        operations.set(redisKey, user, 1000 * 5, TimeUnit.MILLISECONDS);    // 设置缓存及有效时间
        redisTemplate.delete(redisKey); // 删除缓存
    }
    */

    SysUser sysUser = new SysUser();
    sysUser.setUsername(username);
    sysUser.setValid(true);

    QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
    queryWrapper.setEntity(sysUser);

    return sysUserMapper.selectOne(queryWrapper);
}
 
Example 2
Source File: TempProductController.java    From lion with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "扣减产品库存", notes = "当库存不足时,扣减失败,回滚")
@RequestMapping(value = "/deduct", method = {RequestMethod.GET, RequestMethod.POST})
@Transactional
public Result<String> deduct(String productCode, int count) {

    QueryWrapper<TempProduct> wrapper = new QueryWrapper<>();
    wrapper.setEntity(new TempProduct().setCode(productCode));
    TempProduct tempProduct = tempProductService.getOne(wrapper);
    tempProduct.setCount(tempProduct.getCount() - count);
    if (tempProduct.getCount() < 0) {
        throw new LionException(productCode + " 商品库存不足,扣减库存操作失败...");
    }
    tempProductService.updateById(tempProduct);

    return Result.success();
}
 
Example 3
Source File: AccountService.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 减账号金额
 */
//@Transactional(rollbackFor = Exception.class)
public void reduce(String userId, int money) {
    if ("U002".equals(userId)) {
        throw new RuntimeException("this is a mock Exception");
    }

    QueryWrapper<Account> wrapper = new QueryWrapper<>();
    wrapper.setEntity(new Account().setUserId(userId));
    Account account = accountMapper.selectOne(wrapper);
    account.setMoney(account.getMoney() - money);
    accountMapper.updateById(account);
}
 
Example 4
Source File: StorageService.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 减库存
 * 
 * @param commodityCode 商品编号
 * @param count 数量
 */
//@Transactional(rollbackFor = Exception.class)
public void deduct(String commodityCode, int count) {
    QueryWrapper<Storage> wrapper = new QueryWrapper<>();
    wrapper.setEntity(new Storage().setCommodityCode(commodityCode));
    Storage storage = storageMapper.selectOne(wrapper);
    storage.setCount(storage.getCount() - count);

    storageMapper.updateById(storage);
}
 
Example 5
Source File: StorageService.java    From seata-samples with Apache License 2.0 5 votes vote down vote up
/**
 * 减库存
 * 
 * @param commodityCode
 * @param count
 */
@Transactional(rollbackFor = Exception.class)
public void deduct(String commodityCode, int count) {
    if (commodityCode.equals("product-2")) {
        throw new RuntimeException("异常:模拟业务异常:Storage branch exception");
    }

    QueryWrapper<Storage> wrapper = new QueryWrapper<>();
    wrapper.setEntity(new Storage().setCommodityCode(commodityCode));
    Storage storage = storageDAO.selectOne(wrapper);
    storage.setCount(storage.getCount() - count);

    storageDAO.updateById(storage);
}
 
Example 6
Source File: Condition.java    From blade-tool with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * 获取mybatis plus中的QueryWrapper
 *
 * @param query   查询条件
 * @param exclude 排除的查询条件
 * @param clazz   实体类
 * @param <T>     类型
 * @return QueryWrapper
 */
public static <T> QueryWrapper<T> getQueryWrapper(Map<String, Object> query, Map<String, Object> exclude, Class<T> clazz) {
	exclude.forEach((k, v) -> query.remove(k));
	QueryWrapper<T> qw = new QueryWrapper<>();
	qw.setEntity(BeanUtil.newInstance(clazz));
	SqlKeyword.buildCondition(query, qw);
	return qw;
}