3
0

7 Commity 33f4ed14cc ... 1a88c54723

Autor SHA1 Správa Dátum
  guozhaoshun 1a88c54723 fix tag support update typeCode,merchant; 6 rokov pred
  guozhaoshun 7d2928ebf6 fix poster 6 rokov pred
  guozhaoshun c8a3defbf6 fix poster 6 rokov pred
  guozhaoshun fef1be4ad4 fix saveRemoteResource 6 rokov pred
  guozhaoshun 2232e69783 fix poster 6 rokov pred
  guozhaoshun d64df3cd1d fix poster 6 rokov pred
  guozhaoshun c6323af106 Merge branch 'dev001' 6 rokov pred

+ 44 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/product/PosterController.java

@@ -0,0 +1,44 @@
+package cn.rankin.cmsweb.controller.product;
+
+import cn.rankin.cmsweb.service.product.PosterServiceInterface;
+import cn.rankin.common.utils.api.model.APIResult;
+import cn.rankin.common.utils.api.page.Page;
+import cn.rankin.data.api.product.dto.PosterDTO;
+import cn.rankin.data.api.product.entity.Poster;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+
+@RestController
+@RequestMapping(value = "/poster")
+public class PosterController {
+
+    @Autowired
+    private PosterServiceInterface posterServiceInterface;
+
+    @RequestMapping(value = "/list", method = RequestMethod.GET)
+    public APIResult<Page<Poster>> getPosterList(@Valid @RequestBody  PosterDTO posterDTO) {
+        return posterServiceInterface.search(posterDTO);
+    }
+
+    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
+    public APIResult<Poster> getPoster(@PathVariable("id") String id) {
+        return posterServiceInterface.getPoster(id);
+    }
+
+    @RequestMapping(method = RequestMethod.POST)
+    public APIResult<Poster> create(@Valid @RequestBody PosterDTO posterDTO) {
+        return posterServiceInterface.create(posterDTO);
+    }
+
+    @RequestMapping(method = RequestMethod.PUT)
+    public APIResult<Poster> update(@Valid @RequestBody PosterDTO posterDTO) {
+        return posterServiceInterface.update(posterDTO);
+    }
+
+    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
+    public APIResult delete(@PathVariable("id") String id) {
+        return posterServiceInterface.delete(id);
+    }
+}

+ 29 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/product/PosterServiceInterface.java

@@ -0,0 +1,29 @@
+package cn.rankin.cmsweb.service.product;
+
+import cn.rankin.common.utils.api.model.APIResult;
+import cn.rankin.common.utils.api.page.Page;
+import cn.rankin.data.api.product.dto.PosterDTO;
+import cn.rankin.data.api.product.entity.Poster;
+import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+
+@FeignClient(name = "${service.product.name}")
+public interface PosterServiceInterface {
+
+    @RequestMapping(value = "/poster/list", method = RequestMethod.GET)
+    APIResult<Page<Poster>> search(@Valid @RequestBody  PosterDTO searchDTO);
+
+    @RequestMapping(value = "/poster/{id}", method = RequestMethod.GET)
+    APIResult<Poster> getPoster(@PathVariable("id") String id);
+
+    @RequestMapping(value = "/poster", method = RequestMethod.POST)
+    APIResult<Poster> create(@RequestBody PosterDTO posterDTO);
+
+    @RequestMapping(value = "/poster", method = RequestMethod.PUT)
+    APIResult<Poster> update(@RequestBody PosterDTO posterDTO);
+
+    @RequestMapping(value = "/poster/{id}", method = RequestMethod.DELETE)
+    APIResult delete(@PathVariable("id") String id);
+}

+ 40 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/product/dto/PosterDTO.java

