Browse Source

add app宣教文章管理

18339543638 3 năm trước cách đây
mục cha
commit
237cf0a9cc

+ 48 - 0
nb-service-api/web-service-api/src/main/java/com/nb/web/api/entity/AppArticleEntity.java

@@ -0,0 +1,48 @@
+package com.nb.web.api.entity;
+
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.nb.core.entity.GenericEntity;
+import com.nb.web.api.enums.AppArticleEnum;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotNull;
+
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName BusHospitalLogEntity.java
+ * @Description TODO
+ * @createTime 2022年03月21日 11:25:00
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+@TableName(value = "app_article",autoResultMap = true)
+@ApiModel(value="app端宣教文章", description="app端宣教文章")
+public class AppArticleEntity extends GenericEntity<String> {
+
+    @ApiModelProperty(value = "文章标题",required = true)
+    @NotNull(message = "文章标题不能为空")
+    private String title;
+
+    @ApiModelProperty("首图")
+    private String graph;
+
+    @ApiModelProperty(value = "文章类型",example = "0(术后镇痛) 1(癌痛知识) 2(评价标准) 3(健康资讯)",required = true)
+    @NotNull(message = "文章类型不能为空")
+    private AppArticleEnum type;
+
+    @ApiModelProperty(value = "是否为外链",required = true)
+    @NotNull(message = "是否为外链不能为空")
+    private Boolean backLinks;
+
+    @ApiModelProperty(value = "文章内容",example = "当backLinks=false时,该字段不能为空")
+    private String content;
+
+    @ApiModelProperty(value = "外链地址",example = "当backLinks=true时,该字段不能为空")
+    private String url;
+}

+ 33 - 0
nb-service-api/web-service-api/src/main/java/com/nb/web/api/enums/AppArticleEnum.java

@@ -0,0 +1,33 @@
+package com.nb.web.api.enums;
+
+import com.baomidou.mybatisplus.annotation.IEnum;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName AppArticleEnum.java
+ * @Description app宣教文章类型
+ * @createTime 2022年08月10日 16:13:00
+ */
+@AllArgsConstructor
+@JsonFormat(shape = JsonFormat.Shape.OBJECT)
+public enum AppArticleEnum implements IEnum<Integer> {
+    Analgesia(0,"术后镇痛"),
+    Cancer(1,"癌痛知识"),
+    Eval(2,"评价标准"),
+    Healthy(3,"健康资讯"),
+    ;
+    /**
+     * 与枚举ordinal保持一致
+     */
+    @Getter
+    @ApiModelProperty("运行状态编码")
+    private Integer value;
+    @Getter
+    @ApiModelProperty("运行状态内容")
+    private String text;
+    }

+ 37 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/controller/AppArticleController.java

@@ -0,0 +1,37 @@
+package com.nb.web.service.bus.controller;
+
+import com.baomidou.mybatisplus.core.mapper.Mapper;
+import com.nb.common.crud.BaseService;
+import com.nb.common.crud.controller.BaseCrudController;
+import com.nb.web.api.entity.AppArticleEntity;
+import com.nb.web.service.bus.service.LocalAppArticleService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.Authorization;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName AppArticleController.java
+ * @Description TODO
+ * @createTime 2022年06月24日 15:02:00
+ */
+@RestController
+@RequestMapping("/bus/app/article")
+@Api(tags = "app宣教文章管理",description="app宣教文章管理    权限: app:article: ",authorizations = {@Authorization("app:article:")})
+public class AppArticleController extends BaseCrudController<AppArticleEntity,String> {
+    @Resource
+    private LocalAppArticleService appArticleService;
+
+    @Override
+    public BaseService<? extends Mapper<AppArticleEntity>, AppArticleEntity, String> getService() {
+        return appArticleService;
+    }
+
+    @Override
+    public String getPermissionPrefix() {
+        return "app:article:";
+    }
+}

+ 11 - 2
nb-service/web-service/src/main/java/com/nb/web/service/bus/controller/BusInfusionHistoryController.java

@@ -112,8 +112,17 @@ public class BusInfusionHistoryController implements BaseQueryController<BusInfu
             Map<String, List<BusDeviceHistoryEntity>> historiesMap = histories.stream()
                     .collect(Collectors.groupingBy(BusDeviceHistoryEntity::getInfusionId));
             result.parallelStream()
-                    .forEach(infusion->
-                            infusion.setLossRate(deviceHistoryService.computeLossRate(historiesMap.get(infusion.getId())))
+                    .forEach(infusion->{
+                                List<BusDeviceHistoryEntity> historyEntities = historiesMap.get(infusion.getId());
+                                if (CollectionUtil.isEmpty(historyEntities)) {
+                                    infusion.setReceiveNum(0L);
+                                    infusion.setLossRate(BigDecimal.ZERO);
+                                }else {
+                                    long count = historyEntities.stream().map(BusDeviceHistoryEntity::getDataNumber).distinct().count();
+                                    infusion.setReceiveNum(count);
+                                    infusion.setLossRate(deviceHistoryService.computeLossRate(count,historyEntities));
+                                }
+                            }
                     );
         }
         return R.success(result);

