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;
}
}
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);
}
}
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);
}
}
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);
}
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());
}
}
Aggregations