Explorar o código

Merge remote-tracking branch 'origin/prod' into prod

李进 %!s(int64=2) %!d(string=hai) anos
pai
achega
6e9bb8ddcc

+ 45 - 0
device-api-service-merc-mini/src/main/java/com/xy/controller/MercMiniDeviceDataController.java

@@ -0,0 +1,45 @@
+package com.xy.controller;
+
+import com.xy.annotate.RestMappingController;
+import com.xy.dto.DeviceDataDto;
+import com.xy.service.DeviceDataServiceImpl;
+import com.xy.utils.MercAuthUtils;
+import com.xy.utils.PageBean;
+import com.xy.utils.R;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import javax.validation.Valid;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author hechunping
+ * @since 2023/3/27
+ */
+@RestMappingController("merc-mini/deviceData")
+@AllArgsConstructor
+@Api(tags = "小程序-设备销售数据统计")
+public class MercMiniDeviceDataController {
+
+    private final DeviceDataServiceImpl deviceDataService;
+
+    @PostMapping("sumPage")
+    @ApiOperation("设备销售数据统计分页")
+    public R<PageBean<DeviceDataDto.SumPageVo>> sumPage(@RequestBody @Valid DeviceDataDto.SumPageDto dto){
+        dto.setMercId(MercAuthUtils.getMercId());
+        return R.ok(deviceDataService.sumPage(dto).getData());
+    }
+
+    @PostMapping("sumCount")
+    @ApiOperation("设备销售数据统计总计")
+    public R<DeviceDataDto.SumCountVo> sumCount(@RequestBody @Valid DeviceDataDto.SumCountDto dto){
+        dto.setMercId(MercAuthUtils.getMercId());
+        return R.ok(deviceDataService.sumCount(dto).getData());
+    }
+}

+ 70 - 1
device-api-service/src/main/java/com/xy/service/DeviceDataServiceImpl.java

@@ -2,6 +2,7 @@ package com.xy.service;
 
 import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xy.annotation.Lock;
@@ -10,6 +11,7 @@ import com.xy.collections.map.JConcurrentHashMap;
 import com.xy.collections.map.JHashMap;
 import com.xy.collections.map.JMap;
 import com.xy.dto.DeviceDataDto;
+import com.xy.dto.DeviceInfoDto;
 import com.xy.entity.DeviceData;
 import com.xy.entity.SysDictRedis;
 import com.xy.mapper.DeviceDataMapper;
@@ -19,13 +21,16 @@ import com.xy.utils.enums.DictSonEnum;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 
+import javax.validation.Valid;
 import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import static com.xy.utils.Beans.copy;
 import static com.xy.utils.PlusBeans.toIPage;
@@ -41,10 +46,74 @@ import static com.xy.utils.PlusBeans.toPageBean;
  * @since 2023-01-11
  */
 @Service
