Browse Source

add UserTag UserRecommend module

guozhaoshun 6 years ago
parent
commit
53870c5081

+ 73 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/UserController.java

@@ -0,0 +1,73 @@
+package cn.rankin.cmsweb.controller.user;
+
+import cn.rankin.cmsweb.service.user.UserRecommendService;
+import cn.rankin.cmsweb.service.user.UserTagServiceInterface;
+import cn.rankin.common.utils.api.model.APICode;
+import cn.rankin.common.utils.api.model.APIResult;
+import cn.rankin.data.api.product.vo.UserRecommendVo;
+import cn.rankin.data.api.user.entity.UserRecommend;
+import cn.rankin.data.api.user.entity.UserTag;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping(value = "/user")
+public class UserController {
+
+    @Autowired
+    private UserRecommendService userRecommendService;
+
+    @Autowired
+    private UserTagServiceInterface userTagService;
+
+    // 用户推荐位设置
+    @RequestMapping(value = "/userRecommend/uid/{uid}", method = RequestMethod.GET)
+    public APIResult<List<UserRecommendVo>> getUserRecommend(@PathVariable("uid") String uid) {
+        if (StringUtils.isEmpty(uid)) {
+            return APIResult.error(APICode.PARAMETER_ERROR);
+        }
+        List<UserRecommend> userRecommendList = userRecommendService.get(uid);
+        return APIResult.ok(userRecommendList);
+    }
+
+    @RequestMapping(value = "/userRecommend/uid/{uid}", method = RequestMethod.PUT)
+    public APIResult<List<UserRecommendVo>> updateUserRecommend(@PathVariable("uid") String uid, @RequestBody List<String> productIdList) {
+        if (StringUtils.isEmpty(uid) || CollectionUtils.isEmpty(productIdList)) {
+            return APIResult.error(APICode.PARAMETER_ERROR);
+        }
+
+        List<UserRecommend> userRecommendList = userRecommendService.put(uid, productIdList);
+        return APIResult.ok(userRecommendList);
+    }
+
+    //用户标签配置
+    @RequestMapping(value = "/userTag/uid/{uid}", method = RequestMethod.GET)
+    public APIResult<UserTag> getUserTagsByUid(@PathVariable("uid") String uid) {
+        List<UserTag> userTags = userTagService.findUserTagByUid(uid);
+        if (userTags != null) {
+//            merchantInfoSetService.setMerchantInfo(apiResult.getData());
+
+            userTags.forEach(userTag -> {
+                userTag.getRelationList();
+
+
+
+
+
+            });
+
+
+            /*public List<ItemVo> findItemByPids(List<String> productIdList, String merchantId) {
+                return productClient.findItemByPids(productIdList,merchantId);
+            }*/
+            return APIResult.ok(userTags);
+        }else{
+            return APIResult.error(APICode.NOT_EXISTS);
+        }
+    }
+
+}

+ 95 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/UserTagController.java

