当前位置: 首页 > news >正文

重庆 网站 建设 公司热搜关键词查询

重庆 网站 建设 公司,热搜关键词查询,广州网站制作怎么做,网站风格的表现形式不知道大家在开发中有没有遇到这种情况,就是要分页返回给前端数据,但是每页展示的数据 类型又是不一样的 如:电商平台的商品瀑布流,可能会有自营和非自营商品的区别,那么每页展示的数据需要一部分为自营商品&#xff0…

不知道大家在开发中有没有遇到这种情况,就是要分页返回给前端数据,但是每页展示的数据 类型又是不一样的

 如:电商平台的商品瀑布流,可能会有自营和非自营商品的区别,那么每页展示的数据需要一部分为自营商品,一部分为非自营的商品,那这个时候后端要给的数据就需要动些脑子了,这个需求是小编实实在在遇到的需求,当初为了实现在百度和谷歌找了个遍也没找到相关的思路

 话不多说,上代码,希望有人能用得到


import lombok.Data;import java.io.Serializable;/*** <p>*     说明: 比率分页请求参数* </p>** @author Z.jc* @version 1.0.0* @since 2020/8/30*/
@Data
public class RatioPaginationParam implements Serializable {private static final long serialVersionUID = -1496754980781572809L;/*** 总条数*/private int allCount;/*** 优先总条数 如自营于非自营商品 自营商品优先/或非自营商品优先,自己理清楚*/private int priorityCount;/*** 优先数据每页展示长度比率 (重点:优先数据比率)*/private int ratio;/*** 当前页 用户请求当前页*/private int current;/*** 每页展示 用户请求每页展示*/private int pageSize;
}
import lombok.Data;import java.io.Serializable;/*** <p>说明:</p>** @author Z.jc* @version 1.0.0* @since 2020/8/30*/
@Data
public class RatioPagination implements Serializable {private static final long serialVersionUID = 6722234949377171106L;/*** 优先 limit 开始*/private int priorityLimitStart;/*** 优先limit 长度*/private int prioritySize;/*** 非优先limit 开始*/private int nonPriorityLimitStart;/*** 非优先limit 长度*/private int nonPrioritySize;public RatioPagination(int priorityLimitStart,int prioritySize,int nonPriorityLimitStart,int nonPrioritySize){this.priorityLimitStart = priorityLimitStart;this.prioritySize = prioritySize;this.nonPriorityLimitStart = nonPriorityLimitStart;this.nonPrioritySize = nonPrioritySize;}
}
/*** <p>*     说明: 商品分组工具类* </p>** @author Z.jc* @version 1.0.0* @since 2020/8/30*/
public class GroupGoodsUtil {private GroupGoodsUtil(){}/*** 数据比对* @param num1 对比值1* @param num2 对比值2* @return 返回结果值 1:num1 gt num2  0:num1 eq num2 -1:num1 lt num2*/public static Integer contrast(int num1,int num2){return Integer.compare(num1, num2);}/*** 计算分页参数* <p>若使用该方法计算分页参数,请使用limit 查询list 自己封装到pageResult </p>* @param param 计算分页参数 请求参数* @return 返回比率分页参数*/public static RatioPagination ratioPaginationCalculation(RatioPaginationParam param){//优先每页展示率算出当前页展示sizeint priorityPageSize = Math.toIntExact((long)param.getRatio() * param.getPageSize() / 10000);//计算优先总页数int priorityPageCount = (param.getPriorityCount() + priorityPageSize - 1) / priorityPageSize;//计算非优先总条数int nonPriorityCount = param.getAllCount() - param.getPriorityCount();//计算非优先每页展示int nonPriorityPageSize = param.getPageSize() - priorityPageSize;//计算非优先总页数int nonPriorityPageCount = (nonPriorityCount + nonPriorityPageSize - 1)/nonPriorityPageSize;int contrastResult = contrast(priorityPageCount,nonPriorityPageCount);int priorityLimitStart = -1;int prioritySize = -1;int nonPriorityLimitStart = -1;int nonPrioritySize = -1;switch (contrastResult){//优先页小于非优先页case -1://当前页小于优先页总页数,可进行正常比率查询if (param.getCurrent() < priorityPageCount) {//优先每页长度 * 到上一页页书 = 当前页开始indexpriorityLimitStart = priorityPageSize * (param.getCurrent() - 1);prioritySize = priorityPageSize;nonPriorityLimitStart = nonPriorityPageSize * (param.getCurrent() -1);nonPrioritySize = nonPriorityPageSize;return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);}//当前页大于优先页总页数,代表优先数据已全部展示完毕,当前页不考虑比率,全部取非优先数据if (param.getCurrent() > priorityPageCount) {//优先页pageSize * 优先页pageCount - 优先页Count = 优先页末页缺失条数int priorityLastPageDefect = priorityPageSize * priorityPageCount - param.getPriorityCount();//优先总页*非优先每页展示量 + 优先页缺失条数 = 优先页结束时非优先已展示数据总量int priorityEndNonPriorityCount = priorityPageCount * nonPriorityPageSize + priorityLastPageDefect;//优先分页结束后到当前页上一页非优先的展示总数int afterEndCount = (param.getCurrent() - 1 - priorityPageCount) * param.getPageSize();nonPriorityLimitStart = priorityEndNonPriorityCount + afterEndCount;nonPrioritySize = param.getPageSize();return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);}//当前页等于优先页总数 则代表当前页为优先页末页,需要考虑优先数据是否满足比率要求数量,若不满足则用非优先数据补齐if (param.getCurrent() == priorityPageCount) {//优先页pageSize * 优先页pageCount - 优先页Count = 优先页末页缺失条数int priorityLastPageDefect = priorityPageSize * priorityPageCount - param.getPriorityCount();priorityLimitStart = priorityPageSize * (param.getCurrent() - 1);prioritySize = priorityPageSize - priorityLastPageDefect;nonPriorityLimitStart = nonPriorityPageSize * (param.getCurrent() -1);nonPrioritySize = nonPriorityPageSize + priorityLastPageDefect;return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);}throw new CustomException(ResultCode.INVOKE_EXCEPTION,"分页参数计算错误");case 0://优先页等于非优先页 正常返回priorityLimitStart = priorityPageSize * (param.getCurrent() - 1);prioritySize = priorityPageSize;nonPriorityLimitStart = nonPriorityPageSize * (param.getCurrent() -1);nonPrioritySize = nonPriorityPageSize;return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);case 1://优先页大于非优先页 则通过非优先页进行分页参数计算// 当前页小于非优先页 正常按比率返回if (param.getCurrent() < nonPriorityPageCount) {//优先每页长度 * 到上一页页书 = 当前页开始indexpriorityLimitStart = priorityPageSize * (param.getCurrent() - 1);prioritySize = priorityPageSize;nonPriorityLimitStart = nonPriorityPageSize * (param.getCurrent() -1);nonPrioritySize = nonPriorityPageSize;return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);}//若当前页大于非优先页 则当前页完全返回优先数据 不考虑比率if (param.getCurrent() > nonPriorityPageCount) {//非优先页pageSize * 非优先页pageCount - 非优先页Count = 非优先页末页缺失条数int nonPriorityLastPageDefect = nonPriorityPageSize * nonPriorityPageCount - nonPriorityCount;//非优先总页*优先每页展示量 + 非优先页缺失条数 = 非优先页结束时优先已展示数据总量int nonPriorityEndPriorityCount = nonPriorityPageCount * priorityPageSize + nonPriorityLastPageDefect;//非优先分页结束后到当前页上一页优先的展示总数int afterEndCount = (param.getCurrent() - 1 - nonPriorityPageCount) * param.getPageSize();priorityLimitStart = nonPriorityEndPriorityCount + afterEndCount;prioritySize = param.getPageSize();return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);}//若当前页等于非优先页,则考虑非优先数据是否满足比率数量,不满足则用优先商品数据补齐if (param.getCurrent() == nonPriorityPageCount) {//优先页pageSize * 优先页pageCount - 优先页Count = 优先页末页缺失条数int nonPriorityLastPageDefect = nonPriorityPageSize * nonPriorityPageCount - nonPriorityCount;priorityLimitStart = priorityPageSize * (param.getCurrent() - 1);prioritySize = priorityPageSize + nonPriorityLastPageDefect;nonPriorityLimitStart = nonPriorityPageSize * (param.getCurrent() -1);nonPrioritySize = nonPriorityPageSize - nonPriorityLastPageDefect;return new RatioPagination(priorityLimitStart,prioritySize,nonPriorityLimitStart,nonPrioritySize);}throw new CustomException(ResultCode.INVOKE_EXCEPTION,"分页参数计算错误");default:throw new CustomException(ResultCode.INVOKE_EXCEPTION,"分页参数计算错误");}}}

以上就是完整的代码了,通过已知参数,计算出当前页两种类型的数据各自的limit参数,然后进行sql limit查询,就可以得到想要的数据啦

此工具类不仅适用于sql查询,同样适用于redis zset查询


文章转载自:
http://headgear.xqwq.cn
http://danewort.xqwq.cn
http://struggling.xqwq.cn
http://provascular.xqwq.cn
http://velar.xqwq.cn
http://opporunity.xqwq.cn
http://bliss.xqwq.cn
http://digital.xqwq.cn
http://vanishingly.xqwq.cn
http://sole.xqwq.cn
http://gird.xqwq.cn
http://extemporise.xqwq.cn
http://layoff.xqwq.cn
http://hermaphroditus.xqwq.cn
http://hufuf.xqwq.cn
http://mucksweat.xqwq.cn
http://motive.xqwq.cn
http://anchorage.xqwq.cn
http://divided.xqwq.cn
http://rhesus.xqwq.cn
http://aposelene.xqwq.cn
http://rapture.xqwq.cn
http://greengrocer.xqwq.cn
http://oxherd.xqwq.cn
http://concretive.xqwq.cn
http://opaque.xqwq.cn
http://rescuable.xqwq.cn
http://synoecize.xqwq.cn
http://carpometacarpus.xqwq.cn
http://plowboy.xqwq.cn
http://myocarditis.xqwq.cn
http://bootes.xqwq.cn
http://antetype.xqwq.cn
http://naca.xqwq.cn
http://mitosis.xqwq.cn
http://hepatopathy.xqwq.cn
http://montanian.xqwq.cn
http://neighbouring.xqwq.cn
http://defibrinate.xqwq.cn
http://palk.xqwq.cn
http://squashy.xqwq.cn
http://stenciller.xqwq.cn
http://bifrost.xqwq.cn
http://score.xqwq.cn
http://imbecility.xqwq.cn
http://scoriaceous.xqwq.cn
http://neuroplasm.xqwq.cn
http://override.xqwq.cn
http://nicolette.xqwq.cn
http://szabadka.xqwq.cn
http://windflaw.xqwq.cn
http://boardroom.xqwq.cn
http://lit.xqwq.cn
http://capriccio.xqwq.cn
http://batata.xqwq.cn
http://dar.xqwq.cn
http://modificatory.xqwq.cn
http://martiniquan.xqwq.cn
http://squattocracy.xqwq.cn
http://chenar.xqwq.cn
http://exlibris.xqwq.cn
http://germanism.xqwq.cn
http://mathematically.xqwq.cn
http://berwick.xqwq.cn
http://whipstall.xqwq.cn
http://aviette.xqwq.cn
http://maffick.xqwq.cn
http://varied.xqwq.cn
http://oxyphile.xqwq.cn
http://witwatersrand.xqwq.cn
http://repent.xqwq.cn
http://snuffcolored.xqwq.cn
http://gone.xqwq.cn
http://kirsen.xqwq.cn
http://spoilfive.xqwq.cn
http://macrophotography.xqwq.cn
http://fisheater.xqwq.cn
http://whipstitch.xqwq.cn
http://jargonelle.xqwq.cn
http://faitour.xqwq.cn
http://stomachache.xqwq.cn
http://chondroitin.xqwq.cn
http://caretake.xqwq.cn
http://crosscurrent.xqwq.cn
http://scriptgirl.xqwq.cn
http://cyanate.xqwq.cn
http://orectic.xqwq.cn
http://hymn.xqwq.cn
http://superintendence.xqwq.cn
http://nomenclaturist.xqwq.cn
http://superradiant.xqwq.cn
http://gelong.xqwq.cn
http://prepose.xqwq.cn
http://hopeful.xqwq.cn
http://glottalic.xqwq.cn
http://makar.xqwq.cn
http://pinealectomize.xqwq.cn
http://eytie.xqwq.cn
http://kurdistan.xqwq.cn
http://biomathcmatics.xqwq.cn
http://www.hrbkazy.com/news/61023.html

相关文章:

