Explorar o código

医健宝-首页统计、店铺修改改为待审核pass字段

chenguo hai 6 días
pai
achega
a896366124

+ 31 - 32
fs-admin/src/main/java/com/fs/api/controller/IndexStatisticsController.java

@@ -1,7 +1,6 @@
 package com.fs.api.controller;
 
 import com.fs.common.core.domain.R;
-import com.fs.common.core.domain.entity.SysDept;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.company.constant.CompanyTrafficConstants;
 import com.fs.company.domain.Company;
@@ -53,7 +52,7 @@ public class IndexStatisticsController {
      */
     @PostMapping("/analysisPreview")
     public R analysisPreview(@RequestBody AnalysisPreviewQueryDTO param){
-        AnalysisPreviewDTO analysisPreviewDTO = null;
+        AnalysisPreviewDTO analysisPreviewDTO = new AnalysisPreviewDTO();
         Integer type = param.getType();
         Integer userType = param.getUserType();
 
@@ -64,7 +63,24 @@ public class IndexStatisticsController {
         if(userType == null) {
             userType = 0;
         }
-        analysisPreviewDTO = redisCache.getCacheObject(String.format("%s:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType));
+        if(param.getCompanyId() != null){
+            analysisPreviewDTO = redisCache.getCacheObject(String.format("%s:%d:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType,param.getCompanyId()));
+        }else if(param.getDeptId() == 1){
+            analysisPreviewDTO = redisCache.getCacheObject(String.format("%s:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType));
+        }else{
+            Company company = new Company();
+            company.setDeptId(param.getDeptId());
+            Long[] companyIds = companyService.selectCompanyList(company).stream().map(Company::getCompanyId).toArray(Long[]::new);
+            for(Long companyId : companyIds){
+                AnalysisPreviewDTO clildDTO = redisCache.getCacheObject(String.format("%s:%d:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType,companyId));
+                if (clildDTO != null) {
+                    long currentWatchUserCount = analysisPreviewDTO.getWatchUserCount();
+                    long childWatchUserCount = clildDTO.getWatchUserCount();
+                    analysisPreviewDTO.setWatchUserCount(currentWatchUserCount + childWatchUserCount);
+                }
+            }
+
+        }
 
         return R.ok().put("data",analysisPreviewDTO);
     }
@@ -124,45 +140,28 @@ public class IndexStatisticsController {
             result.setTraffic(configValue);
         }
         if(param.getCompanyId() != null){
-            //昨天
-            LocalDate yesterday = LocalDate.now().minusDays(1);
-            result.setYesterday(redisCache.getCacheObject(String.format("%s:%d:%d:%s", CompanyTrafficConstants.CACHE_KEY,param.getDeptId(),param.getCompanyId(),yesterday)));
-            //今天
-            result.setToday(redisCache.getCacheObject(String.format("%s:%d:%d:%s", CompanyTrafficConstants.CACHE_KEY,param.getDeptId(),param.getCompanyId(),LocalDate.now())));
-            //本月
-            result.setThisMonth(redisCache.getCacheObject(String.format("%s:%d:%d:%s", CompanyTrafficConstants.CACHE_KEY,param.getDeptId(),param.getCompanyId(),YearMonth.now())));
-            //剩余
-            result.setTraffic(redisCache.getCacheObject(String.format("%s:%d:%d", CompanyTrafficConstants.CACHE_KEY,param.getDeptId(),param.getCompanyId())));
-
+            Company company = companyService.selectCompanyById(param.getCompanyId());
+            getTrafficLogResult(result,CompanyTrafficConstants.CACHE_KEY+":"+company.getDeptId()+":"+param.getCompanyId());
         }else if(param.getDeptId() != null) {
-            //昨天
-            LocalDate yesterday = LocalDate.now().minusDays(1);
-            result.setYesterday(redisCache.getCacheObject(String.format("%s:%s:%s", CompanyTrafficConstants.CACHE_KEY,":1:",yesterday)));
-            //今天
-            result.setToday(redisCache.getCacheObject(String.format("%s:%s:%s", CompanyTrafficConstants.CACHE_KEY,":1:",LocalDate.now())));
-            //本月
-            result.setThisMonth(redisCache.getCacheObject(String.format("%s:%s:%s", CompanyTrafficConstants.CACHE_KEY,":1:",YearMonth.now())));
-            //剩余
-            result.setTraffic(redisCache.getCacheObject(String.format("%s:%s", CompanyTrafficConstants.CACHE_KEY,":1")));
-
+            getTrafficLogResult(result,CompanyTrafficConstants.CACHE_KEY+":"+param.getDeptId());
         }
         return R.ok().put("data",result);
     }
 
-    private TrafficLogDTO getTrafficLogCompany(String key){
-        TrafficLogDTO dto = new TrafficLogDTO();
+    private void getTrafficLogResult(TrafficLogDTO result, String key){
         //昨天
         LocalDate yesterday = LocalDate.now().minusDays(1);
-        dto.setYesterday(redisCache.getCacheObject(key+yesterday));
+        Object yesterdayCount = redisCache.getCacheObject(key+":"+yesterday);
+        Object todayCount = redisCache.getCacheObject(key+":"+LocalDate.now());
+        Object thisMonthCount = redisCache.getCacheObject(key+":"+YearMonth.now());
+        Object traffic = redisCache.getCacheObject(key);
+        result.setYesterday((yesterdayCount == null)?0L:((Integer)yesterdayCount).longValue());
         //今天
-        dto.setToday(redisCache.getCacheObject(key+LocalDate.now()));
+        result.setToday(todayCount == null?0L:((Integer)todayCount).longValue());
         //本月
-        dto.setThisMonth(redisCache.getCacheObject(key+YearMonth.now()));
+        result.setThisMonth(thisMonthCount == null?0L:((Integer)thisMonthCount).longValue());
         //剩余
-        //删除key最后一个字符
-        key = key.substring(0,key.lastIndexOf(":"));
-        dto.setTraffic(redisCache.getCacheObject(key));
-        return dto;
+        result.setTraffic(traffic == null?"0":traffic.toString());
     }
 
     /**

+ 8 - 2
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -852,10 +852,14 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
     private Long updateRedisCache(Company company, Long traffic) throws Exception {
         // 分布式扣除流量
         String companyKey = CompanyTrafficConstants.CACHE_KEY + ":" + company.getDeptId() + ":" + company.getCompanyId();
-        String deptKey = CompanyTrafficConstants.CACHE_KEY + ":" + company.getDeptId();
         String companyDayKey = companyKey + ":"+ LocalDate.now();
-        String dayKey = CompanyTrafficConstants.CACHE_KEY+ ":1:"+ LocalDate.now();
         String companyMonthKey = companyKey + ":"+ YearMonth.now();
+
+        String deptKey = CompanyTrafficConstants.CACHE_KEY + ":" + company.getDeptId();
+        String deptDayKey = deptKey + ":"+ LocalDate.now();
+        String deptMonthKey = deptKey + ":"+ YearMonth.now();
+
+        String dayKey = CompanyTrafficConstants.CACHE_KEY+ ":1:"+ LocalDate.now();
         String monthKey = CompanyTrafficConstants.CACHE_KEY+ ":1:"+ YearMonth.now();
         String lockKey = companyKey + ":lock";
         //销售公司剩余流量
@@ -879,8 +883,10 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
                     balance = redisCache.decr(companyKey, traffic);
                    redisCache.decr(deptKey, traffic);
                    redisCache.incr(companyDayKey, traffic);
+                   redisCache.incr(deptDayKey, traffic);
                    redisCache.incr(dayKey, traffic);
                    redisCache.incr(companyMonthKey, traffic);
+                   redisCache.incr(deptMonthKey, traffic);
                    redisCache.incr(monthKey, traffic);
                 } finally {
                     redisCache.deleteObject(lockKey); // 释放锁

+ 3 - 0
fs-service/src/main/java/com/fs/his/utils/ConfigUtil.java

@@ -63,6 +63,9 @@ public class ConfigUtil {
 
     public JSONObject generateConfigByKeyIndexed(String key,int index){
         SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey(key);
+        if (sysConfig == null) {
+            return new JSONObject();
+        }
         String configValue = sysConfig.getConfigValue();
         if(configValue != null && configValue.trim().startsWith("[")){
             JSONArray array = JSON.parseArray(configValue);

+ 52 - 6
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreScrmServiceImpl.java

@@ -1,8 +1,11 @@
 package com.fs.hisStore.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
+import com.fs.common.utils.StringUtils;
 import com.fs.his.param.FsStoreAuditParam;
+import com.fs.his.utils.ConfigUtil;
 import com.fs.his.utils.StoreMD5PasswordEncoder;
 import com.fs.hisStore.domain.FsStoreProductCategoryScrm;
 import com.fs.hisStore.domain.FsStoreProductScrm;
@@ -15,12 +18,13 @@ import com.fs.hisStore.service.IFsStoreScrmService;
 import com.fs.hisStore.utils.StoreAuditLogUtil;
 import com.fs.hisStore.vo.FsStoreRecommendListVO;
 import com.fs.hisStore.vo.FsStoreScrmVO;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Collections;
-import java.util.List;
+import java.lang.reflect.Field;
+import java.util.*;
 import java.util.stream.Collectors;
 
 
@@ -31,6 +35,7 @@ import java.util.stream.Collectors;
  * @date 2023-06-15
  */
 @Service
+@Slf4j
 public class FsStoreScrmServiceImpl implements IFsStoreScrmService
 {
     @Autowired
@@ -41,6 +46,8 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService
 
     @Autowired
     private FsStoreProductScrmMapper fsStoreProduct;
+    @Autowired
+    private ConfigUtil configUtil;
 
 
     /**
@@ -88,7 +95,7 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService
             }
         }
         StoreMD5PasswordEncoder storeMD5PasswordEncoder = new StoreMD5PasswordEncoder();
-        fsStore.setPassword(storeMD5PasswordEncoder.encode("123456"));
+        fsStore.setPassword(storeMD5PasswordEncoder.encode("XyzAbc~12"));
         fsStore.setCreateTime(DateUtils.getNowDate());
         fsStoreMapper.insertFsStore(fsStore);
         return fsStore.getStoreId();
@@ -105,13 +112,52 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService
     {
         fsStore.setUpdateTime(DateUtils.getNowDate());
         storeAuditLogUtil.addOperLog(fsStore.getStoreId());
-        //更新,信息,时间等,后台重新审核,驳回的店铺,重新审核
-        if(1 == fsStore.getIsAudit()){
-            fsStore.setIsAudit(0);
+        FsStoreScrm oldFsStore = fsStoreMapper.selectFsStoreByStoreId(fsStore.getStoreId());
+        String isAudit = configUtil.generateConfigByKey("medicalMall.func.switch").getString("isAudit");
+        try {
+            if ("1".equals(isAudit)) {
+                if (fsStore.getIsAudit() != null && 1 == fsStore.getIsAudit()) {
+                    Map<String, Object> diff = getDiff(oldFsStore, fsStore);
+                    Set<String> diff_columns = diff.keySet();
+                    String passColumnStr = configUtil.generateConfigByKey("medicalMall.func.switch").getString("pass_columns");
+                    if(StringUtils.isNotEmpty(passColumnStr)){
+                        List<String> pass_columns = Arrays.asList(passColumnStr.split(","));
+                        //判断diff_columns是否在pass_columns中,不是则将isAudit设置为0
+                        for (String column : diff_columns) {
+                            if (!pass_columns.contains(column)) {
+                                fsStore.setIsAudit(0);
+                                break;
+                            }
+                        }
+                    }else{
+                        fsStore.setIsAudit(0);
+                    }
+                }
+            }
+        } catch (IllegalAccessException e) {
+            log.error("获取diff出错", e);
         }
         return fsStoreMapper.updateFsStore(fsStore);
     }
 
+    public static Map<String, Object> getDiff(Object obj1, Object obj2) throws IllegalAccessException {
+        Map<String, Object> diff = new HashMap<>();
+        if (obj1 == null || obj2 == null || !obj1.getClass().equals(obj2.getClass())) {
+            return diff;
+        }
+
+        Field[] fields = obj1.getClass().getDeclaredFields();
+        for (Field field : fields) {
+            field.setAccessible(true);
+            Object value1 = field.get(obj1);
+            Object value2 = field.get(obj2);
+            if (!Objects.equals(value1, value2)) {
+                diff.put(field.getName(), new Object[]{value1, value2});
+            }
+        }
+        return diff;
+    }
+
     /**
      * 批量删除店铺管理
      *

+ 5 - 0
fs-service/src/main/java/com/fs/statis/dto/AnalysisPreviewQueryDTO.java

@@ -47,4 +47,9 @@ public class AnalysisPreviewQueryDTO implements Serializable {
      */
     private Long companyId;
 
+    /**
+     * 部门id
+     * */
+    private Long deptId;
+
 }