Browse Source

fix poster

guozhaoshun 6 năm trước cách đây
mục cha
commit
b1444f5476

+ 5 - 1
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/product/PosterController.java

@@ -6,10 +6,12 @@ import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.common.utils.util.BeanUtil;
 import cn.rankin.data.api.product.dto.PosterDTO;
 import cn.rankin.data.api.product.entity.Poster;
+import cn.rankin.data.api.product.vo.RecommendVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.util.List;
 
 @RestController
 @RequestMapping(value = "/poster")
@@ -19,7 +21,7 @@ public class PosterController {
     private PosterServiceInterface posterServiceInterface;
 
     @RequestMapping(value = "/list", method = RequestMethod.GET)
-    public APIResult<Page<Poster>> getPosterList(PosterDTO posterDTO) {
+    public APIResult<List<Poster>> getPosterList(PosterDTO posterDTO) {
         return posterServiceInterface.search(BeanUtil.convertToMap(posterDTO));
     }
 
@@ -42,4 +44,6 @@ public class PosterController {
     public APIResult delete(@PathVariable("id") String id) {
         return posterServiceInterface.delete(id);
     }
+
+
 }

+ 16 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/MerchantController.java

@@ -1,9 +1,11 @@
 package cn.rankin.cmsweb.controller.user;
 
+import cn.rankin.cmsweb.service.product.PosterServiceInterface;
 import cn.rankin.cmsweb.service.product.RecommendService;
 import cn.rankin.cmsweb.service.user.MerchantService;
 import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.common.utils.api.page.Page;
+import cn.rankin.data.api.product.entity.Poster;
 import cn.rankin.data.api.product.vo.RecommendVo;
 import cn.rankin.data.api.user.dto.MerchantDTO;
 import cn.rankin.data.api.user.dto.MerchantSearchDTO;
@@ -25,6 +27,9 @@ public class MerchantController {
     @Autowired
     private RecommendService recommendService;
 
+    @Autowired
+    private PosterServiceInterface posterServiceInterface;
+
     @RequestMapping(value = {"", "/list"}, method = RequestMethod.GET)
     public APIResult<Page<MerchantVo>> getPage(MerchantSearchDTO searchDTO) {
         return merchantService.search(BeanUtil.convertToMap(searchDTO));
@@ -61,4 +66,15 @@ public class MerchantController {
         return recommendService.put(merchantId, recommendIdList);
     }
 
+    //海报设置
+    @RequestMapping(value = "/poster/{merchantId}", method = RequestMethod.GET)
+    public APIResult<List<Poster>> getPoster(@PathVariable("merchantId") String merchantId) {
+        return posterServiceInterface.getPosters(merchantId);
+    }
+
+    @RequestMapping(value = "/poster/{merchantId}", method = RequestMethod.PUT)
+    public APIResult<List<Poster>> updatePoster(@PathVariable("merchantId") String merchantId, @RequestBody List<String> posterIdList) {
+        return posterServiceInterface.updatePosters(merchantId, posterIdList);
+    }
+
 }

+ 9 - 1
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/product/PosterServiceInterface.java

@@ -8,13 +8,14 @@ import org.springframework.cloud.netflix.feign.FeignClient;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.util.List;
 import java.util.Map;
 
 @FeignClient(name = "${service.product.name}")
 public interface PosterServiceInterface {
 
     @RequestMapping(value = "/poster/list", method = RequestMethod.GET)
-    APIResult<Page<Poster>> search(@RequestParam Map<String, Object> searchDTO);
+    APIResult<List<Poster>> search(@RequestParam Map<String, Object> searchDTO);
 
     @RequestMapping(value = "/poster/{id}", method = RequestMethod.GET)
     APIResult<Poster> getPoster(@PathVariable("id") String id);
@@ -27,4 +28,11 @@ public interface PosterServiceInterface {
 
     @RequestMapping(value = "/poster/{id}", method = RequestMethod.DELETE)
     APIResult delete(@PathVariable("id") String id);
+
+    @RequestMapping(value = "/poster/updatePosters/{merchantId}", method = RequestMethod.PUT)
+    APIResult<List<Poster>> updatePosters(@RequestParam("merchantId") String merchantId,
+                                         @RequestBody List<String> posterIdList);
+
+    @RequestMapping(value = "/poster/getPosters/{merchantId}", method = RequestMethod.GET)
+    APIResult<List<Poster>> getPosters(@RequestParam("merchantId") String merchantId);
 }

+ 45 - 40
rankin-product-service/src/main/java/cn/rankin/productservice/controller/PosterController.java

@@ -2,7 +2,6 @@ package cn.rankin.productservice.controller;
 
 import cn.rankin.common.utils.api.model.APICode;
 import cn.rankin.common.utils.api.model.APIResult;
-import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.common.utils.enums.BaseOrderEnum;
 import cn.rankin.data.api.product.dto.PosterDTO;
 import cn.rankin.data.api.product.entity.*;
@@ -17,7 +16,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
 import java.util.LinkedHashMap;
-import java.util.Map;
+import java.util.List;
 
 @Slf4j
 @RestController
@@ -28,42 +27,29 @@ public class PosterController {
     private PosterService posterService;
 
     @Autowired
-    private ProductService productService;
-
-    @Autowired
     private ProductRepository productRepository;
 
     @RequestMapping(value = "/list", method = RequestMethod.GET)
-    public APIResult<Page<Poster>> search(PosterDTO searchDTO) {
+    public APIResult<List<Poster>> search(PosterDTO searchDTO) {
         Poster poster = new Poster();
 
-/*        String code = searchDTO.getCode();
-        if (!StringUtils.isEmpty(code)) {
-            lesson.setCode("%" + code + "%");
-        }
-
-        String name = searchDTO.getName();
-        if (!StringUtils.isEmpty(name)) {
-            lesson.setTitle("%" + name + "%");
-        }*/
-
         poster.setStatus(searchDTO.getStatus());
         poster.setMerchantId(searchDTO.getMerchantId());
         poster.setPid(searchDTO.getPid());
-        poster.setStatus(searchDTO.getStatus());
         // sort
         LinkedHashMap<String, BaseOrderEnum> sort = new LinkedHashMap() { {
             this.put("gmtModified", BaseOrderEnum.DESC);
         }};
 
-        Page<Poster> posterPage = posterService.search(poster, searchDTO.getPageNo(), searchDTO.getPageSize(), sort);
-
-        return APIResult.ok(posterPage);
+        List<Poster> posters = posterService.search(poster , sort);
+        posters.forEach(entity ->{
+            setProductInfo(entity);
+        } );
+        return APIResult.ok(posters);
     }
 
     @RequestMapping(value = "/{id}", method = RequestMethod.GET)
     public APIResult<Poster> getPoster(@PathVariable("id") String id) {
-
         if (StringUtils.isEmpty(id)) {
             return APIResult.error(APICode.PARAMETER_ERROR);
         }
@@ -73,15 +59,8 @@ public class PosterController {
             return APIResult.error(APICode.NOT_EXISTS);
         }
 
-
-//        Product product = productService.find(result.getPid());
-        Product product = productRepository.findByPid(result.getPid());
-        result.setProduct(product);
-
-
-
+        setProductInfo(result);
         return APIResult.ok(result);
-
     }
 
     @Transactional
@@ -93,6 +72,7 @@ public class PosterController {
             if (null == result) {
                 return APIResult.error(APICode.OPERATE_ERROR);
             }
+            setProductInfo(result);
             return APIResult.ok(result);
         }catch(Exception e){
             log.info("poster create error: message={}",e.getMessage());
@@ -109,22 +89,12 @@ public class PosterController {
             return APIResult.error(APICode.error("参数错误: id不能为空"));
         }
 
-/*        List<String> wareIdList = lessonDTO.getWareList();
-        List<CourseWare> courseWareList = new ArrayList<>();
-        if (wareIdList != null) {
-            APIResult<List<CourseWare>> wareResult = updateRelation(Id, wareIdList);
-            if (!wareResult.getSuccess()) {
-                return APIResult.error(new BaseCode(wareResult.getCode(), wareResult.getMessage()));
-            }else {
-                courseWareList = wareResult.getData();
-            }
-        }*/
-
         Poster result = posterService.update(posterDTO);
         if (null == result) {
             return APIResult.error(APICode.OPERATE_ERROR);
         }
 
+        setProductInfo(result);
         return APIResult.ok(result);
     }
 
@@ -137,4 +107,39 @@ public class PosterController {
             return APIResult.error(ProductServiceAPICode.error("删除失败"));
         }
     }
+
+    @RequestMapping(value = "/updatePosters/{merchantId}", method = RequestMethod.PUT)
+    public APIResult<List<Poster>> updatePosters(@RequestParam("merchantId") String merchantId,
+                                          @RequestBody List<String> posterIdList){
+        List<Poster> posters = posterService.updatePosters(merchantId, posterIdList);
+
+        posters.forEach(poster ->{
+            setProductInfo(poster);
+        });
+        return APIResult.ok(posters);
+    }
+
+    @RequestMapping(value = "/getPosters/{merchantId}", method = RequestMethod.GET)
+    public APIResult<List<Poster>> getPosters(@RequestParam("merchantId") String merchantId){
+        List<Poster> posters = posterService.getByMerchantId(merchantId);
+
+        posters.forEach(poster ->{
+            setProductInfo(poster);
+        });
+        return APIResult.ok(posters);
+    }
+
+    /**
+     * 组装产品信息
+     * @param poster
+     */
+    private void setProductInfo(Poster poster) {
+        if(null == poster){
+            return ;
+        }
+        Product product = productRepository.findByPid(poster.getPid());
+        poster.setProduct(product);
+    }
+
+
 }

+ 6 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/repository/PosterRepository.java

@@ -22,5 +22,11 @@ public interface PosterRepository extends BasicJpaRepository<Poster, String> {
     @Modifying
     @Query(value = "update Poster p set p.status = 1 where p.id = ?1")
     Integer deleteById(String id);
+
+    @Query(value = "select p from Poster p where p.merchantId = ?1 and p.status = ?2")
+    List<Poster> findByStatus(String merchantId, BaseStatusEnum normal);
+
+    @Query(value = "select p from Poster p where p.merchantId = ?1 ")
+    List<Poster> findByMerchantId(String merchantId);
 }
 

+ 33 - 18
rankin-product-service/src/main/java/cn/rankin/productservice/service/PosterService.java

@@ -1,6 +1,5 @@
 package cn.rankin.productservice.service;
 
-import cn.rankin.common.utils.api.page.Page;
 import cn.rankin.common.utils.enums.BaseOrderEnum;
 import cn.rankin.common.utils.enums.BaseStatusEnum;
 import cn.rankin.common.utils.util.JpaSortUtil;
@@ -13,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
@@ -47,18 +47,15 @@ public class PosterService {
         return sortPosterList;
     }
 
-    public Page<Poster> search(Poster poster, Integer pageNo, Integer pageSize, LinkedHashMap<String, BaseOrderEnum> sort) {
+    public List<Poster> search(Poster poster, LinkedHashMap<String, BaseOrderEnum> sort) {
         Long count = posterRepository.count(poster);
-        Page<Poster> page = new Page(count, pageNo, pageSize);
 
         if (count == 0) {
-            return page;
+            return new ArrayList<>();
         }
 
-        List<Poster> posterList = posterRepository.find(poster, page.getStart(), pageSize, JpaSortUtil.sort(sort));
-        page.setList(posterList);
-
-        return page;
+        List<Poster> posterList = posterRepository.find(poster, JpaSortUtil.sort(sort));
+        return posterList;
     }
 
     public Poster findById(String id) {
@@ -66,18 +63,8 @@ public class PosterService {
         return poster;
     }
 
-/*    public boolean exists(String code) {
-        Long count = posterRepository.countByCode(code);
-        return count > 0L;
-    }*/
-
     @Transactional
     public Poster create(PosterDTO posterDTO) {
-        /*String code = lessonDTO.getCode();
-        if (exists(code)) {
-            return APIResult.error(APICode.ALREADY_EXISTS);
-        }*/
-
         Poster poster = convert(posterDTO);
         Poster result = posterRepository.save(poster);
 
@@ -101,4 +88,32 @@ public class PosterService {
         return false;
     }
 
+    public List<Poster> getByMerchantId(String merchantId) {
+        List<Poster> posterList = posterRepository.findByStatus(merchantId, BaseStatusEnum.NORMAL);
+        if (CollectionUtils.isEmpty(posterList)) {
+            return new ArrayList<>();
+        }
+
+        return posterList;
+    }
+
+    public List<Poster> updatePosters(String merchantId, List<String> posterIdList) {
+        if (CollectionUtils.isEmpty(posterIdList)) {
+            return null;
+        }
+
+        List<Poster> posterList = posterRepository.findByStatus(merchantId, BaseStatusEnum.NORMAL);
+
+        // 排序
+        posterList.forEach( poster -> {
+//            String productId = poster.getPid();
+            Integer sort = posterIdList.indexOf(poster.getId());
+            poster.setSort(sort);
+        });
+
+        posterRepository.save(posterList);
+        List<Poster> result = posterRepository.findByStatus(merchantId, BaseStatusEnum.NORMAL);
+        return result;
+    }
+
 }