Procházet zdrojové kódy

字段类型修改

hl před 1 rokem
rodič
revize
fba697e0bf

+ 2 - 1
basic/src/main/java/com/liangjiang/basic/controller/BasicController.java

@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 基础服务数据接口
@@ -35,7 +36,7 @@ public class BasicController {
      * @param params 条件参数
      */
     @RequestMapping(value = "/getDealRecords", method = RequestMethod.POST)
-    public List<DealRecords> getDealRecords(@Valid @RequestBody QueryDealRecordsParams params) {
+    public Map<String,List<DealRecords>> getDealRecords(@Valid @RequestBody QueryDealRecordsParams params) {
         return this.basicService.getDealRecordsByParams(params);
     }
 }

+ 11 - 5
basic/src/main/java/com/liangjiang/basic/domain/bo/QueryDealRecordsParams.java

@@ -4,7 +4,9 @@ import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
-import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
 
 /**
  * 查询交易记录列表参数
@@ -15,10 +17,14 @@ import javax.validation.constraints.NotBlank;
 @NoArgsConstructor
 @AllArgsConstructor
 public class QueryDealRecordsParams {
-    @NotBlank(message = "开始时间不能为空!")
-    private String beginTime;
-    @NotBlank(message = "结束时间不能为空!")
-    private String endTime;
+    @Min(value = 1601922334L, message = "开始时间错误")
+    @Max(value = 9222222222222L, message = "开始时间错误")
+    @NotNull(message = "开始时间(时间戳秒)不能为空!")
+    private Long beginTime;
+    @Min(value = 1601922334L, message = "结束时间错误")
+    @Max(value = 9222222222222L, message = "结束时间错误")
+    @NotNull(message = "结束时间(时间戳秒)不能为空!")
+    private Long endTime;
     // 机器名称
     private String robotName;
 }

+ 4 - 9
basic/src/main/java/com/liangjiang/basic/domain/entity/DealRecords.java

@@ -4,16 +4,13 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
-import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
-import org.springframework.format.annotation.DateTimeFormat;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
-import java.util.Date;
 
 /**
  * 交易记录
@@ -35,24 +32,22 @@ public class DealRecords implements Serializable {
      * 参考价
      */
     @TableField("ref_price")
-    private BigDecimal refPrice;
+    private String refPrice;
     /**
      * 挂单价
      */
     @TableField("reg_price")
-    private BigDecimal regPrice;
+    private String regPrice;
     /**
      * 数量
      */
     @TableField("num")
-    private BigDecimal num;
+    private String num;
     /**
      * 触发时间
      */
     @TableField("trigger_time")
-    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSS")
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSS")
-    private Date triggerTime;
+    private Long triggerTime;
     /**
      * 机器名称
      */

+ 3 - 0
basic/src/main/java/com/liangjiang/basic/mapper/DealRecordsMapper.java

@@ -16,6 +16,9 @@ import java.util.List;
 public interface DealRecordsMapper extends BaseMapper<DealRecords> {
 
     List<DealRecords> queryDealRecords(QueryDealRecordsParams params);
+    List<DealRecords> queryDealRecordsByRef(QueryDealRecordsParams params);
+    List<DealRecords> queryDealRecordsByReg(QueryDealRecordsParams params);
+
 
 
 }

+ 2 - 1
basic/src/main/java/com/liangjiang/basic/service/IBasicService.java

@@ -4,6 +4,7 @@ import com.liangjiang.basic.domain.bo.QueryDealRecordsParams;
 import com.liangjiang.basic.domain.entity.DealRecords;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 交易记录业务接口
@@ -22,6 +23,6 @@ public interface IBasicService {
      * @param params 条件参数
      * @return
      */
-    List<DealRecords> getDealRecordsByParams(QueryDealRecordsParams params);
+    Map<String,List<DealRecords>> getDealRecordsByParams(QueryDealRecordsParams params);
 
 }

+ 2 - 0
basic/src/main/java/com/liangjiang/basic/service/IDealRecordsService.java

@@ -8,4 +8,6 @@ import java.util.List;
 
 public interface IDealRecordsService extends IService<DealRecords> {
     List<DealRecords> queryDealRecords(QueryDealRecordsParams params);
+    List<DealRecords> queryDealRecordsByRef(QueryDealRecordsParams params);
+    List<DealRecords> queryDealRecordsByReg(QueryDealRecordsParams params);
 }

+ 13 - 2
basic/src/main/java/com/liangjiang/basic/service/impl/BasicServiceImpl.java

@@ -7,7 +7,9 @@ import com.liangjiang.basic.service.IDealRecordsService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 交易记录业务接口实现
@@ -28,7 +30,16 @@ public class BasicServiceImpl implements IBasicService {
     }
 
     @Override
-    public List<DealRecords> getDealRecordsByParams(QueryDealRecordsParams params){
-        return dealRecordsService.queryDealRecords(params);
+    public Map<String,List<DealRecords>> getDealRecordsByParams(QueryDealRecordsParams params){
+        Map<String,List<DealRecords>> map =  new HashMap<>();
+
+        params.setBeginTime(params.getBeginTime()*1000L);
+        params.setEndTime(params.getEndTime()*1000L);
+
+        List<DealRecords> ref =  dealRecordsService.queryDealRecordsByRef(params);
+        List<DealRecords> reg =  dealRecordsService.queryDealRecordsByReg(params);
+        map.put("ref",ref);
+        map.put("reg",reg);
+        return map;
     }
 }

+ 15 - 0
basic/src/main/java/com/liangjiang/basic/service/impl/DealRecordsServiceImpl.java

@@ -17,7 +17,22 @@ public class DealRecordsServiceImpl extends ServiceImpl<DealRecordsMapper, DealR
 
     @Override
     public List<DealRecords> queryDealRecords(QueryDealRecordsParams params) {
+        params.setBeginTime(params.getBeginTime()*1000L);
+        params.setEndTime(params.getEndTime()*1000L);
         List<DealRecords> records = dealRecordsMapper.queryDealRecords(params);
         return records;
     }
+
+    @Override
+    public List<DealRecords> queryDealRecordsByRef(QueryDealRecordsParams params) {
+
+        List<DealRecords> records = dealRecordsMapper.queryDealRecordsByRef(params);
+        return records;
+    }
+
+    @Override
+    public List<DealRecords> queryDealRecordsByReg(QueryDealRecordsParams params) {
+        List<DealRecords> records = dealRecordsMapper.queryDealRecordsByReg(params);
+        return records;
+    }
 }

