Search in sources :

Example 61 with UpdateWrapper

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

the class PurchaseOrderServiceImpl method updatePurchaseOrder.

@Override
@Transactional
public void updatePurchaseOrder(PurchaseOrderSaveCommand purchaseOrderSaveCommand) {
    // 1. 更新采购订单
    PurchaseOrder purchaseOrder = dozerUtils.map(purchaseOrderSaveCommand, PurchaseOrder.class);
    purchaseOrder.setPurchaseOrderStatus(PurchaseOrderStatusEnum.EDITING.getCode());
    this.updateById(purchaseOrder);
    // 2. 删除原来的订单商品详情
    purchaseOrderItemService.remove(new UpdateWrapper<PurchaseOrderItem>().eq("purchase_order_id", purchaseOrder.getId()));
    // 2. 新增订单商品详情
    List<PurchaseOrderItemVO> items = purchaseOrderSaveCommand.getItems();
    items.forEach(item -> item.setPurchaseOrderId(purchaseOrder.getId()));
    List<PurchaseOrderItem> purchaseOrderItems = BeanCopierUtils.copyListProperties(items, PurchaseOrderItem::new);
    purchaseOrderItemService.saveBatch(purchaseOrderItems);
}
Also used : PurchaseOrderItem(com.whoiszxl.entity.PurchaseOrderItem) PurchaseOrderItemVO(com.whoiszxl.cqrs.vo.PurchaseOrderItemVO) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) PurchaseOrder(com.whoiszxl.entity.PurchaseOrder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 62 with UpdateWrapper

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

the class MemberInfoServiceImpl method updateByMemberId.

@Override
public boolean updateByMemberId(MemberInfo memberInfo) {
    UpdateWrapper updateWrapper = new UpdateWrapper<>();
    updateWrapper.eq("member_id", memberInfo.getMemberId());
    return this.update(memberInfo, updateWrapper);
}
Also used : UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)

Example 63 with UpdateWrapper

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

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;
}
Also used : SysAnnouncementSend(org.jeecg.modules.system.entity.SysAnnouncementSend) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) LoginUser(org.jeecg.common.system.vo.LoginUser) Date(java.util.Date) Result(org.jeecg.common.api.vo.Result) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 64 with UpdateWrapper

use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project tutorials-java by Artister.

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

Example 65 with UpdateWrapper

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

the class UserRecordServiceImpl method updateRecord.

/**
 * @MethodNameupdateRecord
 * @Params  * @param null
 * @Description 本方法不启用,不适合数据一致性
 * @Return
 * @Since 2021/6/2
 */
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
@Async
@Override
@Deprecated
public void updateRecord(String uid, Long submitId, Long pid, Integer score) {
    QueryWrapper<Judge> judgeQueryWrapper = new QueryWrapper<>();
    judgeQueryWrapper.isNotNull("score").eq("cid", // 非比赛提交
    0).eq("pid", pid).eq("uid", uid).ne("submit_id", submitId).orderByDesc("score").last("limit 1");
    Judge lastHighScoreJudge = judgeService.getOne(judgeQueryWrapper);
    // 之前没有提交过,那么就需要修改
    boolean result = true;
    if (lastHighScoreJudge == null) {
        UpdateWrapper<UserRecord> userRecordUpdateWrapper = new UpdateWrapper<>();
        userRecordUpdateWrapper.setSql("total_score=total_score+" + score).eq("uid", uid);
        result = userRecordMapper.update(null, userRecordUpdateWrapper) == 1;
    } else if (lastHighScoreJudge.getScore() < score) {
        // 如果之前该题目最高得分的提交比现在得分低,也需要修改
        int addValue = score - lastHighScoreJudge.getScore();
        UpdateWrapper<UserRecord> userRecordUpdateWrapper = new UpdateWrapper<>();
        userRecordUpdateWrapper.setSql("total_score=total_score+" + addValue).eq("uid", uid);
        result = userRecordMapper.update(null, userRecordUpdateWrapper) == 1;
    }
    if (result) {
        return;
    } else {
        // 失败则开始尝试
        tryAgainUpdate(uid, score);
    }
}
Also used : UserRecord(top.hcode.hoj.pojo.entity.user.UserRecord) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Judge(top.hcode.hoj.pojo.entity.judge.Judge) Async(org.springframework.scheduling.annotation.Async) Transactional(org.springframework.transaction.annotation.Transactional)

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