use of com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper in project qiwen-file by qiwenshare.
the class UserFileService method deleteUserFile.
@Override
public void deleteUserFile(Long userFileId, Long sessionUserId) {
UserFile userFile = userFileMapper.selectById(userFileId);
String uuid = UUID.randomUUID().toString();
if (userFile.getIsDir() == 1) {
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<UserFile>();
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, RandomUtil.randomInt(FileConstant.deleteFileRandomSize)).set(UserFile::getDeleteBatchNum, uuid).set(UserFile::getDeleteTime, DateUtil.getCurrentTime()).eq(UserFile::getUserFileId, userFileId);
userFileMapper.update(null, userFileLambdaUpdateWrapper);
String filePath = userFile.getFilePath() + userFile.getFileName() + "/";
updateFileDeleteStateByFilePath(filePath, uuid, sessionUserId);
} else {
UserFile userFileTemp = userFileMapper.selectById(userFileId);
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, RandomUtil.randomInt(1, FileConstant.deleteFileRandomSize)).set(UserFile::getDeleteTime, DateUtil.getCurrentTime()).set(UserFile::getDeleteBatchNum, uuid).eq(UserFile::getUserFileId, userFileTemp.getUserFileId());
userFileMapper.update(null, userFileLambdaUpdateWrapper);
}
RecoveryFile recoveryFile = new RecoveryFile();
recoveryFile.setUserFileId(userFileId);
recoveryFile.setDeleteTime(DateUtil.getCurrentTime());
recoveryFile.setDeleteBatchNum(uuid);
recoveryFileMapper.insert(recoveryFile);
}
use of com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper in project jeecg-boot by jeecgboot.
the class SysAnnouncementSendController method editById.
/**
* @功能:更新用户系统消息阅读状态
* @param json
* @return
*/
@PutMapping(value = "/editByAnntIdAndUserId")
public Result<SysAnnouncementSend> editById(@RequestBody JSONObject json) {
Result<SysAnnouncementSend> result = new Result<SysAnnouncementSend>();
String anntId = json.getString("anntId");
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 ='" + anntId + "' and user_id ='" + userId + "'");
SysAnnouncementSend announcementSend = new SysAnnouncementSend();
sysAnnouncementSendService.update(announcementSend, updateWrapper);
result.setSuccess(true);
return result;
}
use of com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper in project jeecg-boot by jeecgboot.
the class SysAnnouncementSendController method readAll.
/**
* @功能:一键已读
* @return
*/
@PutMapping(value = "/readAll")
public Result<SysAnnouncementSend> readAll() {
Result<SysAnnouncementSend> result = new Result<SysAnnouncementSend>();
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 user_id ='" + userId + "'");
SysAnnouncementSend announcementSend = new SysAnnouncementSend();
sysAnnouncementSendService.update(announcementSend, updateWrapper);
JSONObject socketParams = new JSONObject();
socketParams.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_TOPIC);
webSocket.sendMessage(socketParams.toJSONString());
result.setSuccess(true);
result.setMessage("全部已读");
return result;
}
use of com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper in project demo-SpringBoot by Max-Qiu.
the class TestUserService method saveOrUpdateWithWrapper.
/**
* 更新或保存,带条件查询
*/
@Test
void saveOrUpdateWithWrapper() {
// update(entity, updateWrapper) || saveOrUpdate(entity);
// 先执行 update ,根据update结果执行 saveOrUpdate
// UPDATE smp_user SET age=? WHERE (age = ?)
// SELECT id,username,age,email FROM smp_user WHERE id=?
// INSERT INTO smp_user ( id, age ) VALUES ( ?, ? )
boolean save1 = userService.saveOrUpdate(new User().setId(2L).setAge(11), new LambdaUpdateWrapper<User>().eq(User::getAge, 18));
System.out.println(save1);
// UPDATE smp_user SET age=? WHERE (age = ?)
boolean save2 = userService.saveOrUpdate(new User().setId(2L).setAge(18), new LambdaUpdateWrapper<User>().eq(User::getAge, 11));
System.out.println(save2);
// UPDATE smp_user SET username=?, age=? WHERE (age = ?)
// SELECT id,username,age,email FROM smp_user WHERE id=?
// UPDATE smp_user SET age=? WHERE id=?
boolean save3 = userService.saveOrUpdate(new User().setId(2L).setAge(18), new LambdaUpdateWrapper<User>().eq(User::getAge, 1));
System.out.println(save3);
}
use of com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper in project demo-SpringBoot by Max-Qiu.
the class TestUser method update2.
@Test
void update2() {
// UPDATE smp_user SET email=? WHERE username=? AND (username = ?)
// 构造WHERE条件
User whereUser = new User();
whereUser.setUsername("xxxxxx");
LambdaUpdateWrapper<User> wrapper = new LambdaUpdateWrapper<>(whereUser);
wrapper.eq(User::getUsername, "xxxxxx");
// 构造 SET 值
User user = new User();
user.setEmail("123@126.com");
boolean i = user.update(wrapper);
System.out.println("更新结果:" + i);
}
Aggregations