فهرست منبع

地板价查询

xiongzhu 4 سال پیش
والد
کامیت
b61603a1ce

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

@@ -122,6 +122,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/hmpay/**").permitAll()
                 .antMatchers("/order/calcSettle").permitAll()
                 .antMatchers("/ossNotify").permitAll()
+                .antMatchers("/priceList/list").permitAll()
                 // all other requests need to be authenticated
                 .anyRequest().authenticated().and()
                 // make sure we use stateless session; session won't be used to

+ 4 - 0
src/main/java/com/izouma/nineth/service/CacheService.java

@@ -104,4 +104,8 @@ public class CacheService {
     @CacheEvict(value = "orderPriceTrendV2", allEntries = true)
     public void clearOrderPriceTrendV2() {
     }
+
+    @CacheEvict(value = "priceList", allEntries = true)
+    public void clearPriceList() {
+    }
 }

+ 2 - 0
src/main/java/com/izouma/nineth/service/PriceListService.java

@@ -18,6 +18,7 @@ public class PriceListService {
 
     private PriceListRepo  priceListRepo;
     private CollectionRepo collectionRepo;
+    private CacheService   cacheService;
 
     public Page<PriceList> all(PageQuery pageQuery) {
         return priceListRepo.findAll(JpaUtils.toSpecification(pageQuery, PriceList.class), JpaUtils.toPageRequest(pageQuery));
@@ -25,6 +26,7 @@ public class PriceListService {
 
     @Scheduled(initialDelay = 1, fixedRate = 5, timeUnit = TimeUnit.MINUTES)
     public void schedule() {
+        cacheService.clearPriceList();
         for (PriceList priceList : priceListRepo.findAll()) {
             priceList.setPrice(collectionRepo.lowestPrice(priceList.getSearch()).stripTrailingZeros().toPlainString());
             priceListRepo.save(priceList);

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

@@ -9,13 +9,17 @@ import com.izouma.nineth.repo.PriceListRepo;
 import com.izouma.nineth.utils.ObjUtils;
 import com.izouma.nineth.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 @RestController
 @RequestMapping("/priceList")
@@ -64,5 +68,17 @@ public class PriceListController extends BaseController {
         List<PriceList> data = all(pageQuery).getContent();
         ExcelUtils.export(response, data);
     }
+
+    @GetMapping("/list")
+    @Cacheable("priceList")
+    public List<Map<String, String>> list() {
+        return priceListRepo.findAll().stream().map(priceList -> {
+            Map<String, String> map = new HashMap<>();
+            map.put("name", priceList.getName());
+            map.put("img", priceList.getPic());
+            map.put("price", priceList.getPrice());
+            return map;
+        }).collect(Collectors.toList());
+    }
 }