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