@@ -0,0 +1,40 @@
+package cn.rankin.data.api.product.dto;
+
+import cn.rankin.common.utils.enums.BaseStatusEnum;
+import cn.rankin.common.utils.enums.ProductTypeEnum;
+import cn.rankin.data.api.product.entity.Product;
+import cn.rankin.data.api.user.entity.Merchant;
+import lombok.Data;
+import lombok.ToString;
+
+import java.io.Serializable;
+import java.util.Map;
+
+@Data
+@ToString
+public class PosterDTO implements Serializable {
+
+    private String id;
+
+    private String merchantId;
+
+    private String pid;
+
+    private String img;
+
+    private Integer sort;
+
+    private ProductTypeEnum type;
+
+    private BaseStatusEnum status;
+
+    private Integer pageNo = 1;
+
+    private Integer pageSize = 10;
+
+    private Product product;
+
+    private Merchant merchant;
+
+}
+

+ 10 - 1
rankin-data-api/src/main/java/cn/rankin/data/api/product/entity/Poster.java

@@ -2,6 +2,7 @@ package cn.rankin.data.api.product.entity;
 
 import cn.rankin.common.utils.enums.BaseStatusEnum;
 import cn.rankin.common.utils.enums.ProductTypeEnum;
+import cn.rankin.data.api.user.entity.Merchant;
 import lombok.Data;
 import lombok.ToString;
 import org.hibernate.annotations.DynamicInsert;
@@ -10,11 +11,12 @@ import org.hibernate.annotations.DynamicUpdate;
 import javax.persistence.*;
 import java.io.Serializable;
 import java.util.Date;
+import java.util.Map;
 
 @Data
 @ToString
 @Entity
