QueryWrapper
1、想要实现sql:
SELECT COUNT( 1 ) FROM clue_follow_linkman WHERE is_deleted=0 AND (clue_follow_id = ? AND ( (mobile_phone IS NULL OR mobile_phone = ?) ) AND ( (phone IS NULL OR phone = ?) ) AND ( (email IS NULL OR email = ?) ) AND ( (wechat IS NULL OR wechat = ?) ))
代码:
Integer count = this.baseMapper.selectCount(new QueryWrapper<ClueFollowLinkman>().lambda() .eq(ClueFollowLinkman::getClueFollowId, clueFollowId) .and(wrapper -> wrapper.isNull(ClueFollowLinkman::getMobilePhone).or().eq(ClueFollowLinkman::getMobilePhone, "")) .and(wrapper -> wrapper.isNull(ClueFollowLinkman::getPhone).or().eq(ClueFollowLinkman::getPhone, "")) .and(wrapper -> wrapper.isNull(ClueFollowLinkman::getEmail).or().eq(ClueFollowLinkman::getEmail, "")) .and(wrapper -> wrapper.isNull(ClueFollowLinkman::getWechat).or().eq(ClueFollowLinkman::getWechat, "")) ); if (count > 0) { throw new GlobalException("存在联系方式为空的联系人,转商机失败!"); }
虽然可以先根据clueFollowId取出数组,然后根据filter去删选,通过StringUtils.isNotBlank判断是否为空,但会影响性能
2、想要实现找相同的联系人,只要手机号、固定电话、邮箱、微信有一个相同就行
return this.baseMapper.selectList(new QueryWrapper<CustomerLinkman>().lambda().eq(CustomerLinkman::getLinkman, linkman.getLinkman()) .and(wrapper -> wrapper.eq(CustomerLinkman::getMobilePhone, linkman.getMobilePhone()).ne(CustomerLinkman::getMobilePhone, "") .or().eq(CustomerLinkman::getPhone, linkman.getPhone()).ne(CustomerLinkman::getPhone, "") .or().eq(CustomerLinkman::getEmail, linkman.getEmail()).ne(CustomerLinkman::getEmail, "") .or().eq(CustomerLinkman::getWechat, linkman.getWechat()).ne(CustomerLinkman::getWechat, ""))