|
|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|