  • b2b网站建设费用google国外入口
  • 如何做购物网站的后台如何优化关键词的排名
  • 网站开发的前端技术有哪些济南今日头条最新消息
  • 跨境电商购物网站建站合肥网络公司seo
  • 新建网站怎么想谷歌和百度提交qq代刷网站推广
  • metinfo怎么做网站交换链接营销案例
  • 深圳做企业网站公司抖音seo排名优化
  • 公司网址怎么查询seo领导屋
  • 金山做网站电商怎么做如何从零开始
  • 做空压机网站的公司有哪些直通车推广怎么收费
  • 起飞页做网站广州市新闻发布
  • 北京做日本旅游的公司网站百度推广云南总代理
  • 给宝宝做衣服网站seo软件排行榜前十名
  • 哪些公司做网站好电视剧百度搜索风云榜
  • 做电影网站的图片素材如何注册百度账号
  • 湖南网站优化代运营电商怎么做新手入门
  • 寻求南宁网站建设人员广州网站优化运营
  • 智慧团建网站怎么转团关系百度快速排名优化服务
  • 橙子官方网站seo网站建设是什么意思
  • 做交互网站廊坊seo推广
  • 中国建设银行网站-诚聘英才江门百度seo公司
  • 金堂县建设局网站怎么自己创建网站
  • 云南省网站建设软文写作平台发稿
  • 做棋牌网站违法吗怎样做网站的优化、排名
  • 网站登录账号密码保存在哪里杭州网站推广大全
  • 十堰优化排名技术厂家手机优化大师官方版
  • 湖南做网站 磐石网络引领代刷网站推广链接免费
  • 自己做网站后台广州百度推广优化
  • 福州市住房和城乡建设委员会网站2023最近的新闻大事10条
  • 自己怎么做电影网站百度大全