@@ -0,0 +1,95 @@
+package cn.rankin.cmsweb.controller.user;
+
+import cn.rankin.cmsweb.assist.resolver.NeedUser;
+import cn.rankin.cmsweb.entity.UserDetails;
+import cn.rankin.cmsweb.service.user.MerchantInfoSetService;
+import cn.rankin.cmsweb.service.user.UserTagServiceInterface;
+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.util.BeanUtil;
+import cn.rankin.data.api.product.vo.TagVo;
+import cn.rankin.data.api.user.dto.UserTagDTO;
+import cn.rankin.data.api.user.dto.UserTagSearchDTO;
+import cn.rankin.data.api.user.entity.UserTag;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+@Slf4j
+@RestController
+@RequestMapping(value = "/userTag")
+public class UserTagController {
+
+    @Autowired
+    private UserTagServiceInterface userTagService;
+
+    @Autowired
+    private MerchantInfoSetService<TagVo> merchantInfoSetService;
+
+    @RequestMapping(value = "/list", method = RequestMethod.GET)
+    public APIResult<Page<UserTag>> search(@NeedUser UserDetails user, UserTagSearchDTO searchDTO) {
+        if (!user.isPlatForm()) {
+            searchDTO.setUid(user.getId());
+        }
+        Page<UserTag> userTagPage = userTagService.search(BeanUtil.convertToMap(searchDTO));
+        if (userTagPage != null) {
+            //merchantInfoSetService.setMerchantInfo(apiResult.getData().getList());
+            return APIResult.ok(userTagPage);
+        }else{
+            return APIResult.error(APICode.NOT_EXISTS);
+        }
+    }
+
+    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
+    public APIResult<UserTag> getUserTag(@PathVariable("id") String id) {
+        UserTag userTag = userTagService.getUserTag(id);
+        if (userTag != null) {
+//            merchantInfoSetService.setMerchantInfo(apiResult.getData());
+            return APIResult.ok(userTag);
+        }else{
+            return APIResult.error(APICode.NOT_EXISTS);
+        }
+    }
+
+    @RequestMapping(method = RequestMethod.POST)
+    public APIResult<UserTag> create(@RequestBody UserTagDTO dto) {
+        UserTag userTag = userTagService.create(dto);
+        if (userTag != null) {
+//            merchantInfoSetService.setMerchantInfo(apiResult.getData());
+            return APIResult.ok(userTag);
+        }else{
+            return APIResult.error(APICode.NOT_EXISTS);
+        }
+    }
+
+    @RequestMapping(method = RequestMethod.PUT)
+    public APIResult<UserTag> update(@RequestBody UserTagDTO dto) {
+        if(StringUtils.isBlank(dto.getId())){
+            return APIResult.error(APICode.PARAMETER_ERROR);
+        }
+        UserTag userTag = userTagService.update(dto);
+        if (userTag != null) {
+            log.error("update UserTag is error, pid={}", dto.getId());
+//            merchantInfoSetService.setMerchantInfo(apiResult.getData());
+            return APIResult.ok(userTag);
+        }else{
+            return APIResult.error(APICode.NOT_EXISTS);
+        }
+    }
+
+    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
+    public APIResult delete(@PathVariable("id") String id) {
+        if(StringUtils.isBlank(id)){
+            return APIResult.error(APICode.PARAMETER_ERROR);
+        }
+        boolean flag = userTagService.delete(id);
+        if(flag){
+            return APIResult.ok();
+        }else{
+            log.error("delete UserTag is error, pid={}", id);
+            return APIResult.error(APICode.OPERATE_ERROR);
+        }
+    }
+}

+ 20 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/user/UserRecommendService.java

@@ -0,0 +1,20 @@
+package cn.rankin.cmsweb.service.user;
+
+import cn.rankin.data.api.user.entity.UserRecommend;
+import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.List;
+
+@FeignClient(name = "${service.user.name}")
+public interface UserRecommendService {
+
+    @RequestMapping(value = "/userRecommend/uid", method = RequestMethod.GET)
+    List<UserRecommend> get(@RequestParam("uid") String uid);
+
+    @RequestMapping(value = "/userRecommend/uid", method = RequestMethod.PUT)
+    List<UserRecommend> put(@RequestParam("uid") String uid, @RequestBody List<String> productIdList);
+}

+ 35 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/user/UserTagServiceInterface.java

@@ -0,0 +1,35 @@
+package cn.rankin.cmsweb.service.user;
+
+import cn.rankin.common.utils.api.page.Page;
+import cn.rankin.data.api.user.dto.UserTagDTO;
+import cn.rankin.data.api.user.entity.UserTag;
+import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.Map;
+
+@FeignClient(value = "${service.user.name}")
+public interface UserTagServiceInterface {
+
+    @RequestMapping(value = "/userTag/list", method = RequestMethod.GET)
+    Page<UserTag> search(@RequestParam Map<String, Object> searchDTO);
+
+    @RequestMapping(value = "/userTag", method = RequestMethod.POST)
+    UserTag create(@RequestBody UserTagDTO dto);
+
+    @RequestMapping(value = "/userTag", method = RequestMethod.PUT)
+    UserTag update(@RequestBody UserTagDTO dto);
+
+    @RequestMapping(value = "/userTag/{id}", method = RequestMethod.DELETE)
+    boolean delete(@PathVariable("id") String id);
+
+    @RequestMapping(value = "/userTag/{id}", method = RequestMethod.GET)
+    UserTag getUserTag(@PathVariable("id") String id);
+
+    @RequestMapping(value = "/userTag/code/{code}", method = RequestMethod.GET)
+    List<UserTag> findUserTagByCodeUid(@PathVariable("code") String code, @PathVariable("uid") String uid);
+
+    @RequestMapping(value = "/userTag/uid/{uid}", method = RequestMethod.GET)
+    List<UserTag> findUserTagByUid(@PathVariable("uid") String uid);
+}