1.
https://irendui.com/v1/users/17364/rights
2.
3.
4.
5.
7.
8.
9.
库存搜索接口
https://irendui.com/v1/market/volume/search?widthList=1000&productId=1&thickness=0.11&pageNo=1&pageSize=10&
结果:
- {
- "errno": 0,
- "data": [
- {
- "count": 12,
- "weight": 63.448,
- "length": 76654.0,
- "id": 301,
- "name": "山东聚德鑫新型建材有限公司",
- "legalRepName": "李超",
- "legalRepPhone": null,
- "imgUrl": null,
- "updateTime": "2022-07-03 15:10:54",
- "material": null
- },
- {
- "count": 13,
- "weight": 61.090,
- "length": 73008.0,
- "id": 283,
- "name": "山东修堂新型材料有限公司",
- "legalRepName": "刘娟",
- "legalRepPhone": null,
- "imgUrl": null,
- "updateTime": "2022-07-03 14:48:04",
- "material": null
- },
- {
- "count": 10,
- "weight": 53.136,
- "length": 63726.0,
- "id": 265,
- "name": "博兴县盛凯钢铁有限公司",
- "legalRepName": "魏鲁传",
- "legalRepPhone": null,
- "imgUrl": null,
- "updateTime": "2022-06-25 09:37:35",
- "material": null
- },
- {
- "count": 3,
- "weight": 12.246,
- "length": 14749.0,
- "id": 258,
- "name": "山东泰达板业有限公司",
- "legalRepName": "赵海",
- "legalRepPhone": null,
- "imgUrl": null,
- "updateTime": "2022-06-22 11:36:34",
- "material": null
- },
- {
- "count": 24,
- "weight": 144.600,
- "length": 177606.0,
- "id": 453,
- "name": "博兴县佳兴钢铁经营部",
- "legalRepName": "纪金丽",
- "legalRepPhone": null,
- "imgUrl": null,
- "updateTime": "2022-04-08 14:17:10",
- "material": null
- }
- ],
- "errmsg": "成功"
- }
对应在小程序端的 推荐库存的数据
controller层
- @TenantFilter(filter = true)
- @ApiOperation("库存搜索接口")
- @GetMapping("volume/search")
- public Object SearchVolumes(@RequestHeader(value = "phone",required = false) String phone,
- @RequestHeader(value = "venderId",required = false) Integer loginVendorId,
- @RequestHeader(value = "venderStaffId",required = false) Integer venderStaffId,
- @RequestParam Integer productId,
- @RequestParam(required = false) Integer type,
- @RequestParam(required = false) Double width,
- @RequestParam(required = false) String widthList,
- @RequestParam(required = false) Double thickness,
- @RequestParam(required = false) Double thickness2,
- @RequestParam(required = false) Double weight,
- @RequestParam(required = false) Double weight2,
- @RequestParam(required = false)String material,
- @RequestParam(required = false) Integer venderId,
- @RequestParam(required = false) String venderName,
- @RequestParam(defaultValue = "1") Integer pageNo,
- @RequestParam(defaultValue = "20") Integer pageSize) {
- return ResponseUtil.ok(
- volumeService.vendorVolumeSearch(
- productId, type, width, widthList,
- thickness, thickness2,
- weight, weight2,material,venderId,venderName,
- (pageNo - 1) * pageSize, pageSize));
- }
前端传来了5个参数
- @TenantFilter(filter = true)
- @ApiOperation("库存搜索接口")
- @GetMapping("volume/search")
- public Object SearchVolumes(@RequestHeader(value = "phone",required = false) String phone,
- @RequestHeader(value = "venderId",required = false) Integer loginVendorId,
- @RequestHeader(value = "venderStaffId",required = false) Integer venderStaffId,
- @RequestParam Integer productId,
- @RequestParam(required = false) Integer type,
- @RequestParam(required = false) Double width,
- @RequestParam(required = false) String widthList,
- @RequestParam(required = false) Double thickness,
- @RequestParam(required = false) Double thickness2,
- @RequestParam(required = false) Double weight,
- @RequestParam(required = false) Double weight2,
- @RequestParam(required = false)String material,
- @RequestParam(required = false) Integer venderId,
- @RequestParam(required = false) String venderName,
- @RequestParam(defaultValue = "1") Integer pageNo,
- @RequestParam(defaultValue = "20") Integer pageSize) {
- return ResponseUtil.ok(
- volumeService.vendorVolumeSearch(
- productId, type, width, widthList,
- thickness, thickness2,
- weight, weight2,material,venderId,venderName,
- (pageNo - 1) * pageSize, pageSize));
- }
service层
- @Override
- public List<VolumeSearchVO> vendorVolumeSearch(
- Integer productId, Integer type,
- Double width, String widthList,
- Double thickness, Double thickness2,
- Double weight, Double weight2, String material,
- Integer venderId,String venderName,
- Integer pageNo, Integer pageSize) {
- if (thickness == null || thickness2 == null) {
- thickness = thickness2 = thickness != null?thickness : thickness2;
- }
-
- if (weight == null || weight2 == null) {
- weight = weight2 = weight != null?weight : weight2;
- }
-
- String[] widthArr = null;
- if (StringUtils.isNotBlank(widthList)) {
- widthArr = StringUtils.split(widthList, ",");
- }
- List<String> materialList = new ArrayList<>();
- if (StringUtils.isNotBlank(material)) {
- materialList = Arrays.asList(material.replace(" ", "").split(","));
- }
-
- return volumeMapper.vendorVolumeSearch(
- productId, type,
- width, widthArr,
- thickness, thickness2,
- weight, weight2, materialList,venderId,venderName,
- pageNo, pageSize);
- }
mapper层
public interface VenderVolumeMapper extends BaseMapper<VenderVolume> {
mapper.xml
- <select id="vendorVolumeSearch" resultType="com.ruopu.tomfox.dao.vo.wechat.VolumeSearchVO">
- SELECT
- count(vl.id) as count,
- sum(vl.weight) as weight,
- sum(vl.length) as length,
- if(vu.update_time is not null, vu.update_time, "2020-09-01 00:00:00") as update_time,
- v.id, v.name, v.legal_rep_name, v.legal_rep_phone, v.img_url, vl.material
- FROM vender_volume vl
- LEFT JOIN vender v on (vl.vender_id = v.id)
- LEFT JOIN vender_config vc on (vl.vender_id = vc.vender_id)
- LEFT JOIN vender_volume_update vu on (vl.vender_id = vu.vender_id)
- WHERE
- vl.deleted = 0
- AND vl.status = 2
- AND vc.board_open = true
- -- AND (vl.weight > 0 or vl.original_weight > 0) --20211213BUG 后端上传热卷 轧硬在小程序没办法显示 因为新的模板没有这个限制
- AND vl.product_id = #{productId}
- <if test="type != null">
- AND `type` = #{type}
- </if>
- <if test="width != null">
- AND `width` = #{width}
- </if>
- <include refid="WidthArrQuery"></include>
- <include refid="ThicknessQuery"></include>
- <include refid="WeightQuery"></include>
- <include refid="materialQuery"></include>
- <include refid="VenderQuery"></include>
- GROUP BY v.id, v.name, v.legal_rep_name, v.legal_rep_phone, v.img_url
- ORDER BY update_time desc,count desc
- limit #{pageNo}, #{pageSize}
- </select>
涉及的表 四张
vender_volume
vender
vender_config
vender_volume_update
https://irendui.com/v1/market/vender/volume/summary?widthList=1000&productId=1&thickness=0.11&pageNo=1&pageSize=10&venderId=301&
库存搜索接口
postman测试
结果
- {
- "errno": 0,
- "data": [
- {
- "count": 12,
- "weight": 63.448,
- "length": 76654.0,
- "width": 1000.0,
- "thickness": 0.11,
- "thickness2": 0.0,
- "type": 1,
- "material": null,
- "color": null,
- "price": null,
- "maxPrice": 0.00,
- "minPrice": 0.00,
- "originStr": "宏盛达",
- "stockName": "宏盛达"
- }
- ],
- "errmsg": "成功"
- }
对应在小程序的数据为 推荐库存下的详细规格
这些信息
controller层
- @TenantFilter(filter = true)
- @ApiOperation("库存搜索接口")
- @GetMapping("/vender/volume/summary")
- public Object SearchVolumesSummary(
- @RequestHeader(value = "phone",required = false) String phone,
- @RequestHeader(value = "venderId",required = false) Integer loginVendorId,
- @RequestHeader(value = "venderStaffId",required = false) Integer venderStaffId,
- @RequestParam Integer productId,
- @RequestParam(required = false) Integer type,
- @RequestParam(required = false) Double width,
- @RequestParam(required = false) String widthList,
- @RequestParam(required = false) Double thickness,
- @RequestParam(required = false) Double thickness2,
- @RequestParam(required = false) Double weight,
- @RequestParam(required = false) Double weight2,
- @RequestParam(required = false) Integer venderId,
- @RequestParam(required = false) String venderName,
- @RequestParam(required = false)String material,
- @RequestParam(defaultValue = "1") Integer pageNo,
- @RequestParam(defaultValue = "20") Integer pageSize) {
-
- return ResponseUtil.ok(volumeService.vendorVolumeSearchSummary(
- venderId, productId, type,
- width, widthList,
- thickness, thickness2,
- weight, weight2, material,venderName,
- (pageNo - 1) * pageSize, pageSize));
-
- }
service层
- @Override
- public List<VolumeSearchSummaryVO> vendorVolumeSearchSummary(
- Integer venderId, Integer productId, Integer type,
- Double width, String widthList,
- Double thickness, Double thickness2,
- Double weight, Double weight2, String material,String venderName,
- Integer pageNo, Integer pageSize) {
- if (thickness == null || thickness2 == null) {
- thickness = thickness2 = thickness != null?thickness : thickness2;
- }
-
- if (weight == null || weight2 == null) {
- weight = weight2 = weight != null?weight : weight2;
- }
-
- String[] widthArr = null;
- if (StringUtils.isNotBlank(widthList)) {
- widthArr = StringUtils.split(widthList, ",");
- }
- List<String> materialList = new ArrayList<>();
- if (StringUtils.isNotBlank(material)) {
- materialList = Arrays.asList(material.replace(" ", "").split(","));
- }
-
- return volumeMapper.vendorVolumeSearchSummary(
- venderId, productId, type,
- width, widthArr,
- thickness, thickness2,
- weight, weight2, materialList,venderName,
- pageNo, pageSize);
- }
- <select id="vendorVolumeSearchSummary" resultType="com.ruopu.tomfox.dao.vo.wechat.VolumeSearchSummaryVO">
- SELECT
- count(vl.id) as "count",
- sum(vl.weight) as "weight",
- sum(vl.length) as "length",
- vl.type,
- vl.width,
- vl.thickness,
- vl.thickness2,
- vl.material,
- vl.origin_str originStr,
- vl.stock_name stockName,
- vl.color,
- max(vl.sell_price) maxPrice,
- min(vl.sell_price) minPrice
- FROM vender_volume vl
- LEFT JOIN vender v on (vl.vender_id = v.id)
- LEFT JOIN vender_config vc on (vl.vender_id = vc.vender_id)
- WHERE
- vl.deleted = 0
- AND vl.status = 2
- AND v.id = #{venderId}
- AND vc.board_open = true
- -- AND (vl.weight > 0 or vl.original_weight > 0)
- AND vl.product_id = #{productId}
- <if test="type != null">
- AND `type` = #{type}
- </if>
- <if test="width != null">
- AND `width` = #{width}
- </if>
- <include refid="WidthArrQuery"></include>
- <include refid="ThicknessQuery"></include>
- <include refid="WeightQuery"></include>
- <include refid="materialQuery"></include>
- <include refid="VenderQuery"></include>
- GROUP BY vl.type, vl.width, vl.thickness, vl.thickness2
- <if test="productId == 4">
- ,vl.color
- </if>
- <if test="productId != 1 and productId != 8">
- ,vl.material
- </if>
- ORDER BY vl.width,vl.thickness asc
- limit #{pageNo}, #{pageSize}
- </select>
涉及的表 vender_volume
vender
vender_config
这个代码在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 测试
- {
- "success": true,
- "message": "",
- "code": 200,
- "result": {
- "priceMax": 5210.0,
- "priceGroupId": 4411,
- "thickness": "0.11",
- "lastpriceTax": 5660.0,
- "type": "彩基镀锌 0.11*1000",
- "delFlag": "0",
- "priceMin": 5200.0,
- "createdAt": 1656891000000,
- "updateBy": "9954",
- "price": 5210.0,
- "id": 424735,
- "priceSum": 10410.0,
- "lastprice": 5210.0,
- "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
- "timestamp": 1656864000000,
- "updatedAt": 1656891000000,
- "priceMaxTax": 5660.0,
- "updateTime": 1656890875697,
- "createBy": "9954",
- "lasttime": 1656891000000,
- "material": "彩基镀锌",
- "createTime": 1656890875697,
- "width": "1000",
- "siteId": "1457210664971423746",
- "priceTax": 5660.0,
- "priceCount": 2.0,
- "category": "镀锌",
- "categoryId": "1457211726671400962",
- "priceMinTax": 5650.0,
- "riseAndFall": -10.0,
- "riseAndFallTax": -10.0
- },
- "timestamp": 1656904441037
- }
显示在小程序端
controller层
- /**
- * 查询天维度价格统计(用于价格指数页面列表点开数据展示)
- * @param
- * @return
- */
- @AutoLog(value = "/prices/dailyByProductSpec")
- @ApiOperation(value = "/prices/dailyByProductSpec", notes = "/prices/dailyByProductSpec")
- @GetMapping(value = "/prices/dailyByProductSpec")
- public Result<?> statisticsPriceDailyByProductSpec(@RequestParam("siteId")String siteId,@RequestParam("productSpec")String productSpec, @RequestParam("date")String date) {
- return service.statisticsPriceDailyByProductSpec(productSpec, siteId, date);
- }
service层
- @Override
- public Result<?> statisticsPriceDailyByProductSpec(String productSpec, String siteId, String date) {
- Document daily = renduiPriceDailyManager.queryByProductSpec(productSpec, siteId, date);
- if(daily == null) {
- return null;
- }
- Document yesterdayDaily = renduiPriceDailyManager.queryLastDataBy(productSpec, siteId, DateCommonUtil.getTDateZero(DateCommonUtil.getDateFromStr(date)).getTime());
- boolean isToday = DateCommonUtil.isToday(daily.getLong("updatedAt"));
- float beforePrice = new Float("0.00");
- float beforePriceTax = new Float("0.00");
- if (yesterdayDaily != null && yesterdayDaily.get("price") != null) {
- beforePrice = Float.parseFloat(yesterdayDaily.get("price").toString());
- beforePriceTax = Float.parseFloat(yesterdayDaily.get("priceTax").toString());
- }
- float currentPrice = getPriceByField(daily, "price");
- float currentPriceTax = getPriceByField(daily, "priceTax");
- if (isToday) {
- currentPrice = getPriceByField(daily, "lastprice");
- currentPriceTax = getPriceByField(daily, "lastpriceTax");
- }
- Float riseAndFall = getRiseAndFall(currentPrice , beforePrice);
- Float riseAndFallTax = getRiseAndFall(currentPriceTax , beforePriceTax);
- daily.put("riseAndFall", riseAndFall);
- daily.put("riseAndFallTax", riseAndFallTax);
- return Result.OK(daily);
- }
manager层
- public List<Document> queryByProductSpec(String productSpec, String siteId, long from, long to) {
- MongoCollection<Document> collection = mongoDatabase.getCollection(TABLE_NAME);
-
- Document document = new Document();
-
- DBObject dbObject = new BasicDBObject();
- dbObject.put("$gte", from);
- dbObject.put("$lt", to);
- Document sort = new Document();
- sort.put("id",-1);
- document.put("productSpec", productSpec);
- document.put("siteId", siteId);
- document.put("timestamp",dbObject);
- FindIterable<Document> findIterable = collection.find(document).sort(sort);
- MongoCursor<Document> mongoCursor = findIterable.iterator();
- List<Document> documentList = new ArrayList<>();
- while (mongoCursor.hasNext()) {
- Document doc = mongoCursor.next();
- doc.remove("_id");
- documentList.add(doc);
- }
- return documentList;
- }
操控的表为
rendui_price_daily
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测试
结果:
- {
- "success": true,
- "message": "",
- "code": 200,
- "result": [
- {
- "id": 22096588,
- "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
- "satisticsTime": null,
- "timestamp": 1656891000000,
- "price": 5210.0,
- "priceTax": 5660.0,
- "siteId": "1457210664971423746",
- "categoryId": "1457211726671400962"
- },
- {
- "id": 22096588,
- "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
- "satisticsTime": null,
- "timestamp": 1656891000000,
- "price": 5210.0,
- "priceTax": 5660.0,
- "siteId": "1457210664971423746",
- "categoryId": "1457211726671400962"
- },
- {
- "id": 22096588,
- "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
- "satisticsTime": null,
- "timestamp": 1656891000000,
- "price": 5210.0,
- "priceTax": 5660.0,
- "siteId": "1457210664971423746",
- "categoryId": "1457211726671400962"
- },
- {
- "id": 22096588,
- "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
- "satisticsTime": null,
- "timestamp": 1656891000000,
- "price": 5210.0,
- "priceTax": 5660.0,
- "siteId": "1457210664971423746",
- "categoryId": "1457211726671400962"
- },
- {
- "id": 22096588,
- "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
- "satisticsTime": null,
- "timestamp": 1656891000000,
- "price": 5210.0,
- "priceTax": 5660.0,
- "siteId": "1457210664971423746",
- "categoryId": "1457211726671400962"
- },
- {
- "id": 22096588,
- "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
- "satisticsTime": null,
- "timestamp": 1656891000000,
- "price": 5210.0,
- "priceTax": 5660.0,
- "siteId": "1457210664971423746",
- "categoryId": "1457211726671400962"
- },
- {
- "id": 22096588,
- "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
- "satisticsTime": null,
- "timestamp": 1656891000000,
- "price": 5210.0,
- "priceTax": 5660.0,
- "siteId": "1457210664971423746",
- "categoryId": "1457211726671400962"
- },
- {
- "id": 22096588,
- "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
- "satisticsTime": null,
- "timestamp": 1656891000000,
- "price": 5210.0,
- "priceTax": 5660.0,
- "siteId": "1457210664971423746",
- "categoryId": "1457211726671400962"
- },
- {
- "id": 22096588,
- "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
- "satisticsTime": null,
- "timestamp": 1656891000000,
- "price": 5210.0,
- "priceTax": 5660.0,
- "siteId": "1457210664971423746",
- "categoryId": "1457211726671400962"
- },
- {
- "id": 22096588,
- "productSpec": "1457211726671400962_1000_0.11_彩基镀锌",
- "satisticsTime": null,
- "timestamp": 1656891000000,
- "price": 5210.0,
- "priceTax": 5660.0,
- "siteId": "1457210664971423746",
- "categoryId": "1457211726671400962"
- }
- ],
- "timestamp": 1656913315693
- }
小程序端显示:
代码分析
controller层
- /**
- * 查询分钟维度价格统计(曲线图的数据接口)
- * @param
- * @return
- */
- @AutoLog(value = "/prices/statistics")
- @ApiOperation(value = "/prices/statistics", notes = "/prices/statistics")
- @GetMapping(value = "/prices/statistics")
- public Result<?> statisticsPrice(@RequestParam(value = "productSpec") String productSpec, @RequestParam(value = "siteId")String siteId, @RequestParam(value = "from")String from, @RequestParam(value = "to")String to) {
- boolean fromBeforeTo = DateCommonUtil.getDateFromStr(from).before(DateCommonUtil.getDateFromStr(to));
- if(!fromBeforeTo){
- return Result.error("开始时间不能大于结束时间");
- }
- List<PriceStatisticsVO> result = service.statisticsPrice(productSpec, siteId, from, to);
- return Result.OK(result);
- }
service层
- @Override
- public List<PriceStatisticsVO> statisticsPrice(String productSpec, String siteId, String from, String to) {
- long dateDiff = DateUtil.betweenDay(DateCommonUtil.getDateFromStr(from), DateCommonUtil.getDateFromStr(to), false);
- boolean isSameDay = DateUtil.isSameDay(DateCommonUtil.getDateFromStr(from), DateCommonUtil.getDateFromStr(to));
- if (dateDiff <= 0 && isSameDay) {
- return statisticsMinutely2(productSpec, siteId, from, to);
- } else {
- return statisticsDaily(productSpec, siteId, from, to, dateDiff);
- }
- }
- private List<PriceStatisticsVO> statisticsMinutely2(String productSpec, String siteId, String from, String to) {
- long FIVE_MINUTES = 5 * 60000;
- long fromTime = DateCommonUtil.getTimeFromStr(from);
- long toTime = DateCommonUtil.getTimeFromStr(to);
- List<Document> minutely = renduiPriceMinutelyManager.queryByProductSpec(productSpec, siteId, fromTime, toTime);
- List<PriceStatisticsVO> results = new ArrayList<>();
- long minuteDiff = DateUtil.between(DateCommonUtil.getDateFromStr(from), DateCommonUtil.getDateFromStr(to), DateUnit.MINUTE);
- int window = (int) minuteDiff / 5;
- // 如果为空
- if (minutely.size() == 0) {
- PriceStatisticsVO lastPrice = getLastPrice(productSpec, siteId, fromTime);
- long t = fromTime;
- while (t <= toTime) {
- PriceStatisticsVO p = new PriceStatisticsVO();
- BeanUtil.copyProperties(lastPrice, p);
- p.setTimestamp(t);
- results.add(lastPrice);
- t += 5 * 60000;
- }
- return results;
- }
-
- PriceStatisticsVO firstPrice = new PriceStatisticsVO();
- BeanUtil.copyProperties(minutely.get(0), firstPrice);
- // 补充左边的数据
- long fistTime = firstPrice.getTimestamp();
- PriceStatisticsVO formerPrice = null;
- if (fistTime > fromTime) {
- PriceStatisticsVO latestPrice = getLastPrice(productSpec, siteId, fromTime);
- long t = fromTime;
- int i = 0;
- while (t < fistTime) {
- PriceStatisticsVO p = new PriceStatisticsVO();
- BeanUtil.copyProperties(latestPrice, p);
- p.setTimestamp(t);
-
- results.add(p);
- formerPrice = p;
- i ++;
- t += FIVE_MINUTES;
- }
- }
-
- // 补充中间数据
-
- for (int i = 0; i < minutely.size(); i ++) {
- Document m = minutely.get(i);
- PriceStatisticsVO price = new PriceStatisticsVO();
- BeanUtil.copyProperties(m, price);
- // 补充中间数据
- if (formerPrice != null && price.getTimestamp() - formerPrice.getTimestamp() > FIVE_MINUTES) {
- long t = formerPrice.getTimestamp() + FIVE_MINUTES;
- while ( t < price.getTimestamp()) {
- PriceStatisticsVO p = new PriceStatisticsVO();
- BeanUtil.copyProperties(formerPrice, p);
- p.setTimestamp(t);
- results.add(p);
- t += FIVE_MINUTES;
- }
- }
- results.add(price);
- formerPrice = price;
- }
-
- if (formerPrice != null && formerPrice.getTimestamp() < toTime) {
- long t = formerPrice.getTimestamp() + FIVE_MINUTES;
- while ( t < toTime) {
- PriceStatisticsVO p = new PriceStatisticsVO();
- BeanUtil.copyProperties(formerPrice, p);
- p.setTimestamp(t);
- results.add(p);
- t += FIVE_MINUTES;
- }
- }
-
- return results;
- }
- private List<PriceStatisticsVO> statisticsDaily(String productSpec, String siteId, String from, String to, long dateDiff) {
- List<PriceStatisticsVO> result = new ArrayList<>();
- //按天统计
- long fromTime = 0;
- for (int i = 0; i < dateDiff + 1; i++) {
- if (i == 0) {
- fromTime = DateCommonUtil.getTimeFromStr(from);
- }
- long toTime = DateCommonUtil.dayAfterInterval(DateCommonUtil.dateFromTimestamp(fromTime), 1).getTime();
- List<Document> daily = renduiPriceDailyManager.queryByProductSpec(productSpec, siteId, fromTime, toTime);
- PriceStatisticsVO statisticsVO = new PriceStatisticsVO();
- statisticsVO.setProductSpec(productSpec);
- statisticsVO.setPrice(Float.valueOf("0.00"));
- statisticsVO.setPriceTax(Float.valueOf("0.00"));
- statisticsVO.setSatisticsTime(DateCommonUtil.strFromTimestamp(fromTime));
- if (CollectionUtil.isEmpty(daily)) {
- setDailyEmptyVal(productSpec, siteId, fromTime, i, statisticsVO);
- } else {
- BeanUtil.copyProperties(daily.get(daily.size() - 1), statisticsVO);
- }
- fromTime = toTime;
- result.add(statisticsVO);
- }
-
- for (int i = 0; i < result.size(); i++) {
- //将空值替换为上个周期的数据 ,因为前面保证了第一条数据一定有值所以不会出现数组越界问题
- if (result.get(i).getProductSpec() != null && result.get(i).getProductSpec().equals(EMPTY_MARK)) {
- PriceStatisticsVO statisticsVO = getNotEmptyOne(i - 1, result);
- String statisticTime = result.get(i).getSatisticsTime();
- BeanUtil.copyProperties(statisticsVO, result.get(i));
- result.get(i).setSatisticsTime(statisticTime);
- }
- }
- return result;
- }
- private List<PriceStatisticsVO> statisticsDaily(String productSpec, String siteId, String from, String to, long dateDiff) {
- List<PriceStatisticsVO> result = new ArrayList<>();
- //按天统计
- long fromTime = 0;
- for (int i = 0; i < dateDiff + 1; i++) {
- if (i == 0) {
- fromTime = DateCommonUtil.getTimeFromStr(from);
- }
- long toTime = DateCommonUtil.dayAfterInterval(DateCommonUtil.dateFromTimestamp(fromTime), 1).getTime();
- List<Document> daily = renduiPriceDailyManager.queryByProductSpec(productSpec, siteId, fromTime, toTime);
- PriceStatisticsVO statisticsVO = new PriceStatisticsVO();
- statisticsVO.setProductSpec(productSpec);
- statisticsVO.setPrice(Float.valueOf("0.00"));
- statisticsVO.setPriceTax(Float.valueOf("0.00"));
- statisticsVO.setSatisticsTime(DateCommonUtil.strFromTimestamp(fromTime));
- if (CollectionUtil.isEmpty(daily)) {
- setDailyEmptyVal(productSpec, siteId, fromTime, i, statisticsVO);
- } else {
- BeanUtil.copyProperties(daily.get(daily.size() - 1), statisticsVO);
- }
- fromTime = toTime;
- result.add(statisticsVO);
- }
-
- for (int i = 0; i < result.size(); i++) {
- //将空值替换为上个周期的数据 ,因为前面保证了第一条数据一定有值所以不会出现数组越界问题
- if (result.get(i).getProductSpec() != null && result.get(i).getProductSpec().equals(EMPTY_MARK)) {
- PriceStatisticsVO statisticsVO = getNotEmptyOne(i - 1, result);
- String statisticTime = result.get(i).getSatisticsTime();
- BeanUtil.copyProperties(statisticsVO, result.get(i));
- result.get(i).setSatisticsTime(statisticTime);
- }
- }
- return result;
- }
manager层
- public List<Document> queryByProductSpec(String productSpec, String siteId, long from, long to) {
- MongoCollection<Document> collection = mongoDatabase.getCollection(TABLE_NAME);
-
- Document document = new Document();
-
- DBObject dbObject = new BasicDBObject();
- dbObject.put("$gte", from);
- dbObject.put("$lt", to);
- Document sort = new Document();
- sort.put("id",-1);
- document.put("productSpec", productSpec);
- document.put("siteId", siteId);
- document.put("timestamp",dbObject);
- FindIterable<Document> findIterable = collection.find(document).sort(sort);
- MongoCursor<Document> mongoCursor = findIterable.iterator();
- List<Document> documentList = new ArrayList<>();
- while (mongoCursor.hasNext()) {
- Document doc = mongoCursor.next();
- doc.remove("_id");
- documentList.add(doc);
- }
- return documentList;
- }
涉及的表:rendui_price_daily