-@Table(name = "p_posters")
+@Table(name = "p_posters",uniqueConstraints = {@UniqueConstraint(columnNames = {"merchant_id", "pid"})})
 @DynamicInsert
 @DynamicUpdate
 public class Poster implements Serializable {
@@ -41,6 +43,7 @@ public class Poster implements Serializable {
     @Enumerated(EnumType.ORDINAL)
     private ProductTypeEnum type;
 
+    @Column(nullable = false)
     @Enumerated(EnumType.ORDINAL)
     private BaseStatusEnum status;
 
@@ -52,5 +55,11 @@ public class Poster implements Serializable {
     @Temporal(TemporalType.TIMESTAMP)
     private Date gmtModified;
 
+    @Transient
+    private Product product;
+
+    @Transient
+    private Merchant merchant;
+
 }
 

+ 1 - 1
rankin-data-api/src/main/java/cn/rankin/data/api/product/entity/Tag.java

@@ -31,7 +31,7 @@ public class Tag implements Serializable {
     @Column(name = "group_id", updatable = false, nullable = false)
     private String groupId;
 
-    @Column(name = "type_code", updatable = false, nullable = false)
+    @Column(name = "type_code", nullable = false)
     private String typeCode;
 
     @Column

+ 41 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/product/vo/PosterVo.java

@@ -0,0 +1,41 @@
+package cn.rankin.data.api.product.vo;
+
+import cn.rankin.common.utils.enums.BaseStatusEnum;
+import cn.rankin.common.utils.enums.ProductTypeEnum;
+import cn.rankin.data.api.product.entity.Product;
+import cn.rankin.data.api.user.entity.Merchant;
+import lombok.Data;
+import lombok.ToString;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+@ToString
+public class PosterVo implements Serializable {
+
+    private String id;
+
+    private String merchantId;
+
+    private String pid;
+
+    private String img;
+
+    private Integer sort;
+
+    private ProductTypeEnum type;
+
+    private BaseStatusEnum status;
+
+    private Date gmtCreated;
+
+    private Date gmtModified;
+
+    private Product product;
+
+    private Merchant merchant;
+
+
+}
+

+ 138 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/controller/PosterController.java

@@ -0,0 +1,138 @@
+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.*;
+import cn.rankin.productservice.code.ProductServiceAPICode;
+import cn.rankin.productservice.repository.ProductRepository;
+import cn.rankin.productservice.service.*;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+@Slf4j
+@RestController
+@RequestMapping(value = "poster")
+public class PosterController {
+
+    @Autowired
+    private PosterService posterService;
+
+    @Autowired
+    private ProductService productService;
+
+    @Autowired
+    private ProductRepository productRepository;
+
+    @RequestMapping(value = "/list", method = RequestMethod.GET)
+    public APIResult<Page<Poster>> search(@Valid @RequestBody 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());
+
+        // 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);
+    }
+
+    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
+    public APIResult<Poster> getPoster(@PathVariable("id") String id) {
+
+        if (StringUtils.isEmpty(id)) {
+            return APIResult.error(APICode.PARAMETER_ERROR);
+        }
+
+        Poster result = posterService.findById(id);
+        if(null == result){
+            return APIResult.error(APICode.NOT_EXISTS);
+        }
+
+
+//        Product product = productService.find(result.getPid());
+        Product product = productRepository.findByPid(result.getPid());
+        result.setProduct(product);
+
+
+
+        return APIResult.ok(result);
+
+    }
+
+    @Transactional
+    @RequestMapping(method = RequestMethod.POST)
+    public APIResult<Poster> create(@Valid @RequestBody PosterDTO posterDTO) {
+        try{
+            // 创建海报
+            Poster result = posterService.create(posterDTO);
+            if (null == result) {
+                return APIResult.error(APICode.OPERATE_ERROR);
+            }
+            return APIResult.ok(result);
+        }catch(Exception e){
+            log.info("poster create error: message={}",e.getMessage());
+            return APIResult.error(APICode.OPERATE_ERROR);
+        }
+
+    }
+
+    @Transactional
+    @RequestMapping(method = RequestMethod.PUT)
+    public APIResult<Poster> update(@Valid @RequestBody PosterDTO posterDTO) {
+        String Id = posterDTO.getId();
+        if (Id == null) {
+            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);
+        }
+
+        return APIResult.ok(result);
+    }
+
+    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
+    public APIResult delete(@PathVariable("id") String id) {
+        Boolean flag = posterService.delete(id);
+        if(flag){
+            return APIResult.ok();
+        }else{
+            return APIResult.error(ProductServiceAPICode.error("删除失败"));
+        }
+    }
+}

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

@@ -1,9 +1,26 @@
 package cn.rankin.productservice.repository;
 
+import cn.rankin.common.utils.enums.BaseStatusEnum;
 import cn.rankin.common.utils.jpa.BasicJpaRepository;
 import cn.rankin.data.api.product.entity.Poster;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.List;
 
 public interface PosterRepository extends BasicJpaRepository<Poster, String> {
+//    Long countByCode(String code);
+
+    @Query(value = "select p from Poster p where p.id in (?1) and p.status = ?2")
+    List<Poster> findByIds(List<String> ids, BaseStatusEnum status);
+
+
+    @Query(value = "select p from Poster p where p.id = ?1 ")
+    Poster findPosterById(String id);
+
 
+    @Modifying
+    @Query(value = "update Poster p set p.status = 1 where p.id = ?1")
+    Integer deleteById(String id);
 }
 

+ 4 - 4
rankin-product-service/src/main/java/cn/rankin/productservice/repository/TagRepository.java

@@ -10,16 +10,16 @@ import java.util.List;
 
 public interface TagRepository extends BasicJpaRepository<Tag, String> {
 
-    @Query(value = "select t from Tag t where t.groupId = ?1 order by t.sort")
-    List<Tag> findByGroupId(String groupId);
+    @Query(value = "select t from Tag t where t.groupId = ?1 and t.status = ?2  order by t.sort")
+    List<Tag> findByGroupId(String groupId, BaseStatusEnum status);
 
     /*  add   */
     @Query(value = "select t from Tag t where t.groupId = ?1 order by t.sort")
     List<Tag> findByTagTypeId(String tagTypeId);
 
 
-    @Query(value = "select t from Tag t where t.typeCode = ?1 and t.merchantId = ?2 order by t.sort")
-    List<Tag> findByTypeCode(String typeCode,String merchantId);
+    @Query(value = "select t from Tag t where t.typeCode = ?1 and t.merchantId = ?2  and t.status = ?3 order by t.sort")
+    List<Tag> findByTypeCode(String typeCode,String merchantId, BaseStatusEnum status);
 
     @Query(value = "select t from Tag t where t.typeCode = ?1 order by t.sort")
     List<Tag> findByTypeCode(String typeCode);

+ 104 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/service/PosterService.java

@@ -0,0 +1,104 @@
+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;
+import cn.rankin.common.utils.util.ListUtil;
+import cn.rankin.data.api.product.dto.PosterDTO;
+import cn.rankin.data.api.product.entity.Poster;
+import cn.rankin.productservice.repository.PosterRepository;
+import cn.rankin.productservice.utils.DTOConverter;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static cn.rankin.productservice.utils.DTOConverter.convert;
+
+@Slf4j
+@Service
+public class PosterService {
+
+    @Autowired
+    private PosterRepository posterRepository;
+
+    public List<Poster> findByIds(List<String> posterIds) {
+        List<Poster> posterList = posterRepository.findByIds(posterIds);
+
+        if (posterList == null || posterList.size() == 0) {
+            return posterList;
+        }
+
+        Map<String, Poster> posterMap = ListUtil.convert(posterList, "id", Poster.class);
+        List<Poster> sortPosterList = new ArrayList<>();
+        posterIds.forEach( id -> {
+            Poster poster = posterMap.get(id);
+            if (poster != null) {
+                sortPosterList.add(poster);
+            }
+        });
+
+        return sortPosterList;
+    }
+
+    public Page<Poster> search(Poster poster, Integer pageNo, Integer pageSize, LinkedHashMap<String, BaseOrderEnum> sort) {
+        Long count = posterRepository.count(poster);
+        Page<Poster> page = new Page(count, pageNo, pageSize);
+
+        if (count == 0) {
+            return page;
+        }
+
+        List<Poster> posterList = posterRepository.find(poster, page.getStart(), pageSize, JpaSortUtil.sort(sort));
+        page.setList(posterList);
+
+        return page;
+    }
+
+    public Poster findById(String id) {
+        Poster poster = posterRepository.find(id);
+        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);
+
+        return result;
+    }
+
+    @Transactional
+    public Poster update(PosterDTO posterDTO) {
+        Poster poster = DTOConverter.convert(posterDTO);
+        Poster result = posterRepository.update(poster);
+
+        return result;
+    }
+
+    @Transactional
+    public Boolean delete(String id) {
+        Integer count = posterRepository.deleteById(id);
+        if (count > 0) {
+            return true;
+        }
+        return false;
+    }
+
+}

+ 3 - 3
rankin-product-service/src/main/java/cn/rankin/productservice/service/TagService.java

@@ -46,14 +46,14 @@ public class TagService {
     private GoodsService goodsService;
 
     public List<Tag> findByGroupId(String groupId) {
-        List<Tag> tagList = tagRepository.findByGroupId(groupId);
+        List<Tag> tagList = tagRepository.findByGroupId(groupId, BaseStatusEnum.NORMAL);
         setGroupInfo(tagList);
         return tagList;
     }
 
     /*add    2018-05-17 */
     public List<Tag> findByTypeCode(String typeCode,String merchantId) {
-        List<Tag> tagList = tagRepository.findByTypeCode(typeCode,merchantId);
+        List<Tag> tagList = tagRepository.findByTypeCode(typeCode,merchantId, BaseStatusEnum.NORMAL);
         return tagList;
     }
 
@@ -192,7 +192,7 @@ public class TagService {
 
     @Transactional
     public void sortTag(String groupId, List<String> tagIdList) {
-        List<Tag> tagList = tagRepository.findByGroupId(groupId);
+        List<Tag> tagList = tagRepository.findByGroupId(groupId, BaseStatusEnum.NORMAL);
         sortTag(tagIdList, tagList);
         tagRepository.update(tagList);
     }

+ 9 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/utils/DTOConverter.java

@@ -11,6 +11,15 @@ import org.springframework.beans.BeanUtils;
 
 public class DTOConverter {
 
+    // PosterDTO to Poster
+    public static Poster convert(PosterDTO posterDTO) {
+        Poster poster = new Poster();
+        BeanUtils.copyProperties(posterDTO, poster);
+//        course.setType(ProductTypeEnum.COURSE);
+
+        return poster;
+    }
+
     // CourseDTO to Course
     public static Course convert(CourseDTO courseDTO) {
         Course course = new Course();

+ 7 - 47
rankin-resource-service/src/main/java/cn/rankin/resourceservice/service/ResourceService.java

@@ -304,53 +304,13 @@ public class ResourceService {
      */
     public APIResult<Resource> updateRemoteResource(Resource resource) {
 
-        APIResult<ResourceRemote> result = resourceProxy.findById(resource.getId());
-        log.info("Remote Server info: code={}, message={},data={}", result.getCode(), result.getMessage(),result.getData());
-        if (!result.getSuccess()) {
-            log.error("Remote Server Error: code={}, message={}", result.getCode(), result.getMessage());
-            APIResult errResult = APIResult.error(APICode.REMOTE_SERVER_ERROR);
-            errResult.setMessage(result.getMessage());
-            return errResult;
+        if (org.apache.commons.lang.StringUtils.isEmpty(resource.getId())) {
+            return APIResult.error(APICode.PARAMETER_ERROR);
         }
 
-
-/*        List<Map<String, Object>> videos = new ArrayList<>();
-        Map<String, Object> video = new HashMap<>();
-        video.put("bucket","efunbox");
-        video.put("path",resource.getPath());
-        video.put("format",resource.getFormat());
-        video.put("quality",resource.getQuality());
-        video.put("size",resource.getSize());
-
-        videos.add(video);
-
-        APIResult<ResourceDetail> apiResult = resourceProxy.updateResources(new HashMap<String, Object>(){
-            {
-                this.put("id", resource.getId());
-                this.put("no", resource.getCode());
-                this.put("title", resource.getName());
-                this.put("type", "1");
-                this.put("videos", videos);
-            }
-        });*/
-
-        Set<ResourceVideo> videos = result.getData().getVideos();
-        if(videos != null && videos.size() > 0){
-            Iterator<ResourceVideo> iterator = videos.iterator();
-            while(iterator.hasNext()){
-                ResourceVideo video = iterator.next();
-                video.setBucket("efunbox");
-                video.setPath(resource.getPath());
-                video.setQuality(resource.getQuality());
-                video.setFormat(resource.getFormat());
-                video.setSize(resource.getSize());
-                log.info("Remote Server info: video={}, message={},data={}", video);
-            }
-        }
-
-
-/*        Set<ResourceVideo> videos = new HashSet<>();
+        Set<ResourceVideo> videos = new HashSet<>();
         ResourceVideo video = new ResourceVideo();
+        video.setId(resource.getId());
         video.setBucket("efunbox");
         video.setPath(resource.getPath());
         video.setQuality(resource.getQuality());
@@ -360,18 +320,18 @@ public class ResourceService {
 
 
         ResourceRemote resourceRemote = new ResourceRemote();
+        resourceRemote.setId(resource.getId());
         resourceRemote.setNo(resource.getCode());
         resourceRemote.setTitle(resource.getName());
         resourceRemote.setType(resource.getType());
         resourceRemote.setVideos(videos);
 
         APIResult<ResourceDetail> apiResult = resourceProxy.updateResources(resourceRemote);
-        log.info("updateResources: "+apiResult);
         if (!apiResult.getSuccess()) {
             return errorResourceAPIResult(apiResult);
-        }*/
+        }
 
-//        Resource resourceVO = apiResult.getData().toNativeResource();
+        log.info("Remote Server info: code={}, message={},data={}", apiResult.getCode(), apiResult.getMessage(),apiResult.getData());
         return APIResult.ok();
     }