فهرست منبع

Merge branch 'dev' of xiongzhu/raex_back into master

阳泽剑 3 سال پیش
والد
کامیت
6f7bd93e33

+ 75 - 0
src/main/java/com/izouma/nineth/domain/Result.java

@@ -0,0 +1,75 @@
+package com.izouma.nineth.domain;
+
+import com.izouma.nineth.enums.SystemCode;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.formula.functions.T;
+
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.List;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class Result<T> {
+    //返回码
+    private int code;
+    //提示信息
+    private String msg;
+    //当前时候毫秒值
+    private String time;
+    // 返回对象
+    private List<T> data;
+
+
+    public static Result OK() {
+        return new Result(SystemCode.SUCCESS);
+    }
+
+
+    public static Result NO() {
+        return new Result(SystemCode.ERROR);
+    }
+
+
+    public void setMsgIsNUll(String msg) {
+        if (StringUtils.isBlank(getMsg())) {
+            setMsg(msg);
+        }
+    }
+
+
+    public void setCodeIsNUll(String code) {
+        if (ObjectUtils.isEmpty(getCode())) {
+            setMsg(code);
+        }
+    }
+
+
+    public void setSysCodeIsNUll(SystemCode sysCode) {
+        if (ObjectUtils.isEmpty(getCode())) {
+            setCode(sysCode.getCode());
+        }
+        if (StringUtils.isBlank(getMsg())) {
+            setMsg(sysCode.getMsg());
+        }
+    }
+
+    public Result(SystemCode sysCode) {
+        this.code = sysCode.getCode();
+        this.msg = sysCode.getMsg();
+    }
+
+    public void setSystemCode(SystemCode sysCode) {
+        this.code = sysCode.getCode();
+        this.msg = sysCode.getMsg();
+    }
+
+    public  Result<T> success(List<T> data){
+        return new Result<T>(SystemCode.SUCCESS.getCode(), SystemCode.SUCCESS.getMsg(),String.valueOf(LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"))),data);
+    }
+}

+ 17 - 0
src/main/java/com/izouma/nineth/dto/PriceListVo.java

@@ -0,0 +1,17 @@
+package com.izouma.nineth.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+public class PriceListVo {
+    private String name;
+    private String img;
+    private String price;
+    private String origin_price;
+}

+ 38 - 0
src/main/java/com/izouma/nineth/enums/SystemCode.java

@@ -0,0 +1,38 @@
+package com.izouma.nineth.enums;
+
+
+public enum SystemCode {
+
+    /**
+     * 操作成功
+     **/
+    SUCCESS(1, "SUCCESS"),
+    /**
+     * 操作失败
+     **/
+    ERROR(2, "ERROR"),
+    ;
+
+    /**
+     * 自定义状态码
+     **/
+    private int code;
+    /**
+     * 自定义描述
+     **/
+    private String message;
+
+    SystemCode(int code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return message;
+    }
+}
+

+ 12 - 0
src/main/java/com/izouma/nineth/repo/CollectionRepo.java

@@ -166,6 +166,18 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
             "and c.stock > 0 order by c.price limit 5) t", nativeQuery = true)
     String lowestPrice(String search);
 
+    @Query(value = "select c.original_price from collection_info c where c.name like ?1 " +
+            "and c.source = 'OFFICIAL' " +
+            "and c.original_price != null " +
+            "and c.stock > 0 order by c.original_price limit 1", nativeQuery = true)
+    String lowestOriginPrice(String search);
+
+    @Query(value = "select min(t.price) from (select c.price from collection_info c where c.name like ?1 " +
+            "and c.source = 'TRANSFER' " +
+            "and c.salable = true " +
+            "and c.stock > 0 order by c.price limit 5) t", nativeQuery = true)
+    String lowestPrices(String search);
+
     @Query("select c from Collection c join c.tags t on t.id = ?1 ")
     Page<Collection> byTag(Long tagId, Pageable pageable);
 

+ 1 - 0
src/main/java/com/izouma/nineth/security/WebSecurityConfig.java

@@ -129,6 +129,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/auctionRecord/all").permitAll()
                 .antMatchers("/ossNotify").permitAll()
                 .antMatchers("/priceList/list").permitAll()
+                .antMatchers("/priceList/priceListVo").permitAll()
                 .antMatchers("/user/collectionInvitorList").permitAll()
                 .antMatchers("/auth/oasisLogin").permitAll()
                 .antMatchers("/auth/oasisLoginPhone").permitAll()

+ 18 - 0
src/main/java/com/izouma/nineth/web/PriceListController.java

@@ -1,6 +1,8 @@
 package com.izouma.nineth.web;
 
 import com.izouma.nineth.domain.PriceList;
+import com.izouma.nineth.domain.Result;
+import com.izouma.nineth.dto.PriceListVo;
 import com.izouma.nineth.repo.CollectionRepo;
 import com.izouma.nineth.service.PriceListService;
 import com.izouma.nineth.dto.PageQuery;
@@ -17,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -87,5 +90,20 @@ public class PriceListController extends BaseController {
             return map;
         }).collect(Collectors.toList());
     }
+    @GetMapping("/priceListVo")
+    @Cacheable("priceList")
+    public Result<PriceListVo> priceList() {
+        ArrayList<PriceListVo> list = new ArrayList<>();
+        List<PriceList> priceLists = priceListRepo.findAll();
+        for (PriceList priceList : priceLists) {
+            list.add(new PriceListVo().builder()
+                    .name(priceList.getName())
+                    .img(priceList.getPic())
+                    .price(collectionRepo.lowestPrices(priceList.getSearch()))
+                    .origin_price(collectionRepo.lowestOriginPrice(priceList.getSearch()))
+                    .build());
+        }
+         return Result.OK().success(list);
+    }
 }