Search in sources :

Example 41 with UpdateWrapper

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;
}
Also used : RemoteJudgeDTO(top.hcode.hoj.remoteJudge.entity.RemoteJudgeDTO) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) Judge(top.hcode.hoj.pojo.entity.judge.Judge)

Example 42 with UpdateWrapper

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);
}
Also used : User(com.hb0730.boot.admin.security.model.User) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)

Example 43 with 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();
}
Also used : User(com.baomidou.mybatisplus.samples.association.entity.User) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) Date(java.util.Date)

Example 44 with UpdateWrapper

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());
}
Also used : Test(org.junit.jupiter.api.Test) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) List(java.util.List) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) RoleMapper(com.baomidou.mybatisplus.samples.wrapper.mapper.RoleMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) User(com.baomidou.mybatisplus.samples.wrapper.entity.User) CollectionUtils(org.springframework.util.CollectionUtils) Assertions(org.junit.jupiter.api.Assertions) Resource(javax.annotation.Resource) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) UserMapper(com.baomidou.mybatisplus.samples.wrapper.mapper.UserMapper) User(com.baomidou.mybatisplus.samples.wrapper.entity.User) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 45 with UpdateWrapper

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());
}
Also used : Test(org.junit.jupiter.api.Test) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) List(java.util.List) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) RoleMapper(com.baomidou.mybatisplus.samples.wrapper.mapper.RoleMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) User(com.baomidou.mybatisplus.samples.wrapper.entity.User) CollectionUtils(org.springframework.util.CollectionUtils) Assertions(org.junit.jupiter.api.Assertions) Resource(javax.annotation.Resource) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) UserMapper(com.baomidou.mybatisplus.samples.wrapper.mapper.UserMapper) User(com.baomidou.mybatisplus.samples.wrapper.entity.User) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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