-@AllArgsConstructor
+@AllArgsConstructor(onConstructor_ = @Lazy)
 @Api(tags = "设备统计数据")
 public class DeviceDataServiceImpl extends ServiceImpl<DeviceDataMapper, DeviceData> implements DeviceDataService {
 
+    private final DeviceInfoServiceImpl deviceInfoService;
+    @PostMapping("sumPage")
+    @ApiOperation("设备销售统计")
+    public R<PageBean<DeviceDataDto.SumPageVo>> sumPage(@RequestBody @Valid DeviceDataDto.SumPageDto dto) {
+        PageBean pageBean = dto.getPage();
+        String salesCount = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getSalesCount));
+        String salesMoney = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getSalesMoney));
+        String goodsCount = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getGoodsCount));
+        String refundMoney = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getRefundMoney));
+        String refundCount = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getRefundCount));
+        String riskCount = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getRiskCount));
+        String zeroCount = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getZeroCount));
+        String deviceId = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getDeviceId));
+
+        LambdaQueryWrapper<DeviceData> lqw = new QueryWrapper<DeviceData>()
+                .select(String.format("%s,sum(%s) %s,sum(%s) %s,sum(%s) %s,sum(%s) %s,sum(%s) %s,sum(%s) %s,sum(%s) %s"
+                        , deviceId, salesCount, salesCount, salesMoney, salesMoney, goodsCount, goodsCount
+                        ,refundMoney,refundMoney,refundCount,refundCount,riskCount,riskCount,zeroCount,zeroCount
+                ))
+                .orderByAsc("asc".equals(dto.getOrderBy()), dto.getOrderByKey())
+                .orderByDesc("desc".equals(dto.getOrderBy()), dto.getOrderByKey())
+                .lambda()
+                .eq(Emptys.check(dto.getMercId()),DeviceData::getMercId, dto.getMercId())
+                .eq(DeviceData::getType, dto.getType())
+                .ge(Emptys.check(dto.getBeginDate()), DeviceData::getDateValue, dto.getBeginDate())
+                .le(Emptys.check(dto.getEndDate()), DeviceData::getDateValue, dto.getEndDate())
+                .groupBy(DeviceData::getDeviceId);
+        IPage<DeviceData> ipage = page(toIPage(pageBean), lqw);
+        if(Emptys.check(ipage.getRecords())) {
+            List<Long> deviceIdList = ipage.getRecords().stream().map(DeviceData::getDeviceId).collect(Collectors.toList());
+            Map<Long, String> deviceMap = deviceInfoService.getDeviceNameList(new DeviceInfoDto.DeviceIdDto().setDeviceId(deviceIdList)).getData();
+            PageBean<DeviceDataDto.SumPageVo> sumPageVoPageBean = toPageBean(DeviceDataDto.SumPageVo.class, ipage);
+            sumPageVoPageBean.getRecords().forEach(i -> {
+                i.setDeviceName(deviceMap.get(i.getDeviceId()));
+            });
+            return R.ok(sumPageVoPageBean);
+        }
+        return R.ok();
+    }
+
+    @PostMapping("sumCount")
+    @ApiOperation("设备销售统计总计")
+    public R<DeviceDataDto.SumCountVo> sumCount(@RequestBody @Valid DeviceDataDto.SumCountDto dto) {
+        String salesCount = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getSalesCount));
+        String salesMoney = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getSalesMoney));
+        String goodsCount = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getGoodsCount));
+        String refundMoney = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getRefundMoney));
+        String refundCount = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getRefundCount));
+        String riskCount = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getRiskCount));
+        String zeroCount = StringTools.humpToLine(LambdaUtils.getProperty(DeviceData::getZeroCount));
+        //查询总数
+        LambdaQueryWrapper<DeviceData> lqw = new QueryWrapper<DeviceData>()
+                .select(String.format("sum(%s) %s,sum(%s) %s,sum(%s) %s,sum(%s) %s,sum(%s) %s,sum(%s) %s,sum(%s) %s"
+                        , salesCount, salesCount, salesMoney, salesMoney, goodsCount, goodsCount
+                        ,refundMoney,refundMoney,refundCount,refundCount,riskCount,riskCount,zeroCount,zeroCount
+                ))
+                .lambda()
+                .eq(Emptys.check(dto.getMercId()),DeviceData::getMercId, dto.getMercId())
+                .eq(DeviceData::getType, dto.getType())
+                .ge(Emptys.check(dto.getBeginDate()), DeviceData::getDateValue, dto.getBeginDate())
+                .le(Emptys.check(dto.getEndDate()), DeviceData::getDateValue, dto.getEndDate());
+        return R.ok(copy(DeviceDataDto.SumCountVo.class,getOne(lqw)));
+    }
+
     @PostMapping("obj")
     @ApiOperation("对象查询")
     public R<DeviceDataDto.Vo> obj(@RequestBody DeviceDataDto.Vo vo) {

+ 7 - 0
device-api-service/src/main/java/com/xy/service/DeviceInfoServiceImpl.java

@@ -2,6 +2,7 @@ package com.xy.service;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.ListUtil;
 import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.text.StrBuilder;
@@ -625,7 +626,13 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
                 }
 
             }
+
+            //在线排序
+            if (CollUtil.isNotEmpty(deviceInfos)) {
+                deviceInfos = ListUtil.sortByProperty(deviceInfos, LambdaUtils.getProperty(DeviceInfoDto.MercHomeDeviceVo::getNetState));
+            }
             vo.setDeviceInfos(deviceInfos);
+
             dataList.add(vo);
         }
 

+ 2 - 2
device-api-service/src/main/java/com/xy/service/DeviceQualityServiceImpl.java

