王先生 2 gadi atpakaļ
vecāks
revīzija
8b29bb9f30

+ 52 - 0
eladmin-common/src/main/java/me/zhengjie/utils/BigDecimalSerializer.java

@@ -0,0 +1,52 @@
+/**
+ * Copyright (C), 2022-07-01
+ * FileName: BigDecimalSerializer
+ * Author:   wanglongda
+ * Date:     2022/7/1 14:22
+ * Description: 金钱序列话
+ */
+package me.zhengjie.utils;/**
+ * Created Name: wanglongda
+ * Created Time: 2022/7/1 14:22
+ * Description: iot-zhcy
+ */
+
+import com.alibaba.fastjson.serializer.JSONSerializer;
+import com.alibaba.fastjson.serializer.SerializeWriter;
+import com.alibaba.fastjson.serializer.ToStringSerializer;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ObjectUtils;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+
+/**
+ * <功能简要> <br>
+ * <金钱序列化>
+ *
+ * @Author wanglongda
+ * @createTime 2022/7/1 14:22
+ * @Version 1.0.0
+ */
+
+@Component
+public class BigDecimalSerializer extends JsonSerializer<BigDecimal> {
+
+    public static final BigDecimalSerializer instance = new BigDecimalSerializer();
+
+    public BigDecimalSerializer() {
+    }
+
+    @Override
+    public void serialize(BigDecimal bigDecimal, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
+        if (!ObjectUtils.isEmpty(bigDecimal)){
+            BigDecimal number = bigDecimal.setScale(2,BigDecimal.ROUND_HALF_EVEN);
+            jsonGenerator.writeNumber(number);
+        } else {
+            jsonGenerator.writeNumber(bigDecimal);
+        }
+    }
+}

+ 3 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/food/domain/DmFood.java

@@ -15,6 +15,7 @@
 */
 package me.zhengjie.modules.dm.food.domain;
 
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import lombok.Data;
 import cn.hutool.core.bean.BeanUtil;
 import io.swagger.annotations.ApiModelProperty;
@@ -22,6 +23,7 @@ import cn.hutool.core.bean.copier.CopyOptions;
 import me.zhengjie.base.BaseEntity;
 import me.zhengjie.domain.LocalStorage;
 import me.zhengjie.modules.dm.foodCate.domain.DmFoodCate;
+import me.zhengjie.utils.BigDecimalSerializer;
 import me.zhengjie.utils.SecurityUtils;
 import org.springframework.security.core.userdetails.UserDetails;
 
@@ -58,6 +60,7 @@ public class DmFood extends BaseEntity implements Serializable {
 
     @Column(name = "price",nullable = false)
     @ApiModelProperty(value = "单价")
+    @JsonSerialize(using = BigDecimalSerializer.class)
     private BigDecimal price;
 
     @Column(name = "picture")

+ 3 - 0
eladmin-system/src/main/java/me/zhengjie/modules/dm/food/service/dto/DmFoodDto.java

@@ -15,6 +15,7 @@
 */
 package me.zhengjie.modules.dm.food.service.dto;
 
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import lombok.Data;
 import java.sql.Timestamp;
 import java.math.BigDecimal;
@@ -24,6 +25,7 @@ import com.alibaba.fastjson.serializer.ToStringSerializer;
 import me.zhengjie.base.BaseDTO;
 import me.zhengjie.domain.LocalStorage;
 import me.zhengjie.modules.dm.foodCate.domain.DmFoodCate;
+import me.zhengjie.utils.BigDecimalSerializer;
 
 /**
 * @website https://el-admin.vip
@@ -50,6 +52,7 @@ public class DmFoodDto extends BaseDTO implements Serializable {
     private String cateName;
 
     /** 单价 */
+    @JsonSerialize(using = BigDecimalSerializer.class)
     private BigDecimal price;
 
     /** 图片 */

+ 8 - 8
eladmin-system/src/main/java/me/zhengjie/modules/dm/statement/repository/DmHaveDinnerRepository.java

@@ -12,38 +12,38 @@ public interface DmHaveDinnerRepository extends JpaRepository<DmHaveDinner,Integ
      */
     @Transactional
     @Modifying
-    @Query(value = "DROP VIEW IF EXISTS `zgmonth`",nativeQuery = true)
+    @Query(value = "DROP VIEW IF \\EXISTS `zgmonth`",nativeQuery = true)
     void dropByZgMonth();
     @Transactional
     @Modifying
-    @Query(value = "DROP VIEW IF EXISTS `zdmonth`",nativeQuery = true)
+    @Query(value = "DROP VIEW IF \\EXISTS `zdmonth`",nativeQuery = true)
     void dropByZdMonth();
 
     @Transactional
     @Modifying
-    @Query(value = "DROP VIEW IF EXISTS zgyear",nativeQuery = true)
+    @Query(value = "DROP VIEW IF \\EXISTS zgyear",nativeQuery = true)
     void dropByZgYear();
     @Transactional
     @Modifying
-    @Query(value = "DROP VIEW if IF EXISTS zdyear",nativeQuery = true)
+    @Query(value = "DROP VIEW  IF \\EXISTS zdyear",nativeQuery = true)
     void dropByZdYear();
 
     @Transactional
     @Modifying
-    @Query(value = "DROP VIEW if IF EXISTS `zgday`",nativeQuery = true)
+    @Query(value = "DROP VIEW  IF \\EXISTS `zgday`",nativeQuery = true)
     void dropByZgDay();
     @Transactional
     @Modifying
-    @Query(value = "DROP VIEW IF EXISTS `zdday`",nativeQuery = true)
+    @Query(value = "DROP VIEW IF \\EXISTS `zdday`",nativeQuery = true)
     void dropByZdDay();
 
     @Transactional
     @Modifying
-    @Query(value = "DROP VIEW IF EXISTS `zgweek`",nativeQuery = true)
+    @Query(value = "DROP VIEW IF \\EXISTS `zgweek`",nativeQuery = true)
     void dropByZgWeek();
     @Transactional
     @Modifying
-    @Query(value = "DROP VIEW IF EXISTS `zdweek`",nativeQuery = true)
+    @Query(value = "DROP VIEW IF \\EXISTS `zdweek`",nativeQuery = true)
     void dropByZdWeek();
 
     /**