Browse Source

功能开关改造,新增平台配置页面,完善店铺、商品不需要重新审核字段功能

chenguo 1 month ago
parent
commit
873e08c155

+ 20 - 0
fs-admin/src/main/java/com/fs/hisStore/controller/ConfigInitController.java

@@ -0,0 +1,20 @@
+package com.fs.hisStore.controller;
+
+import com.fs.hisStore.config.MedicalMallConfig;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/configInit")
+public class ConfigInitController {
+
+    @Autowired
+    private MedicalMallConfig medicalMallConfig;
+
+    @GetMapping("/initMedicalMallConfig")
+    public void init() {
+        medicalMallConfig.init();
+    }
+}

+ 10 - 0
fs-admin/src/main/java/com/fs/hisStore/controller/FsStoreProductScrmController.java

@@ -35,6 +35,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.servlet.http.HttpServletRequest;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 商品Controller
@@ -209,4 +210,13 @@ public class FsStoreProductScrmController extends BaseController
         return R.ok().put("data",list);
     }
 
+    /**
+     * 获取店铺商品表字段
+     * */
+    @GetMapping("/getStoreProductColumns")
+    public R getStoreProductColumns() {
+        List<Map<String, String>> list = fsStoreProductService.getStoreProductColumns();
+        return R.ok().put("data", list);
+    }
+
 }

+ 10 - 0
fs-admin/src/main/java/com/fs/hisStore/controller/FsStoreScrmController.java

@@ -17,6 +17,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 店铺管理Controller
@@ -148,4 +149,13 @@ public class FsStoreScrmController extends BaseController
     public R auditLog(@PathVariable Long storeId){
         return R.ok().put("auditLog",storeAuditLogUtil.selectOperLogByMainId(storeId));
     }
+
+    /**
+     * 获取店铺商品表字段
+     * */
+    @GetMapping("/getStoreColumns")
+    public R getStoreProductColumns() {
+        List<Map<String, String>> list = fsStoreService.getStoreColumns();
+        return R.ok().put("data", list);
+    }
 }

+ 0 - 3
fs-admin/src/main/java/com/fs/web/controller/system/SysLoginController.java

@@ -90,9 +90,6 @@ public class SysLoginController
         //药品商城参数
         AjaxResult ajax = AjaxResult.success();
 
-        if(medicalMallConfig!=null){
-            ajax.put("medicalMallConfig", medicalMallConfig);
-        }
         ajax.put("user", user);
         Integer isAdmin = 0;
         if (permissions.contains("*:*:*")){

+ 11 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreProductScrmMapper.java

@@ -1,6 +1,7 @@
 package com.fs.hisStore.mapper;
 
 import java.util.List;
+import java.util.Map;
 
 import com.fs.his.param.FsStoreProductListSParam;
 import com.fs.his.vo.FsStoreProductListSVO;
@@ -398,4 +399,14 @@ public interface FsStoreProductScrmMapper
             "where find_in_set(p.product_id,#{ids})  " +
             "</script>"})
     List<FsStoreProductActivityListVO> selectFsStoreProductByIdsAudit(String productIds,@Param("config") MedicalMallConfig  config);
+
+    @Select("SELECT " +
+            " distinct  " +
+            "    COLUMN_NAME as colName,  " +
+            "    COLUMN_COMMENT  as colComment " +
+            "FROM  " +
+            "    information_schema.COLUMNS  " +
+            "WHERE  " +
+            "    TABLE_NAME = 'fs_store_product_scrm'")
+    List<Map<String, String>> getStoreProductColumns();
 }

+ 11 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreScrmMapper.java

@@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 店铺管理Mapper接口
@@ -88,4 +89,14 @@ public interface FsStoreScrmMapper
 //    @Select("select store_id ,store_name,bus_no,bus_name  from fs_store_scrm ")
     @Select("select store_id ,store_name  from fs_store_scrm ")
     List<FsStoreScrmVO> selectFsAllStoreList();
+
+    @Select("SELECT " +
+            " distinct  " +
+            "    COLUMN_NAME as colName,  " +
+            "    COLUMN_COMMENT as colComment " +
+            "FROM  " +
+            "    information_schema.COLUMNS  " +
+            "WHERE  " +
+            "    TABLE_NAME = 'fs_store_scrm'")
+    List<Map<String, String>> getStoreColumns();
 }

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/service/IFsStoreProductScrmService.java

@@ -135,4 +135,6 @@ public interface IFsStoreProductScrmService
     FsStoreProductScrm selectFsStoreProductByIdAudit(Long productId);
 
     List<FsStoreProductActivityListVO> selectFsStoreProductByIdsAudit(String productIds);
+
+    List<Map<String, String>> getStoreProductColumns();
 }

