• 价格明细接口分析


     一.价格明细页面

     二.调用的接口

    1.

    https://irendui.com/v1/users/17364/rights

    2.

    https://irendui.com/v1/market/volume/search?widthList=1000&productId=1&thickness=0.11&pageNo=1&pageSize=10&

    3.

    https://irendui.com/v1/market/vender/volume/summary?widthList=1000&productId=1&thickness=0.11&pageNo=1&pageSize=10&venderId=301& 

    4.

    https://irendui.com/v1/market/vender/volume/summary?widthList=1000&productId=1&thickness=0.11&pageNo=1&pageSize=10&venderId=283& 

    5.

    https://irendui.com/v1/jec/rendui/prices/dailyByProductSpec?productSpec=1457211726671400962_1000_0.11_%E5%BD%A9%E5%9F%BA%E9%95%80%E9%94%8C&date=2022-07-04%2000:00:00&siteId=1457210664971423746& 

    6.https://irendui.com/v1/market/vender/volume/summary?widthList=1000&productId=1&thickness=0.11&pageNo=1&pageSize=10&venderId=265& 

    7.

    https://irendui.com/v1/jec/rendui/prices/statistics?siteId=1457210664971423746&productSpec=1457211726671400962_1000_0.11_%E5%BD%A9%E5%9F%BA%E9%95%80%E9%94%8C&from=2022-07-04%2009:00:00&to=2022-07-04%2009:46:51& 

    8.

    https://irendui.com/v1/market/vender/volume/summary?widthList=1000&productId=1&thickness=0.11&pageNo=1&pageSize=10&venderId=258& 

    9.

    https://irendui.com/v1/market/vender/volume/summary?widthList=1000&productId=1&thickness=0.11&pageNo=1&pageSize=10&venderId=453& 

    三.对接口进行详细分析

     2.

    库存搜索接口

    https://irendui.com/v1/market/volume/search?widthList=1000&productId=1&thickness=0.11&pageNo=1&pageSize=10&

    结果:

    1. {
    2. "errno": 0,
    3. "data": [
    4. {
    5. "count": 12,
    6. "weight": 63.448,
    7. "length": 76654.0,
    8. "id": 301,
    9. "name": "山东聚德鑫新型建材有限公司",
    10. "legalRepName": "李超",
    11. "legalRepPhone": null,
    12. "imgUrl": null,
    13. "updateTime": "2022-07-03 15:10:54",
    14. "material": null
    15. },
    16. {
    17. "count": 13,
    18. "weight": 61.090,
    19. "length": 73008.0,
    20. "id": 283,
    21. "name": "山东修堂新型材料有限公司",
    22. "legalRepName": "刘娟",
    23. "legalRepPhone": null,
    24. "imgUrl": null,
    25. "updateTime": "2022-07-03 14:48:04",
    26. "material": null
    27. },
    28. {
    29. "count": 10,
    30. "weight": 53.136,
    31. "length": 63726.0,
    32. "id": 265,
    33. "name": "博兴县盛凯钢铁有限公司",
    34. "legalRepName": "魏鲁传",
    35. "legalRepPhone": null,
    36. "imgUrl": null,
    37. "updateTime": "2022-06-25 09:37:35",
    38. "material": null
    39. },
    40. {
    41. "count": 3,
    42. "weight": 12.246,
    43. "length": 14749.0,
    44. "id": 258,
    45. "name": "山东泰达板业有限公司",
    46. "legalRepName": "赵海",
    47. "legalRepPhone": null,
    48. "imgUrl": null,
    49. "updateTime": "2022-06-22 11:36:34",
    50. "material": null
    51. },
    52. {
    53. "count": 24,
    54. "weight": 144.600,
    55. "length": 177606.0,
    56. "id": 453,
    57. "name": "博兴县佳兴钢铁经营部",
    58. "legalRepName": "纪金丽",
    59. "legalRepPhone": null,
    60. "imgUrl": null,
    61. "updateTime": "2022-04-08 14:17:10",
    62. "material": null
    63. }
    64. ],
    65. "errmsg": "成功"
    66. }

     对应在小程序端的 推荐库存的数据

     controller层

    1. @TenantFilter(filter = true)
    2. @ApiOperation("库存搜索接口")
    3. @GetMapping("volume/search")
    4. public Object SearchVolumes(@RequestHeader(value = "phone",required = false) String phone,
    5. @RequestHeader(value = "venderId",required = false) Integer loginVendorId,
    6. @RequestHeader(value = "venderStaffId",required = false) Integer venderStaffId,
    7. @RequestParam Integer productId,
    8. @RequestParam(required = false) Integer type,
    9. @RequestParam(required = false) Double width,
    10. @RequestParam(required = false) String widthList,
    11. @RequestParam(required = false) Double thickness,
    12. @RequestParam(required = false) Double thickness2,
    13. @RequestParam(required = false) Double weight,
    14. @RequestParam(required = false) Double weight2,
    15. @RequestParam(required = false)String material,
    16. @RequestParam(required = false) Integer venderId,
    17. @RequestParam(required = false) String venderName,
    18. @RequestParam(defaultValue = "1") Integer pageNo,
    19. @RequestParam(defaultValue = "20") Integer pageSize) {
    20. return ResponseUtil.ok(
    21. volumeService.vendorVolumeSearch(
    22. productId, type, width, widthList,
    23. thickness, thickness2,
    24. weight, weight2,material,venderId,venderName,
    25. (pageNo - 1) * pageSize, pageSize));
    26. }

     前端传来了5个参数

     

    1. @TenantFilter(filter = true)
    2. @ApiOperation("库存搜索接口")
    3. @GetMapping("volume/search")
    4. public Object SearchVolumes(@RequestHeader(value = "phone",required = false) String phone,
    5. @RequestHeader(value = "venderId",required = false) Integer loginVendorId,
    6. @RequestHeader(value = "venderStaffId",required = false) Integer venderStaffId,
    7. @RequestParam Integer productId,
    8. @RequestParam(required = false) Integer type,
    9. @RequestParam(required = false) Double width,
    10. @RequestParam(required = false) String widthList,
    11. @RequestParam(required = false) Double thickness,
    12. @RequestParam(required = false) Double thickness2,
    13. @RequestParam(required = false) Double weight,
    14. @RequestParam(required = false) Double weight2,
    15. @RequestParam(required = false)String material,
    16. @RequestParam(required = false) Integer venderId,
    17. @RequestParam(required = false) String venderName,
    18. @RequestParam(defaultValue = "1") Integer pageNo,
    19. @RequestParam(defaultValue = "20") Integer pageSize) {
    20. return ResponseUtil.ok(
    21. volumeService.vendorVolumeSearch(
    22. productId, type, width, widthList,
    23. thickness, thickness2,
    24. weight, weight2,material,venderId,venderName,
    25. (pageNo - 1) * pageSize, pageSize));
    26. }

    service层

    1. @Override
    2. public List<VolumeSearchVO> vendorVolumeSearch(
    3. Integer productId, Integer type,
    4. Double width, String widthList,
    5. Double thickness, Double thickness2,
    6. Double weight, Double weight2, String material,
    7. Integer venderId,String venderName,
    8. Integer pageNo, Integer pageSize) {
    9. if (thickness == null || thickness2 == null) {
    10. thickness = thickness2 = thickness != null?thickness : thickness2;
    11. }
    12. if (weight == null || weight2 == null) {
    13. weight = weight2 = weight != null?weight : weight2;
    14. }
    15. String[] widthArr = null;
    16. if (StringUtils.isNotBlank(widthList)) {
    17. widthArr = StringUtils.split(widthList, ",");
    18. }
    19. List<String> materialList = new ArrayList<>();
    20. if (StringUtils.isNotBlank(material)) {
    21. materialList = Arrays.asList(material.replace(" ", "").split(","));
    22. }
    23. return volumeMapper.vendorVolumeSearch(
    24. productId, type,
    25. width, widthArr,
    26. thickness, thickness2,
    27. weight, weight2, materialList,venderId,venderName,
    28. pageNo, pageSize);
    29. }

    mapper层

    public interface VenderVolumeMapper extends BaseMapper<VenderVolume> {

    mapper.xml

    1. <select id="vendorVolumeSearch" resultType="com.ruopu.tomfox.dao.vo.wechat.VolumeSearchVO">
    2. SELECT
    3. count(vl.id) as count,
    4. sum(vl.weight) as weight,
    5. sum(vl.length) as length,
    6. if(vu.update_time is not null, vu.update_time, "2020-09-01 00:00:00") as update_time,
    7. v.id, v.name, v.legal_rep_name, v.legal_rep_phone, v.img_url, vl.material
    8. FROM vender_volume vl
    9. LEFT JOIN vender v on (vl.vender_id = v.id)
    10. LEFT JOIN vender_config vc on (vl.vender_id = vc.vender_id)
    11. LEFT JOIN vender_volume_update vu on (vl.vender_id = vu.vender_id)
    12. WHERE
    13. vl.deleted = 0
    14. AND vl.status = 2
    15. AND vc.board_open = true
    16. -- AND (vl.weight > 0 or vl.original_weight > 0) --20211213BUG 后端上传热卷 轧硬在小程序没办法显示 因为新的模板没有这个限制
    17. AND vl.product_id = #{productId}
    18. <if test="type != null">
    19. AND `type` = #{type}
    20. </if>
    21. <if test="width != null">
    22. AND `width` = #{width}
    23. </if>
    24. <include refid="WidthArrQuery"></include>
    25. <include refid="ThicknessQuery"></include>
    26. <include refid="WeightQuery"></include>
    27. <include refid="materialQuery"></include>
    28. <include refid="VenderQuery"></include>
    29. GROUP BY v.id, v.name, v.legal_rep_name, v.legal_rep_phone, v.img_url
    30. ORDER BY update_time desc,count desc
    31. limit #{pageNo}, #{pageSize}
    32. </select>

    涉及的表 四张

    vender_volume
    vender
    vender_config
    vender_volume_update

    3.

    https://irendui.com/v1/market/vender/volume/summary?widthList=1000&productId=1&thickness=0.11&pageNo=1&pageSize=10&venderId=301&

    库存搜索接口

    postman测试

     结果

    1. {
    2. "errno": 0,
    3. "data": [
    4. {
    5. "count": 12,
    6. "weight": 63.448,
    7. "length": 76654.0,
    8. "width": 1000.0,
    9. "thickness": 0.11,
    10. "thickness2": 0.0,
    11. "type": 1,
    12. "material": null,
    13. "color": null,
    14. "price": null,
    15. "maxPrice": 0.00,
    16. "minPrice": 0.00,
    17. "originStr": "宏盛达",
    18. "stockName": "宏盛达"
    19. }
    20. ],
    21. "errmsg": "成功"
    22. }

    对应在小程序的数据为 推荐库存下的详细规格

     

    这些信息 

    controller层

    1. @TenantFilter(filter = true)
    2. @ApiOperation("库存搜索接口")
    3. @GetMapping("/vender/volume/summary")
    4. public Object SearchVolumesSummary(
    5. @RequestHeader(value = "phone",required = false) String phone,
    6. @RequestHeader(value = "venderId",required = false) Integer loginVendorId,
    7. @RequestHeader(value = "venderStaffId",required = false) Integer venderStaffId,
    8. @RequestParam Integer productId,
    9. @RequestParam(required = false) Integer type,
    10. @RequestParam(required = false) Double width,
    11. @RequestParam(required = false) String widthList,
    12. @RequestParam(required = false) Double thickness,
    13. @RequestParam(required = false) Double thickness2,
    14. @RequestParam(required = false) Double weight,
    15. @RequestParam(required = false) Double weight2,
    16. @RequestParam(required = false) Integer venderId,
    17. @RequestParam(required = false) String venderName,
    18. @RequestParam(required = false)String material,
    19. @RequestParam(defaultValue = "1") Integer pageNo,
    20. @RequestParam(defaultValue = "20") Integer pageSize) {
    21. return ResponseUtil.ok(volumeService.vendorVolumeSearchSummary(
    22. venderId, productId, type,
    23. width, widthList,
    24. thickness, thickness2,
    25. weight, weight2, material,venderName,
    26. (pageNo - 1) * pageSize, pageSize));
    27. }

    service层

    1. @Override
    2. public List<VolumeSearchSummaryVO> vendorVolumeSearchSummary(
    3. Integer venderId, Integer productId, Integer type,
    4. Double width, String widthList,
    5. Double thickness, Double thickness2,
    6. Double weight, Double weight2, String material,String venderName,
    7. Integer pageNo, Integer pageSize) {
    8. if (thickness == null || thickness2 == null) {
    9. thickness = thickness2 = thickness != null?thickness : thickness2;
    10. }
    11. if (weight == null || weight2 == null) {
    12. weight = weight2 = weight != null?weight : weight2;
    13. }
    14. String[] widthArr = null;
    15. if (StringUtils.isNotBlank(widthList)) {
    16. widthArr = StringUtils.split(widthList, ",");
    17. }
    18. List<String> materialList = new ArrayList<>();
    19. if (StringUtils.isNotBlank(material)) {
    20. materialList = Arrays.asList(material.replace(" ", "").split(","));
    21. }
    22. return volumeMapper.vendorVolumeSearchSummary(
    23. venderId, productId, type,
    24. width, widthArr,
    25. thickness, thickness2,
    26. weight, weight2, materialList,venderName,
    27. pageNo, pageSize);
    28. }
    1. <select id="vendorVolumeSearchSummary" resultType="com.ruopu.tomfox.dao.vo.wechat.VolumeSearchSummaryVO">
    2. SELECT
    3. count(vl.id) as "count",
    4. sum(vl.weight) as "weight",
    5. sum(vl.length) as "length",
    6. vl.type,
    7. vl.width,
    8. vl.thickness,
    9. vl.thickness2,
    10. vl.material,
    11. vl.origin_str originStr,
    12. vl.stock_name stockName,
    13. vl.color,
    14. max(vl.sell_price) maxPrice,
    15. min(vl.sell_price) minPrice
    16. FROM vender_volume vl
    17. LEFT JOIN vender v on (vl.vender_id = v.id)
    18. LEFT JOIN vender_config vc on (vl.vender_id = vc.vender_id)
    19. WHERE
    20. vl.deleted = 0
    21. AND vl.status = 2
    22. AND v.id = #{venderId}
    23. AND vc.board_open = true
    24. -- AND (vl.weight > 0 or vl.original_weight > 0)
    25. AND vl.product_id = #{productId}
    26. <if test="type != null">
    27. AND `type` = #{type}
    28. </if>
    29. <if test="width != null">
    30. AND `width` = #{width}
    31. </if>
    32. <include refid="WidthArrQuery"></include>
    33. <include refid="ThicknessQuery"></include>
    34. <include refid="WeightQuery"></include>
    35. <include refid="materialQuery"></include>
    36. <include refid="VenderQuery"></include>
    37. GROUP BY vl.type, vl.width, vl.thickness, vl.thickness2
    38. <if test="productId == 4">
    39. ,vl.color
    40. </if>
    41. <if test="productId != 1 and productId != 8">
    42. ,vl.material
    43. </if>
    44. ORDER BY vl.width,vl.thickness asc
    45. limit #{pageNo}, #{pageSize}
    46. </select>
    涉及的表
    vender_volume
    vender
    vender_config

    5

    这个代码在jeecgboot上

    https://irendui.com/v1/jec/rendui/prices/dailyByProductSpec?productSpec=1457211726671400962_1000_0.11_%E5%BD%A9%E5%9F%BA%E9%95%80%E9%94%8C&date=2022-07-04%2000:00:00&siteId=1457210664971423746&

    postman 测试

    1. {
    2. "success": true,
    3. "message": "",
    4. "code": 200,
    5. "result": {
    6. "priceMax": 5210.0,
    7. "priceGroupId": 4411,
    8. "thickness": "0.11",
    9. "lastpriceTax": 5660.0,
    10. "type": "彩基镀锌 0.11*1000",
    11. "delFlag": "0",
    12. "priceMin": 5200.0,
    13. "createdAt": 1656891000000,
    14. "updateBy": "9954",
    15. "price": 5210.0,
    16. "id": 424735,
    17. "priceSum": 10410.0,
    18. "lastprice": 5210.0,
    19. "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
    20. "timestamp": 1656864000000,
    21. "updatedAt": 1656891000000,
    22. "priceMaxTax": 5660.0,
    23. "updateTime": 1656890875697,
    24. "createBy": "9954",
    25. "lasttime": 1656891000000,
    26. "material": "彩基镀锌",
    27. "createTime": 1656890875697,
    28. "width": "1000",
    29. "siteId": "1457210664971423746",
    30. "priceTax": 5660.0,
    31. "priceCount": 2.0,
    32. "category": "镀锌",
    33. "categoryId": "1457211726671400962",
    34. "priceMinTax": 5650.0,
    35. "riseAndFall": -10.0,
    36. "riseAndFallTax": -10.0
    37. },
    38. "timestamp": 1656904441037
    39. }

     显示在小程序端

     controller层

    1. /**
    2. * 查询天维度价格统计(用于价格指数页面列表点开数据展示)
    3. * @param
    4. * @return
    5. */
    6. @AutoLog(value = "/prices/dailyByProductSpec")
    7. @ApiOperation(value = "/prices/dailyByProductSpec", notes = "/prices/dailyByProductSpec")
    8. @GetMapping(value = "/prices/dailyByProductSpec")
    9. public Result<?> statisticsPriceDailyByProductSpec(@RequestParam("siteId")String siteId,@RequestParam("productSpec")String productSpec, @RequestParam("date")String date) {
    10. return service.statisticsPriceDailyByProductSpec(productSpec, siteId, date);
    11. }

    service层

    1. @Override
    2. public Result<?> statisticsPriceDailyByProductSpec(String productSpec, String siteId, String date) {
    3. Document daily = renduiPriceDailyManager.queryByProductSpec(productSpec, siteId, date);
    4. if(daily == null) {
    5. return null;
    6. }
    7. Document yesterdayDaily = renduiPriceDailyManager.queryLastDataBy(productSpec, siteId, DateCommonUtil.getTDateZero(DateCommonUtil.getDateFromStr(date)).getTime());
    8. boolean isToday = DateCommonUtil.isToday(daily.getLong("updatedAt"));
    9. float beforePrice = new Float("0.00");
    10. float beforePriceTax = new Float("0.00");
    11. if (yesterdayDaily != null && yesterdayDaily.get("price") != null) {
    12. beforePrice = Float.parseFloat(yesterdayDaily.get("price").toString());
    13. beforePriceTax = Float.parseFloat(yesterdayDaily.get("priceTax").toString());
    14. }
    15. float currentPrice = getPriceByField(daily, "price");
    16. float currentPriceTax = getPriceByField(daily, "priceTax");
    17. if (isToday) {
    18. currentPrice = getPriceByField(daily, "lastprice");
    19. currentPriceTax = getPriceByField(daily, "lastpriceTax");
    20. }
    21. Float riseAndFall = getRiseAndFall(currentPrice , beforePrice);
    22. Float riseAndFallTax = getRiseAndFall(currentPriceTax , beforePriceTax);
    23. daily.put("riseAndFall", riseAndFall);
    24. daily.put("riseAndFallTax", riseAndFallTax);
    25. return Result.OK(daily);
    26. }

    manager层

    1. public List<Document> queryByProductSpec(String productSpec, String siteId, long from, long to) {
    2. MongoCollection<Document> collection = mongoDatabase.getCollection(TABLE_NAME);
    3. Document document = new Document();
    4. DBObject dbObject = new BasicDBObject();
    5. dbObject.put("$gte", from);
    6. dbObject.put("$lt", to);
    7. Document sort = new Document();
    8. sort.put("id",-1);
    9. document.put("productSpec", productSpec);
    10. document.put("siteId", siteId);
    11. document.put("timestamp",dbObject);
    12. FindIterable<Document> findIterable = collection.find(document).sort(sort);
    13. MongoCursor<Document> mongoCursor = findIterable.iterator();
    14. List<Document> documentList = new ArrayList<>();
    15. while (mongoCursor.hasNext()) {
    16. Document doc = mongoCursor.next();
    17. doc.remove("_id");
    18. documentList.add(doc);
    19. }
    20. return documentList;
    21. }

    操控的表为

    rendui_price_daily

    7.

    https://irendui.com/v1/jec/rendui/prices/statistics?siteId=1457210664971423746&productSpec=1457211726671400962_1000_0.11_%E5%BD%A9%E5%9F%BA%E9%95%80%E9%94%8C&from=2022-07-04%2009:00:00&to=2022-07-04%2009:46:51&

    postman测试

    结果:

    1. {
    2. "success": true,
    3. "message": "",
    4. "code": 200,
    5. "result": [
    6. {
    7. "id": 22096588,
    8. "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
    9. "satisticsTime": null,
    10. "timestamp": 1656891000000,
    11. "price": 5210.0,
    12. "priceTax": 5660.0,
    13. "siteId": "1457210664971423746",
    14. "categoryId": "1457211726671400962"
    15. },
    16. {
    17. "id": 22096588,
    18. "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
    19. "satisticsTime": null,
    20. "timestamp": 1656891000000,
    21. "price": 5210.0,
    22. "priceTax": 5660.0,
    23. "siteId": "1457210664971423746",
    24. "categoryId": "1457211726671400962"
    25. },
    26. {
    27. "id": 22096588,
    28. "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
    29. "satisticsTime": null,
    30. "timestamp": 1656891000000,
    31. "price": 5210.0,
    32. "priceTax": 5660.0,
    33. "siteId": "1457210664971423746",
    34. "categoryId": "1457211726671400962"
    35. },
    36. {
    37. "id": 22096588,
    38. "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
    39. "satisticsTime": null,
    40. "timestamp": 1656891000000,
    41. "price": 5210.0,
    42. "priceTax": 5660.0,
    43. "siteId": "1457210664971423746",
    44. "categoryId": "1457211726671400962"
    45. },
    46. {
    47. "id": 22096588,
    48. "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
    49. "satisticsTime": null,
    50. "timestamp": 1656891000000,
    51. "price": 5210.0,
    52. "priceTax": 5660.0,
    53. "siteId": "1457210664971423746",
    54. "categoryId": "1457211726671400962"
    55. },
    56. {
    57. "id": 22096588,
    58. "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
    59. "satisticsTime": null,
    60. "timestamp": 1656891000000,
    61. "price": 5210.0,
    62. "priceTax": 5660.0,
    63. "siteId": "1457210664971423746",
    64. "categoryId": "1457211726671400962"
    65. },
    66. {
    67. "id": 22096588,
    68. "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
    69. "satisticsTime": null,
    70. "timestamp": 1656891000000,
    71. "price": 5210.0,
    72. "priceTax": 5660.0,
    73. "siteId": "1457210664971423746",
    74. "categoryId": "1457211726671400962"
    75. },
    76. {
    77. "id": 22096588,
    78. "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
    79. "satisticsTime": null,
    80. "timestamp": 1656891000000,
    81. "price": 5210.0,
    82. "priceTax": 5660.0,
    83. "siteId": "1457210664971423746",
    84. "categoryId": "1457211726671400962"
    85. },
    86. {
    87. "id": 22096588,
    88. "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
    89. "satisticsTime": null,
    90. "timestamp": 1656891000000,
    91. "price": 5210.0,
    92. "priceTax": 5660.0,
    93. "siteId": "1457210664971423746",
    94. "categoryId": "1457211726671400962"
    95. },
    96. {
    97. "id": 22096588,
    98. "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
    99. "satisticsTime": null,
    100. "timestamp": 1656891000000,
    101. "price": 5210.0,
    102. "priceTax": 5660.0,
    103. "siteId": "1457210664971423746",
    104. "categoryId": "1457211726671400962"
    105. }
    106. ],
    107. "timestamp": 1656913315693
    108. }

    小程序端显示:

    代码分析

    controller层

    1. /**
    2. * 查询分钟维度价格统计(曲线图的数据接口)
    3. * @param
    4. * @return
    5. */
    6. @AutoLog(value = "/prices/statistics")
    7. @ApiOperation(value = "/prices/statistics", notes = "/prices/statistics")
    8. @GetMapping(value = "/prices/statistics")
    9. public Result<?> statisticsPrice(@RequestParam(value = "productSpec") String productSpec, @RequestParam(value = "siteId")String siteId, @RequestParam(value = "from")String from, @RequestParam(value = "to")String to) {
    10. boolean fromBeforeTo = DateCommonUtil.getDateFromStr(from).before(DateCommonUtil.getDateFromStr(to));
    11. if(!fromBeforeTo){
    12. return Result.error("开始时间不能大于结束时间");
    13. }
    14. List<PriceStatisticsVO> result = service.statisticsPrice(productSpec, siteId, from, to);
    15. return Result.OK(result);
    16. }

     service层

    1. @Override
    2. public List<PriceStatisticsVO> statisticsPrice(String productSpec, String siteId, String from, String to) {
    3. long dateDiff = DateUtil.betweenDay(DateCommonUtil.getDateFromStr(from), DateCommonUtil.getDateFromStr(to), false);
    4. boolean isSameDay = DateUtil.isSameDay(DateCommonUtil.getDateFromStr(from), DateCommonUtil.getDateFromStr(to));
    5. if (dateDiff <= 0 && isSameDay) {
    6. return statisticsMinutely2(productSpec, siteId, from, to);
    7. } else {
    8. return statisticsDaily(productSpec, siteId, from, to, dateDiff);
    9. }
    10. }

     

    1. private List<PriceStatisticsVO> statisticsMinutely2(String productSpec, String siteId, String from, String to) {
    2. long FIVE_MINUTES = 5 * 60000;
    3. long fromTime = DateCommonUtil.getTimeFromStr(from);
    4. long toTime = DateCommonUtil.getTimeFromStr(to);
    5. List<Document> minutely = renduiPriceMinutelyManager.queryByProductSpec(productSpec, siteId, fromTime, toTime);
    6. List<PriceStatisticsVO> results = new ArrayList<>();
    7. long minuteDiff = DateUtil.between(DateCommonUtil.getDateFromStr(from), DateCommonUtil.getDateFromStr(to), DateUnit.MINUTE);
    8. int window = (int) minuteDiff / 5;
    9. // 如果为空
    10. if (minutely.size() == 0) {
    11. PriceStatisticsVO lastPrice = getLastPrice(productSpec, siteId, fromTime);
    12. long t = fromTime;
    13. while (t <= toTime) {
    14. PriceStatisticsVO p = new PriceStatisticsVO();
    15. BeanUtil.copyProperties(lastPrice, p);
    16. p.setTimestamp(t);
    17. results.add(lastPrice);
    18. t += 5 * 60000;
    19. }
    20. return results;
    21. }
    22. PriceStatisticsVO firstPrice = new PriceStatisticsVO();
    23. BeanUtil.copyProperties(minutely.get(0), firstPrice);
    24. // 补充左边的数据
    25. long fistTime = firstPrice.getTimestamp();
    26. PriceStatisticsVO formerPrice = null;
    27. if (fistTime > fromTime) {
    28. PriceStatisticsVO latestPrice = getLastPrice(productSpec, siteId, fromTime);
    29. long t = fromTime;
    30. int i = 0;
    31. while (t < fistTime) {
    32. PriceStatisticsVO p = new PriceStatisticsVO();
    33. BeanUtil.copyProperties(latestPrice, p);
    34. p.setTimestamp(t);
    35. results.add(p);
    36. formerPrice = p;
    37. i ++;
    38. t += FIVE_MINUTES;
    39. }
    40. }
    41. // 补充中间数据
    42. for (int i = 0; i < minutely.size(); i ++) {
    43. Document m = minutely.get(i);
    44. PriceStatisticsVO price = new PriceStatisticsVO();
    45. BeanUtil.copyProperties(m, price);
    46. // 补充中间数据
    47. if (formerPrice != null && price.getTimestamp() - formerPrice.getTimestamp() > FIVE_MINUTES) {
    48. long t = formerPrice.getTimestamp() + FIVE_MINUTES;
    49. while ( t < price.getTimestamp()) {
    50. PriceStatisticsVO p = new PriceStatisticsVO();
    51. BeanUtil.copyProperties(formerPrice, p);
    52. p.setTimestamp(t);
    53. results.add(p);
    54. t += FIVE_MINUTES;
    55. }
    56. }
    57. results.add(price);
    58. formerPrice = price;
    59. }
    60. if (formerPrice != null && formerPrice.getTimestamp() < toTime) {
    61. long t = formerPrice.getTimestamp() + FIVE_MINUTES;
    62. while ( t < toTime) {
    63. PriceStatisticsVO p = new PriceStatisticsVO();
    64. BeanUtil.copyProperties(formerPrice, p);
    65. p.setTimestamp(t);
    66. results.add(p);
    67. t += FIVE_MINUTES;
    68. }
    69. }
    70. return results;
    71. }
    1. private List<PriceStatisticsVO> statisticsDaily(String productSpec, String siteId, String from, String to, long dateDiff) {
    2. List<PriceStatisticsVO> result = new ArrayList<>();
    3. //按天统计
    4. long fromTime = 0;
    5. for (int i = 0; i < dateDiff + 1; i++) {
    6. if (i == 0) {
    7. fromTime = DateCommonUtil.getTimeFromStr(from);
    8. }
    9. long toTime = DateCommonUtil.dayAfterInterval(DateCommonUtil.dateFromTimestamp(fromTime), 1).getTime();
    10. List<Document> daily = renduiPriceDailyManager.queryByProductSpec(productSpec, siteId, fromTime, toTime);
    11. PriceStatisticsVO statisticsVO = new PriceStatisticsVO();
    12. statisticsVO.setProductSpec(productSpec);
    13. statisticsVO.setPrice(Float.valueOf("0.00"));
    14. statisticsVO.setPriceTax(Float.valueOf("0.00"));
    15. statisticsVO.setSatisticsTime(DateCommonUtil.strFromTimestamp(fromTime));
    16. if (CollectionUtil.isEmpty(daily)) {
    17. setDailyEmptyVal(productSpec, siteId, fromTime, i, statisticsVO);
    18. } else {
    19. BeanUtil.copyProperties(daily.get(daily.size() - 1), statisticsVO);
    20. }
    21. fromTime = toTime;
    22. result.add(statisticsVO);
    23. }
    24. for (int i = 0; i < result.size(); i++) {
    25. //将空值替换为上个周期的数据 ,因为前面保证了第一条数据一定有值所以不会出现数组越界问题
    26. if (result.get(i).getProductSpec() != null && result.get(i).getProductSpec().equals(EMPTY_MARK)) {
    27. PriceStatisticsVO statisticsVO = getNotEmptyOne(i - 1, result);
    28. String statisticTime = result.get(i).getSatisticsTime();
    29. BeanUtil.copyProperties(statisticsVO, result.get(i));
    30. result.get(i).setSatisticsTime(statisticTime);
    31. }
    32. }
    33. return result;
    34. }
    1. private List<PriceStatisticsVO> statisticsDaily(String productSpec, String siteId, String from, String to, long dateDiff) {
    2. List<PriceStatisticsVO> result = new ArrayList<>();
    3. //按天统计
    4. long fromTime = 0;
    5. for (int i = 0; i < dateDiff + 1; i++) {
    6. if (i == 0) {
    7. fromTime = DateCommonUtil.getTimeFromStr(from);
    8. }
    9. long toTime = DateCommonUtil.dayAfterInterval(DateCommonUtil.dateFromTimestamp(fromTime), 1).getTime();
    10. List<Document> daily = renduiPriceDailyManager.queryByProductSpec(productSpec, siteId, fromTime, toTime);
    11. PriceStatisticsVO statisticsVO = new PriceStatisticsVO();
    12. statisticsVO.setProductSpec(productSpec);
    13. statisticsVO.setPrice(Float.valueOf("0.00"));
    14. statisticsVO.setPriceTax(Float.valueOf("0.00"));
    15. statisticsVO.setSatisticsTime(DateCommonUtil.strFromTimestamp(fromTime));
    16. if (CollectionUtil.isEmpty(daily)) {
    17. setDailyEmptyVal(productSpec, siteId, fromTime, i, statisticsVO);
    18. } else {
    19. BeanUtil.copyProperties(daily.get(daily.size() - 1), statisticsVO);
    20. }
    21. fromTime = toTime;
    22. result.add(statisticsVO);
    23. }
    24. for (int i = 0; i < result.size(); i++) {
    25. //将空值替换为上个周期的数据 ,因为前面保证了第一条数据一定有值所以不会出现数组越界问题
    26. if (result.get(i).getProductSpec() != null && result.get(i).getProductSpec().equals(EMPTY_MARK)) {
    27. PriceStatisticsVO statisticsVO = getNotEmptyOne(i - 1, result);
    28. String statisticTime = result.get(i).getSatisticsTime();
    29. BeanUtil.copyProperties(statisticsVO, result.get(i));
    30. result.get(i).setSatisticsTime(statisticTime);
    31. }
    32. }
    33. return result;
    34. }

    manager层

    1. public List<Document> queryByProductSpec(String productSpec, String siteId, long from, long to) {
    2. MongoCollection<Document> collection = mongoDatabase.getCollection(TABLE_NAME);
    3. Document document = new Document();
    4. DBObject dbObject = new BasicDBObject();
    5. dbObject.put("$gte", from);
    6. dbObject.put("$lt", to);
    7. Document sort = new Document();
    8. sort.put("id",-1);
    9. document.put("productSpec", productSpec);
    10. document.put("siteId", siteId);
    11. document.put("timestamp",dbObject);
    12. FindIterable<Document> findIterable = collection.find(document).sort(sort);
    13. MongoCursor<Document> mongoCursor = findIterable.iterator();
    14. List<Document> documentList = new ArrayList<>();
    15. while (mongoCursor.hasNext()) {
    16. Document doc = mongoCursor.next();
    17. doc.remove("_id");
    18. documentList.add(doc);
    19. }
    20. return documentList;
    21. }

    涉及的表:rendui_price_daily

  • 相关阅读:
    「git 系列」git 如何存储代码的?
    ExcelBDD Python指南
    Failed to start mysql.service Unit mysql.service not found
    Android Studio 生成开发库并打包maven包上传到私有服务器使用
    计算机网络学习三(以太网基本概念)
    HTTP原理入门
    【HarmonyOS】元服务卡片展示动态数据,并定点更新卡片数据
    3D视觉——3.人体姿态估计(Pose Estimation) 算法对比 即 效果展示——MediaPipe与OpenPose
    lombok插件各个注解介绍
    创建n维空间每个维度(轴)的刻度值numpy.ogrid[]
  • 原文地址:https://blog.csdn.net/weixin_44021708/article/details/125593982