Search in sources :

Example 1 with UpdateWrapper

use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project goodsKill by techa03.

the class SeckillServiceImpl method reduceNumberInner.

@Transactional(rollbackFor = Exception.class)
@Override
public int reduceNumberInner(SuccessKilled successKilled) {
    successKilledMapper.insert(successKilled);
    Seckill wrapper = new Seckill();
    wrapper.setSeckillId(successKilled.getSeckillId());
    UpdateWrapper<Seckill> updateWrapper = new UpdateWrapper(wrapper);
    updateWrapper.gt("end_time", successKilled.getCreateTime());
    updateWrapper.lt("start_time", successKilled.getCreateTime());
    updateWrapper.gt("number", 0);
    updateWrapper.setSql("number = number - 1");
    int update = baseMapper.update(null, updateWrapper);
    if (update <= 0) {
        throw new SeckillCloseException("seckill is closed");
    } else {
        taskExecutor.execute(() -> streamBridge.send(DEFAULT_BINDING_NAME_MONGO_SAVE, MessageBuilder.withPayload(SeckillMockSaveVo.builder().seckillId(successKilled.getSeckillId()).userPhone(successKilled.getUserPhone()).note(REDIS_MONGO_REACTIVE.getName()).build()).build()));
        log.info("已发送");
        return update;
    }
}
Also used : SeckillCloseException(com.goodskill.common.exception.SeckillCloseException) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) Seckill(com.goodskill.entity.Seckill) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with UpdateWrapper

use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project jeecg-boot by jeecgboot.

the class SysBaseApiImpl method updateSysAnnounReadFlag.

@Override
public void updateSysAnnounReadFlag(String busType, String busId) {
    SysAnnouncement announcement = sysAnnouncementMapper.selectOne(new QueryWrapper<SysAnnouncement>().eq("bus_type", busType).eq("bus_id", busId));
    if (announcement != null) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = sysUser.getId();
        LambdaUpdateWrapper<SysAnnouncementSend> updateWrapper = new UpdateWrapper().lambda();
        updateWrapper.set(SysAnnouncementSend::getReadFlag, CommonConstant.HAS_READ_FLAG);
        updateWrapper.set(SysAnnouncementSend::getReadTime, new Date());
        updateWrapper.last("where annt_id ='" + announcement.getId() + "' and user_id ='" + userId + "'");
        SysAnnouncementSend announcementSend = new SysAnnouncementSend();
        sysAnnouncementSendMapper.update(announcementSend, updateWrapper);
    }
}
Also used : UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)

Example 3 with UpdateWrapper

use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project solon by noear.

the class OptimisticLockerInnerInterceptor method doOptimisticLocker.

protected void doOptimisticLocker(Map<String, Object> map, String msId) {
    // updateById(et), update(et, wrapper);
    Object et = map.getOrDefault(Constants.ENTITY, null);
    if (Objects.nonNull(et)) {
        // version field
        TableFieldInfo fieldInfo = this.getVersionFieldInfo(et.getClass());
        if (null == fieldInfo) {
            return;
        }
        try {
            Field versionField = fieldInfo.getField();
            // 旧的 version 值
            Object originalVersionVal = versionField.get(et);
            if (originalVersionVal == null) {
                if (null != exception) {
                    /**
                     * 自定义异常处理
                     */
                    throw exception;
                }
                return;
            }
            String versionColumn = fieldInfo.getColumn();
            // 新的 version 值
            Object updatedVersionVal = this.getUpdatedVersionVal(fieldInfo.getPropertyType(), originalVersionVal);
            String methodName = msId.substring(msId.lastIndexOf(StringPool.DOT) + 1);
            if ("update".equals(methodName)) {
                AbstractWrapper<?, ?, ?> aw = (AbstractWrapper<?, ?, ?>) map.getOrDefault(Constants.WRAPPER, null);
                if (aw == null) {
                    UpdateWrapper<?> uw = new UpdateWrapper<>();
                    uw.eq(versionColumn, originalVersionVal);
                    map.put(Constants.WRAPPER, uw);
                } else {
                    aw.apply(versionColumn + " = {0}", originalVersionVal);
                }
            } else {
                map.put(Constants.MP_OPTLOCK_VERSION_ORIGINAL, originalVersionVal);
            }
            versionField.set(et, updatedVersionVal);
        } catch (IllegalAccessException e) {
            throw ExceptionUtils.mpe(e);
        }
    } else // update(LambdaUpdateWrapper) or update(UpdateWrapper)
    if (wrapperMode && map.entrySet().stream().anyMatch(t -> Objects.equals(t.getKey(), Constants.WRAPPER))) {
        setVersionByWrapper(map, msId);
    }
}
Also used : Field(java.lang.reflect.Field) TableFieldInfo(com.baomidou.mybatisplus.core.metadata.TableFieldInfo) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) AbstractWrapper(com.baomidou.mybatisplus.core.conditions.AbstractWrapper)

Example 4 with UpdateWrapper

use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project jeeagile by jeeagile.

the class AgileSysDictTypeServiceImpl method updateModel.

@Override
public boolean updateModel(AgileSysDictType agileSysDictType) {
    this.validateData(agileSysDictType);
    AgileSysDictType oldAgileSysDictType = this.getById(agileSysDictType.getId());
    if (oldAgileSysDictType.getDictType() != agileSysDictType.getDictType()) {
        LambdaUpdateWrapper<AgileSysDictData> lambdaUpdateWrapper = new UpdateWrapper().lambda();
        lambdaUpdateWrapper.set(AgileSysDictData::getDictType, agileSysDictType.getDictType());
        lambdaUpdateWrapper.eq(AgileSysDictData::getDictType, oldAgileSysDictType.getDictType());
        agileSysDictDataService.update(lambdaUpdateWrapper);
    }
    return this.updateById(agileSysDictType);
}
Also used : AgileSysDictData(com.jeeagile.system.entity.AgileSysDictData) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) AgileSysDictType(com.jeeagile.system.entity.AgileSysDictType)

Example 5 with UpdateWrapper

use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project mybatch by mywill26.

the class ImportWriteExcelThread method overHandle.

private void overHandle() {
    File file = new File(filePath);
    String cloudPath = cloudFileService.upload(file, importParam.getUserId());
    excelTaskService.update(new UpdateWrapper<ExcelTask>().set("exp_file_name", file.getName()).set("exp_file_path", cloudPath).eq("id", importParam.getTaskId()));
    if (!file.delete()) {
        LOGGER.error("[{}] file delete fail", file.getName());
    }
}
Also used : UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) File(java.io.File)

Aggregations

UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)97 Transactional (org.springframework.transaction.annotation.Transactional)41 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)40 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)34 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)28 Session (org.apache.shiro.session.Session)24 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)21 Judge (top.hcode.hoj.pojo.entity.judge.Judge)17 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)16 HttpSession (javax.servlet.http.HttpSession)14 Problem (top.hcode.hoj.pojo.entity.problem.Problem)14 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)13 StatusNotFoundException (top.hcode.hoj.common.exception.StatusNotFoundException)11 Group (top.hcode.hoj.pojo.entity.group.Group)11 Date (java.util.Date)10 Discussion (top.hcode.hoj.pojo.entity.discussion.Discussion)10 Contest (top.hcode.hoj.pojo.entity.contest.Contest)8 User (com.baomidou.mybatisplus.samples.wrapper.entity.User)5 Result (org.jeecg.common.api.vo.Result)5 LoginUser (org.jeecg.common.system.vo.LoginUser)5