+ 39 - 1
basic/src/main/resources/mapper/DealRecordsMapper.xml

@@ -14,10 +14,48 @@
         FROM
             deal_records d
         where
-            d.trigger_time BETWEEN #{beginTime} AND #{endTime}
+            d.trigger_time BETWEEN ${beginTime} AND ${endTime}
             <if test="robotName != null and robotName != ''">
                 and d.robot_name = #{robotName}
             </if>
         order by d.id asc
     </select>
+
+    <!-- 查询交易记录 -refPrice -->
+    <select id="queryDealRecordsByRef" resultType="com.liangjiang.basic.domain.entity.DealRecords" parameterType="com.liangjiang.basic.domain.bo.QueryDealRecordsParams">
+        SELECT
+            d.id,
+            d.num,
+            d.ref_price refPrice,
+            d.robot_name robotName,
+            d.side,
+            d.trigger_time triggerTime
+        FROM
+        deal_records d
+        where
+        d.trigger_time BETWEEN ${beginTime} AND ${endTime}
+        <if test="robotName != null and robotName != ''">
+            and d.robot_name = #{robotName}
+        </if>
+        order by d.id asc
+    </select>
+
+    <!-- 查询交易记录 -regPrice -->
+    <select id="queryDealRecordsByReg" resultType="com.liangjiang.basic.domain.entity.DealRecords" parameterType="com.liangjiang.basic.domain.bo.QueryDealRecordsParams">
+        SELECT
+        d.id,
+        d.num,
+        d.reg_price regPrice,
+        d.robot_name robotName,
+        d.side,
+        d.trigger_time triggerTime
+        FROM
+        deal_records d
+        where
+        d.trigger_time BETWEEN ${beginTime} AND ${endTime}
+        <if test="robotName != null and robotName != ''">
+            and d.robot_name = #{robotName}
+        </if>
+        order by d.id asc
+    </select>
 </mapper>

+ 5 - 4
basic/src/test/java/com/liangjiang/basic/BasicTest.java

@@ -16,6 +16,7 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @Author hellor
@@ -31,8 +32,8 @@ public class BasicTest {
     public void save() throws ParseException {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSS");
         Date date = sdf.parse("2023-12-07 12:12:12.1585");
-        DealRecords dealRecords = new DealRecords(null, new BigDecimal("123.5156"),
-                new BigDecimal("123.5056"), new BigDecimal("1.5754"), date, "rust1", "kk");
+        DealRecords dealRecords = new DealRecords(null, "123.5156",
+                "123.5056","1.5754", date.getTime(), "rust1", "kk");
         List<DealRecords> list= new ArrayList<>();
         list.add(dealRecords);
         basicService.saveDealRecords(list);
@@ -40,8 +41,8 @@ public class BasicTest {
 
     @Test
     public void query() {
-        QueryDealRecordsParams params = new QueryDealRecordsParams("2023-12-07 00:00:00", "2023-12-07 22:22:22", null);
-        List<DealRecords> records = basicService.getDealRecordsByParams(params);
+        QueryDealRecordsParams params = new QueryDealRecordsParams(1701922332L, 1701922336L, null);
+        Map<String,List<DealRecords>> records = basicService.getDealRecordsByParams(params);
         System.out.println(records);
     }