@@ -101,7 +101,7 @@ public class DeviceQualityServiceImpl extends ServiceImpl<DeviceQualityMapper, D
     public R<DeviceQualityDto.Vo> obj(@RequestBody DeviceQualityDto.Obj obj) {
         LambdaQueryWrapper<DeviceQuality> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(obj, DeviceQuality.class)
                 .build()
-                .orderByDesc(DeviceQuality::getCreateTime);
+                .orderByDesc(DeviceQuality::getQualityId);
         List<DeviceQuality> deviceQualities = list(lambdaQueryWrapper);
         List<DeviceQualityDto.Vo> list = copy(DeviceQualityDto.Vo.class, deviceQualities);
         if (!Emptys.check(list)) {
@@ -218,7 +218,7 @@ public class DeviceQualityServiceImpl extends ServiceImpl<DeviceQualityMapper, D
         JSONObject data = qualityResultBack.getData();
         LambdaQueryWrapper<DeviceQuality> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceQuality>()
                 .eq(DeviceQuality::getDeviceId, deviceId)
-                .eq(DeviceQuality::getShowStatus, true);
+                .eq(DeviceQuality::getShowStatus, true).orderByDesc(DeviceQuality::getQualityId).last("limit 1");
         DeviceQuality deviceQuality = getOne(lambdaQueryWrapper);
         if (deviceQuality == null) {
             return R.fail("设备不存在");

+ 95 - 0
device-api/src/main/java/com/xy/dto/DeviceDataDto.java

@@ -1,6 +1,7 @@
 package com.xy.dto;
 
 import cn.hutool.core.date.DateTime;
+import cn.hutool.core.util.StrUtil;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.xy.utils.PageBean;
 import io.swagger.annotations.ApiModelProperty;
@@ -22,6 +23,100 @@ import java.util.List;
  */
 public class DeviceDataDto {
 
+    @Data
+    @Accessors(chain = true)
+    public static class SumCountVo{
+        @ApiModelProperty(value = "营业额;单位分")
+        private Integer salesMoney;
+
+        @ApiModelProperty(value = "销售笔数")
+        private Integer salesCount;
+
+        @ApiModelProperty(value = "销售商品数")
+        private Integer goodsCount;
+
+        @ApiModelProperty(value = "退款金额;单位分")
+        private Integer refundMoney;
+
+        @ApiModelProperty(value = "退款笔数")
+        private Integer refundCount;
+
+        @ApiModelProperty(value = "风险订单数")
+        private Integer riskCount;
+
+        @ApiModelProperty(value = "0元订单笔数")
+        private Integer zeroCount;
+    }
+    @Data
+    @Accessors(chain = true)
+    public static class SumCountDto{
+        @ApiModelProperty(value = "商户ID",required = true)
+        private Long mercId;
+
+        @NotNull(message = "统计类型不能为空")
+        @ApiModelProperty(value = "统计类型",required = true)
+        private String type;
+
+        @NotNull(message = "排序字段不能为空")
+        @ApiModelProperty(value = "排序字段",required = true)
+        private String orderByKey;
+
+        @NotNull(message = "排序方式不能为空")
+        @ApiModelProperty(value = "排序方式",required = true)
+        private String orderBy;
+
+        @ApiModelProperty("开始时间")
+        private String beginDate;
+
+        @ApiModelProperty("结束时间")
+        private String endDate;
+
+        public String getBeginDate() {
+            return StrUtil.replace(beginDate,"-","");
+        }
+        public String getEndDate() {
+            return StrUtil.replace(endDate,"-","");
+        }
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class SumPageDto extends SumCountDto{
+        @NotNull(message = "分页信息不能为空")
+        @ApiModelProperty(value = "分页信息",required = true)
+        private PageBean page;
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class SumPageVo {
+        @ApiModelProperty(value = "平台商品id")
+        private Long deviceId;
+
+        @ApiModelProperty(value = "设备名称")
+        private String deviceName;
+
+        @ApiModelProperty(value = "营业额;单位分")
+        private Integer salesMoney;
+
+        @ApiModelProperty(value = "销售笔数")
+        private Integer salesCount;
+
+        @ApiModelProperty(value = "销售商品数")
+        private Integer goodsCount;
+
+        @ApiModelProperty(value = "退款金额;单位分")
+        private Integer refundMoney;
+
+        @ApiModelProperty(value = "退款笔数")
+        private Integer refundCount;
+
+        @ApiModelProperty(value = "风险订单数")
+        private Integer riskCount;
+
+        @ApiModelProperty(value = "0元订单笔数")
+        private Integer zeroCount;
+    }
     @Data
     @Accessors(chain = true)
     public static class Page extends Vo {