+ 3 - 0
fs-service/src/main/java/com/fs/hisStore/service/IFsStoreScrmService.java

@@ -6,6 +6,7 @@ import com.fs.hisStore.vo.FsStoreRecommendListVO;
 import com.fs.hisStore.vo.FsStoreScrmVO;
 
 import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -84,4 +85,6 @@ public interface IFsStoreScrmService
     List<FsStoreRecommendListVO> storeRecommendList();
 
     List<FsStoreScrmVO> selectAllStore();
+
+    List<Map<String, String>> getStoreColumns();
 }

+ 96 - 6
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreProductScrmServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fs.hisStore.service.impl;
 
+import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.util.*;
@@ -10,6 +11,7 @@ import cn.hutool.core.util.ArrayUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fs.common.BeanCopyUtils;
 import com.fs.common.core.domain.R;
@@ -37,6 +39,7 @@ import com.fs.hisStore.param.FsStoreProductQueryParam;
 import com.fs.hisStore.service.IFsStoreProductAttrValueScrmService;
 import com.fs.hisStore.vo.*;
 import com.fs.statis.dto.ProductAuditDTO;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -54,6 +57,7 @@ import org.springframework.transaction.annotation.Transactional;
  */
 @Service
 @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+@Slf4j
 public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
 {
     @Autowired
@@ -144,13 +148,62 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
     {
         fsStoreProduct.setUpdateTime(DateUtils.getNowDate());
         storeAuditLogUtil.addOperLog(fsStoreProduct.getProductId());
-        //对已上架的商品进行修改需要重新审核
-        if(1 == fsStoreProduct.getIsShow() && "1".equals(fsStoreProduct.getIsAudit())){
-            fsStoreProduct.setIsAudit("0");
+        FsStoreProductScrm oldFsStoreProduct = fsStoreProductMapper.selectFsStoreProductById(fsStoreProduct.getProductId());
+        Boolean isAudit = configUtil.generateConfigByKey("medicalMall.func.switch").getBoolean("isAudit");
+        try {
+            if (isAudit != null && isAudit) {
+                if (oldFsStoreProduct.getIsAudit() != null && "1".equals(oldFsStoreProduct.getIsAudit())) {
+                    Map<String, Object> diff = getDiff(oldFsStoreProduct, fsStoreProduct);
+                    Set<String> diff_columns = diff.keySet();
+                    JSONArray productColumns = configUtil.generateConfigByKey("medicalMall.func.switch").getJSONArray("productColumns");
+                    if(com.fs.common.utils.StringUtils.isNotEmpty(productColumns)){
+                        //判断diff_columns是否在productColumns中,不是则将isAudit设置为0
+                        for (String column : diff_columns) {
+                            if (!productColumns.contains(column)) {
+                                fsStoreProduct.setIsAudit("0");
+                                break;
+                            }
+                        }
+                    }else{
+                        fsStoreProduct.setIsAudit("0");
+                    }
+                }
+            }
+        } catch (IllegalAccessException e) {
+            log.error("获取diff出错", e);
         }
         return fsStoreProductMapper.updateFsStoreProduct(fsStoreProduct);
     }
 
+    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);
+
+            // BigDecimal类型特殊处理
+            if (value1 instanceof BigDecimal && value2 instanceof BigDecimal) {
+                BigDecimal bd1 = (BigDecimal) value1;
+                BigDecimal bd2 = (BigDecimal) value2;
+                // 使用compareTo方法比较,避免精度问题
+                if (bd1.compareTo(bd2) != 0) {
+                    diff.put(field.getName(), new Object[]{value1, value2});
+                }
+            }
+            // 其他类型使用默认比较
+            else if (!Objects.equals(value1, value2)) {
+                diff.put(field.getName(), new Object[]{value1, value2});
+            }
+        }
+        return diff;
+    }
+
     /**
      * 批量删除商品
      *
@@ -363,9 +416,29 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
             }
         }
         if(param.getProductId() != null && param.getProductId() > 0){
-            //对已上架的商品进行修改需要重新审核
-            if(1 == product.getIsShow() && "1".equals(product.getIsAudit())){
-                product.setIsAudit("0");
+            FsStoreProductScrm oldFsStoreProduct = fsStoreProductMapper.selectFsStoreProductById(product.getProductId());
+            Boolean isAudit = configUtil.generateConfigByKey("medicalMall.func.switch").getBoolean("isAudit");
+            try {
+                if (isAudit != null && isAudit) {
+                    if (oldFsStoreProduct.getIsAudit() != null && "1".equals(oldFsStoreProduct.getIsAudit())) {
+                        Map<String, Object> diff = getDiff(oldFsStoreProduct, product);
+                        Set<String> diff_columns = diff.keySet();
+                        JSONArray productColumns = configUtil.generateConfigByKey("medicalMall.func.switch").getJSONArray("productColumns");
+                        if(com.fs.common.utils.StringUtils.isNotEmpty(productColumns)){
+                            //判断diff_columns是否在productColumns中,不是则将isAudit设置为0
+                            for (String column : diff_columns) {
+                                if (!productColumns.contains(column)) {
+                                    product.setIsAudit("0");
+                                    break;
+                                }
+                            }
+                        }else{
+                            product.setIsAudit("0");
+                        }
+                    }
+                }
+            } catch (IllegalAccessException e) {
+                log.error("获取diff出错", e);
             }
             fsStoreProductMapper.updateFsStoreProduct(product);
             if (param.getSpecType().equals(0)) {
@@ -1037,4 +1110,21 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
     public List<FsStoreProductActivityListVO> selectFsStoreProductByIdsAudit(String productIds) {
         return fsStoreProductMapper.selectFsStoreProductByIdsAudit(productIds,medicalMallConfig);
     }
+
+    @Override
+    public List<Map<String, String>> getStoreProductColumns() {
+        List<Map<String, String> > list = fsStoreProductMapper.getStoreProductColumns();
+        List<Map<String, String>> result = new ArrayList<>();
+        for (Map<String, String> column : list) {
+            Map<String, String> camelCaseColumn = new HashMap<>();
+            String columnName = column.get("colName");
+            String camelCaseName = com.fs.common.utils.StringUtils.toCamelCase(columnName);;
+            camelCaseColumn.put("colName", camelCaseName);
+            camelCaseColumn.put("colComment", column.get("colComment"));
+            result.add(camelCaseColumn);
+        }
+
+        return result;
+    }
+
 }

+ 37 - 8
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreScrmServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fs.hisStore.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.DateUtils;
@@ -24,6 +25,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.lang.reflect.Field;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -113,18 +115,17 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService
         fsStore.setUpdateTime(DateUtils.getNowDate());
         storeAuditLogUtil.addOperLog(fsStore.getStoreId());
         FsStoreScrm oldFsStore = fsStoreMapper.selectFsStoreByStoreId(fsStore.getStoreId());
-        String isAudit = configUtil.generateConfigByKey("medicalMall.func.switch").getString("isAudit");
+        Boolean isAudit = configUtil.generateConfigByKey("medicalMall.func.switch").getBoolean("isAudit");
         try {
-            if ("1".equals(isAudit)) {
+            if (isAudit != null && 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
+                    JSONArray storeColumns = configUtil.generateConfigByKey("medicalMall.func.switch").getJSONArray("storeColumns");
+                    if(StringUtils.isNotEmpty(storeColumns)){
+                        //判断diff_columns是否在storeColumns中,不是则将isAudit设置为0
                         for (String column : diff_columns) {
-                            if (!pass_columns.contains(column)) {
+                            if (!storeColumns.contains(column)) {
                                 fsStore.setIsAudit(0);
                                 break;
                             }
@@ -151,7 +152,17 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService
             field.setAccessible(true);
             Object value1 = field.get(obj1);
             Object value2 = field.get(obj2);
-            if (!Objects.equals(value1, value2)) {
+            // BigDecimal类型特殊处理
+            if (value1 instanceof BigDecimal && value2 instanceof BigDecimal) {
+                BigDecimal bd1 = (BigDecimal) value1;
+                BigDecimal bd2 = (BigDecimal) value2;
+                // 使用compareTo方法比较,避免精度问题
+                if (bd1.compareTo(bd2) != 0) {
+                    diff.put(field.getName(), new Object[]{value1, value2});
+                }
+            }
+            // 其他类型使用默认比较
+            else if (!Objects.equals(value1, value2)) {
                 diff.put(field.getName(), new Object[]{value1, value2});
             }
         }
@@ -263,5 +274,23 @@ public class FsStoreScrmServiceImpl implements IFsStoreScrmService
         return fsStoreMapper.selectFsAllStoreList();
     }
 
+    @Override
+    public List<Map<String, String>> getStoreColumns() {
+        List<Map<String, String> > list = fsStoreMapper.getStoreColumns();
+        List<Map<String, String>> result = new ArrayList<>();
+
+        for (Map<String, String> column : list) {
+            Map<String, String> camelCaseColumn = new HashMap<>();
+            String columnName = column.get("colName");
+            String camelCaseName = StringUtils.toCamelCase(columnName);
+            camelCaseColumn.put("colName", camelCaseName);
+            camelCaseColumn.put("colComment", column.get("colComment"));
+            result.add(camelCaseColumn);
+        }
+
+        return result;
+    }
+
+
 }