use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project HOJ by HimitZH.
the class RemoteJudgeToSubmit method process.
public boolean process(RemoteJudgeStrategy remoteJudgeStrategy) {
RemoteJudgeDTO remoteJudgeDTO = remoteJudgeStrategy.getRemoteJudgeDTO();
log.info("Ready Send Task to RemoteJudgeDTO => {}", remoteJudgeDTO);
String errLog = null;
try {
remoteJudgeStrategy.submit();
} catch (Exception e) {
log.error("Submit Failed! Error:", e);
errLog = e.getMessage();
}
Long submitId = remoteJudgeDTO.getSubmitId();
// 提交失败 前端手动按按钮再次提交 修改状态 STATUS_SUBMITTED_FAILED
if (submitId == null || submitId == -1L) {
// 将使用的账号放回对应列表
log.error("[{}] Submit Failed! Begin to return the account to other task!", remoteJudgeDTO.getOj());
remoteJudgeService.changeAccountStatus(remoteJudgeDTO.getOj(), remoteJudgeDTO.getUsername());
if (RemoteJudgeContext.openCodeforcesFixServer) {
if (remoteJudgeDTO.getOj().equals(Constants.RemoteJudge.GYM_JUDGE.getName()) || remoteJudgeDTO.getOj().equals(Constants.RemoteJudge.CF_JUDGE.getName())) {
// 对CF特殊,归还判题机权限
log.error("[{}] Submit Failed! Begin to return the Server Status to other task!", remoteJudgeDTO.getOj());
remoteJudgeService.changeServerSubmitCFStatus(remoteJudgeDTO.getServerIp(), remoteJudgeDTO.getServerPort());
}
}
// 更新此次提交状态为提交失败!
UpdateWrapper<Judge> judgeUpdateWrapper = new UpdateWrapper<>();
judgeUpdateWrapper.set("status", Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus()).set("error_message", errLog).eq("submit_id", remoteJudgeDTO.getJudgeId());
judgeEntityService.update(judgeUpdateWrapper);
// 更新其它表
judgeContext.updateOtherTable(remoteJudgeDTO.getSubmitId(), Constants.Judge.STATUS_SYSTEM_ERROR.getStatus(), remoteJudgeDTO.getCid(), remoteJudgeDTO.getUid(), remoteJudgeDTO.getPid(), remoteJudgeDTO.getGid(), null, null);
return false;
}
// 提交成功顺便更新状态为-->STATUS_PENDING 等待判题中...
judgeEntityService.updateById(new Judge().setSubmitId(remoteJudgeDTO.getJudgeId()).setStatus(Constants.Judge.STATUS_PENDING.getStatus()).setVjudgeSubmitId(submitId).setVjudgeUsername(remoteJudgeDTO.getUsername()).setVjudgePassword(remoteJudgeDTO.getPassword()).setJudger(name));
log.info("[{}] Submit Successfully! The submit_id of remote judge is [{}]. Waiting the result of the task!", submitId, remoteJudgeDTO.getOj());
return true;
}
use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project boot-admin by hb0730.
the class BaseServiceImpl method update.
@Override
public boolean update(Wrapper<ENTITY> updateWrapper) {
if (updateWrapper instanceof UpdateWrapper) {
UpdateWrapper<ENTITY> update = (UpdateWrapper<ENTITY>) updateWrapper;
update.set(BusinessDomain.UPDATE_TIME, LocalDateTime.now());
// 设置用户
User currentUser = SecurityUtils.getCurrentUser();
if (null != currentUser) {
update.set(BusinessDomain.UPDATE_USER_ID, currentUser.getId());
}
}
return super.update(updateWrapper);
}
use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project mybatis-plus-samples by baomidou.
the class AssociationTest method testUpdate.
private void testUpdate() {
System.out.println("=======================开始更新==================================================>");
UpdateWrapper<User> wrapper = new UpdateWrapper<>();
wrapper.eq("company_id", 1);
User user = new User();
user.setName(new Date().getTime() + "");
userService.update(user, wrapper);
testSelect();
}
use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project mybatis-plus-samples by baomidou.
the class WrapperTest method tests.
@Test
public void tests() {
System.out.println("----- 普通查询 ------");
List<User> plainUsers = userMapper.selectList(new QueryWrapper<User>().eq("role_id", 2L));
List<User> lambdaUsers = userMapper.selectList(new QueryWrapper<User>().lambda().eq(User::getRoleId, 2L));
Assertions.assertEquals(plainUsers.size(), lambdaUsers.size());
print(plainUsers);
System.out.println("----- 带子查询(sql注入) ------");
List<User> plainUsers2 = userMapper.selectList(new QueryWrapper<User>().inSql("role_id", "select id from role where id = 2"));
List<User> lambdaUsers2 = userMapper.selectList(new QueryWrapper<User>().lambda().inSql(User::getRoleId, "select id from role where id = 2"));
Assertions.assertEquals(plainUsers2.size(), lambdaUsers2.size());
print(plainUsers2);
System.out.println("----- 带嵌套查询 ------");
List<User> plainUsers3 = userMapper.selectList(new QueryWrapper<User>().nested(i -> i.eq("role_id", 2L).or().eq("role_id", 3L)).and(i -> i.ge("age", 20)));
List<User> lambdaUsers3 = userMapper.selectList(new QueryWrapper<User>().lambda().nested(i -> i.eq(User::getRoleId, 2L).or().eq(User::getRoleId, 3L)).and(i -> i.ge(User::getAge, 20)));
Assertions.assertEquals(plainUsers3.size(), lambdaUsers3.size());
print(plainUsers3);
System.out.println("----- 自定义(sql注入) ------");
// 方式一
List<User> plainUsers4 = userMapper.selectList(new QueryWrapper<User>().apply("role_id = 2"));
/* List<User> lambdaUsers4 = userMapper.selectList(new QueryWrapper<User>().lambda()
.apply("role_id = 2"));*/
// 方式二
List<User> plainUsers5 = userMapper.selectList(new QueryWrapper<User>().apply("role_id = {0}", 2));
/* List<User> lambdaUsers5 = userMapper.selectList(new QueryWrapper<User>().lambda()
.apply("role_id = {0}",2));*/
print(plainUsers4);
Assertions.assertEquals(plainUsers4.size(), plainUsers5.size());
UpdateWrapper<User> uw = new UpdateWrapper<>();
uw.set("email", null);
uw.eq("id", 4);
userMapper.update(new User(), uw);
User u4 = userMapper.selectById(4);
Assertions.assertNull(u4.getEmail());
}
use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project mybatis-plus-samples by baomidou.
the class WrapperTest method lambdaQueryWrapper.
@Test
public void lambdaQueryWrapper() {
System.out.println("----- 普通查询 ------");
List<User> plainUsers = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getRoleId, 2L));
List<User> lambdaUsers = userMapper.selectList(new QueryWrapper<User>().lambda().eq(User::getRoleId, 2L));
Assertions.assertEquals(plainUsers.size(), lambdaUsers.size());
print(plainUsers);
System.out.println("----- 带子查询(sql注入) ------");
List<User> plainUsers2 = userMapper.selectList(new LambdaQueryWrapper<User>().inSql(User::getRoleId, "select id from role where id = 2"));
List<User> lambdaUsers2 = userMapper.selectList(new QueryWrapper<User>().lambda().inSql(User::getRoleId, "select id from role where id = 2"));
Assertions.assertEquals(plainUsers2.size(), lambdaUsers2.size());
print(plainUsers2);
System.out.println("----- 带嵌套查询 ------");
List<User> plainUsers3 = userMapper.selectList(new LambdaQueryWrapper<User>().nested(i -> i.eq(User::getRoleId, 2L).or().eq(User::getRoleId, 3L)).and(i -> i.ge(User::getAge, 20)));
List<User> lambdaUsers3 = userMapper.selectList(new QueryWrapper<User>().lambda().nested(i -> i.eq(User::getRoleId, 2L).or().eq(User::getRoleId, 3L)).and(i -> i.ge(User::getAge, 20)));
Assertions.assertEquals(plainUsers3.size(), lambdaUsers3.size());
print(plainUsers3);
System.out.println("----- 自定义(sql注入) ------");
List<User> plainUsers4 = userMapper.selectList(new QueryWrapper<User>().apply("role_id = 2"));
print(plainUsers4);
UpdateWrapper<User> uw = new UpdateWrapper<>();
uw.set("email", null);
uw.eq("id", 4);
userMapper.update(new User(), uw);
User u4 = userMapper.selectById(4);
Assertions.assertNull(u4.getEmail());
}
Aggregations