mybatisflex分页修改

This commit is contained in:
张松 2025-02-18 09:46:16 +08:00
parent 33930a96e8
commit 28b5a7d2d4
3 changed files with 26 additions and 14 deletions

View File

@ -19,8 +19,9 @@ import java.time.LocalDateTime;
*/
public interface ShopUserMapper extends BaseMapper<ShopUser> {
Page<ShopUser> selectPageByKeyAndIsVip(Page<Object> objectPage, @Param("key") String key, @Param("isVip") Integer isVip,
@Param("shopId") Long shopId);
Page<ShopUser> selectPageByKeyAndIsVip();
long selectPageByKeyAndIsVip_COUNT();
int incrAccount(@Param("shopId") long shopId, @Param("id") Long id, @Param("time") LocalDateTime time, @Param("money") BigDecimal money);
int decrAccount(@Param("shopId") long shopId, @Param("id") Long id, @Param("time") LocalDateTime time, @Param("money") BigDecimal money);

View File

@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.shopuser.*;
import com.czg.account.entity.ShopUser;
import com.czg.account.entity.ShopUserFlow;
@ -20,6 +21,8 @@ import com.czg.service.account.mapper.ShopUserMapper;
import com.czg.utils.AssertUtil;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboService;
@ -27,6 +30,8 @@ import org.springframework.stereotype.Service;
import java.math.RoundingMode;
import static com.mybatisflex.core.query.QueryMethods.column;
/**
* 商户储值会员 服务层实现
*
@ -53,7 +58,15 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
@Override
public Page<ShopUser> getPage(String key, Integer isVip) {
return mapper.selectPageByKeyAndIsVip(PageUtil.buildPage(), key, isVip, StpKit.USER.getShopId());
QueryWrapper queryWrapper = new QueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getShopId());
if (StrUtil.isNotBlank(key)) {
queryWrapper.and(column(UserInfo::getNickName).like(key).or(column(UserInfo::getPhone).like(key)));
}
if (isVip != null) {
queryWrapper.eq(ShopUser::getIsVip, isVip);
}
return mapper.xmlPaginate("selectPageByKeyAndIsVip", PageUtil.buildPage(), queryWrapper);
}
@Override

View File

@ -19,17 +19,7 @@
and amount - #{money} >= 0
</update>
<select id="selectPageByKeyAndIsVip" resultType="com.czg.account.entity.ShopUser">
select a.* from tb_user_info as a
left join tb_shop_user as b on a.id=b.user_id
where b.shop_id=#{shopId}
<if test="key != null and key != ''">
and (a.nick_name like %#{key}% or a.phone like %#{key}%)
</if>
<if test="isVip != null">
and b.is_vip=#{isVip}
</if>
</select>
<select id="selectUserSummary" resultType="com.czg.account.dto.shopuser.ShopUserSummaryDTO">
select count(a.id) userTotal, sum(IFNULL(a.amount, 0)) balanceTotal,sum(IFNULL(b.amount,0)) chargeTotal from
tb_shop_user as a
@ -53,4 +43,12 @@
left join tb_shop_activate_in_record as c on c.shop_id = b.shop_id
where a.id=#{userId}
</select>
<select id="selectPageByKeyAndIsVip" resultType="com.czg.account.entity.ShopUser">
select tb_user_info.* from tb_user_info
left join tb_shop_user on tb_user_info.id=tb_shop_user.user_id ${qwSql} limit ${pageOffset}, ${pageSize}
</select>
<select id="selectPageByKeyAndIsVip_COUNT" resultType="java.lang.Long">
select count(1) from tb_user_info
left join tb_shop_user on tb_user_info.id=tb_shop_user.user_id ${qwSql}
</select>
</mapper>