+ 17 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/mapper/AppArticleMapper.java

@@ -0,0 +1,17 @@
+package com.nb.web.service.bus.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.nb.web.api.entity.AppArticleEntity;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName AppArticleMapper.java
+ * @Description app宣教文章
+ * @createTime 2022年03月19日 09:15:00
+ */
+@Mapper
+public interface AppArticleMapper extends BaseMapper<AppArticleEntity> {
+
+}

+ 54 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/service/LocalAppArticleService.java

@@ -0,0 +1,54 @@
+package com.nb.web.service.bus.service;
+
+import cn.dev33.satoken.exception.NotPermissionException;
+import cn.hutool.core.util.StrUtil;
+import com.nb.auth.bean.LoginUser;
+import com.nb.auth.utils.SecurityUtil;
+import com.nb.common.crud.BaseService;
+import com.nb.core.exception.CustomException;
+import com.nb.web.api.entity.AppArticleEntity;
+import com.nb.web.service.bus.entity.BusDocEntity;
+import com.nb.web.service.bus.mapper.AppArticleMapper;
+import com.nb.web.service.bus.mapper.BusDocMapper;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName LocalAppArticleService.java
+ * @Description app宣教文章
+ * @createTime 2022年03月19日 09:27:00
+ */
+@Service
+@Slf4j
+public class LocalAppArticleService extends BaseService<AppArticleMapper, AppArticleEntity,String> {
+
+    @Override
+    public void validateBeforeSave(AppArticleEntity entity) {
+        validate(entity);
+    }
+
+    @Override
+    public void validateBeforeUpdate(AppArticleEntity entity) {
+        validate(entity);
+    }
+
+    @Override
+    public void validateBeforeDelete(String id) {
+
+    }
+
+
+    private void validate(AppArticleEntity entity){
+        if(Boolean.TRUE.equals(entity.getBackLinks())){
+            if(StrUtil.isEmpty(entity.getUrl())){
+                throw new CustomException("外链连接不能为空");
+            }
+        }else {
+            if(StrUtil.isEmpty(entity.getContent())){
+                throw new CustomException("文章内容不能为空");
+            }
+        }
+    }
+}

+ 11 - 5
nb-service/web-service/src/main/java/com/nb/web/service/bus/service/LocalBusDeviceHistoryService.java

@@ -42,22 +42,28 @@ public class LocalBusDeviceHistoryService extends BaseService<BusDeviceHistoryMa
         return this.baseMapper.pageQuery(query.getPage(),query);
     }
 
-
-    public BigDecimal computeLossRate(List<BusDeviceHistoryEntity> sources) {
-        if(CollectionUtil.isEmpty(sources)){
+    public BigDecimal computeLossRate(long totalCount,List<BusDeviceHistoryEntity> sources) {
+        if(totalCount==0){
             return BigDecimal.ZERO;
         }
-        long count = sources.stream().map(BusDeviceHistoryEntity::getDataNumber).distinct().count();
         AtomicReference<BigDecimal> result = new AtomicReference<>(BigDecimal.ZERO);
         if (CollectionUtil.isNotEmpty(sources)) {
             sources.stream().map(BusDeviceHistoryEntity::getDataNumber)
                     .max(Comparator.comparing(Integer::valueOf))
                     .map(max -> {
-                        BigDecimal proportionRate = BigDecimal.valueOf(count).divide(BigDecimal.valueOf(max), 2, BigDecimal.ROUND_HALF_UP);
+                        BigDecimal proportionRate = BigDecimal.valueOf(totalCount).divide(BigDecimal.valueOf(max), 2, BigDecimal.ROUND_HALF_UP);
                         result.set(BigDecimal.ONE.subtract(proportionRate).multiply(BigDecimal.valueOf(100)));
                         return max;
                     });
         }
         return result.get();
     }
+
+    public BigDecimal computeLossRate(List<BusDeviceHistoryEntity> sources) {
+        if(CollectionUtil.isEmpty(sources)){
+            return BigDecimal.ZERO;
+        }
+        long count = sources.stream().map(BusDeviceHistoryEntity::getDataNumber).distinct().count();
+        return computeLossRate(count,sources);
+    }
 }

+ 2 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/service/dto/TestBusInfusionHistory.java

@@ -39,6 +39,8 @@ public class TestBusInfusionHistory implements Serializable {
 
     private Date startTime;
 
+    private Long receiveNum;
+
     private BigDecimal lossRate;
 
     public static TestBusInfusionHistory valueOf(BusInfusionHistoryEntity source){